Description Usage Arguments Details Value Author(s) References See Also Examples

Performs one and two sample t-tests on multiple imputed datasets.

1 2 3 4 5 6 7 |

`miData` |
list of multiple imputed datasets. |

`x` |
name of a variable that shall be tested. |

`y` |
an optional name of a variable that shall be tested (paired test) or a variable that shall be used to split into groups (unpaired test). |

`alternative` |
a character string specifying the alternative
hypothesis, must be one of |

`mu` |
a number indicating the true value of the mean (or difference in means if you are performing a two sample test). |

`paired` |
a logical indicating whether you want a paired t-test. |

`var.equal` |
a logical variable indicating whether to treat the
two variances as being equal. If |

`conf.level` |
confidence level of the interval. |

`subset` |
an optional vector specifying a subset of observations to be used. |

`...` |
further arguments to be passed to or from methods. |

`alternative = "greater"`

is the alternative that `x`

has a
larger mean than `y`

.

If `paired`

is `TRUE`

then both `x`

and `y`

must
be specified and they must be the same length. Missing values are
not allowed as they should have been imputed. If
`var.equal`

is `TRUE`

then the pooled estimate of the
variance is used. By default, if `var.equal`

is `FALSE`

then the variance is estimated separately for both groups and the
Welch modification to the degrees of freedom is used.

We use the approach of Rubin (1987) in combination with the adjustment of Barnard and Rubin (1999).

A list with class `"htest"`

containing the following components:

`statistic` |
the value of the t-statistic. |

`parameter` |
the degrees of freedom for the t-statistic. |

`p.value` |
the p-value for the test. |

`conf.int` |
a confidence interval for the mean appropriate to the specified alternative hypothesis. |

`estimate` |
the estimated mean (one-sample test), difference in means (paired test), or estimated means (two-sample test) as well as the respective standard deviations. |

`null.value` |
the specified hypothesized value of the mean or mean difference depending on whether it was a one-sample test or a two-sample test. |

`alternative` |
a character string describing the alternative hypothesis. |

`method` |
a character string indicating what type of t-test was performed. |

`data.name` |
a character string giving the name(s) of the data. |

Matthias Kohl Matthias.Kohl@stamats.de

Rubin, D. (1987). *Multiple Imputation for Nonresponse in Surveys*.
John Wiley \& Sons, New York.

Barnard, J. and Rubin, D. (1999). Small-Sample Degrees of Freedom with
Multiple Imputation. *Biometrika*, **86**(4), 948-955.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | ```
## Generate some data
set.seed(123)
x <- rnorm(25, mean = 1)
x[sample(1:25, 5)] <- NA
y <- rnorm(20, mean = -1)
y[sample(1:20, 4)] <- NA
pair <- c(rnorm(25, mean = 1), rnorm(20, mean = -1))
g <- factor(c(rep("yes", 25), rep("no", 20)))
D <- data.frame(ID = 1:45, variable = c(x, y), pair = pair, group = g)
## Use Amelia to impute missing values
library(Amelia)
res <- amelia(D, m = 10, p2s = 0, idvars = "ID", noms = "group")
## Per protocol analysis (Welch two-sample t-test)
t.test(variable ~ group, data = D)
## Intention to treat analysis (Multiple Imputation Welch two-sample t-test)
mi.t.test(res$imputations, x = "variable", y = "group")
## Per protocol analysis (Two-sample t-test)
t.test(variable ~ group, data = D, var.equal = TRUE)
## Intention to treat analysis (Multiple Imputation two-sample t-test)
mi.t.test(res$imputations, x = "variable", y = "group", var.equal = TRUE)
## Specifying alternatives
mi.t.test(res$imputations, x = "variable", y = "group", alternative = "less")
mi.t.test(res$imputations, x = "variable", y = "group", alternative = "greater")
## One sample test
t.test(D$variable[D$group == "yes"])
mi.t.test(res$imputations, x = "variable", subset = D$group == "yes")
mi.t.test(res$imputations, x = "variable", mu = -1, subset = D$group == "yes",
alternative = "less")
mi.t.test(res$imputations, x = "variable", mu = -1, subset = D$group == "yes",
alternative = "greater")
## paired test
t.test(D$variable, D$pair, paired = TRUE)
mi.t.test(res$imputations, x = "variable", y = "pair", paired = TRUE)
``` |

```
Loading required package: Rcpp
##
## Amelia II: Multiple Imputation
## (Version 1.7.4, built: 2015-12-05)
## Copyright (C) 2005-2018 James Honaker, Gary King and Matthew Blackwell
## Refer to http://gking.harvard.edu/amelia/ for more information
##
Welch Two Sample t-test
data: variable by group
t = -6.136, df = 30.075, p-value = 9.442e-07
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
-2.719747 -1.361505
sample estimates:
mean in group no mean in group yes
-1.262978 0.777648
Multiple Imputation Welch Two Sample t-test
data: Variable variable: group no vs group yes
t = -6.2127, df = 27.254, p-value = 1.162e-06
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
-2.673999 -1.346690
sample estimates:
mean (no) SD (no) mean (yes) SD (yes)
-1.2578644 1.1335313 0.7524799 0.9539785
Two Sample t-test
data: variable by group
t = -6.2305, df = 34, p-value = 4.331e-07
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
-2.706232 -1.375020
sample estimates:
mean in group no mean in group yes
-1.262978 0.777648
Multiple Imputation Two Sample t-test
data: Variable variable: group no vs group yes
t = -6.2923, df = 30.34, p-value = 5.881e-07
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
-2.662526 -1.358163
sample estimates:
mean (no) SD (no) mean (yes) SD (yes)
-1.2578644 1.1335313 0.7524799 0.9539785
Multiple Imputation Welch Two Sample t-test
data: Variable variable: group no vs group yes
t = -6.2127, df = 27.254, p-value = 5.811e-07
alternative hypothesis: true difference in means is less than 0
95 percent confidence interval:
-Inf -1.459366
sample estimates:
mean (no) SD (no) mean (yes) SD (yes)
-1.2578644 1.1335313 0.7524799 0.9539785
Multiple Imputation Welch Two Sample t-test
data: Variable variable: group no vs group yes
t = -6.2127, df = 27.254, p-value = 1
alternative hypothesis: true difference in means is greater than 0
95 percent confidence interval:
-2.561323 Inf
sample estimates:
mean (no) SD (no) mean (yes) SD (yes)
-1.2578644 1.1335313 0.7524799 0.9539785
One Sample t-test
data: D$variable[D$group == "yes"]
t = 3.796, df = 19, p-value = 0.001221
alternative hypothesis: true mean is not equal to 0
95 percent confidence interval:
0.348868 1.206428
sample estimates:
mean of x
0.777648
Multiple Imputation One Sample t-test
data: Variable variable
t = 3.9439, df = 19.617, p-value = 0.0008272
alternative hypothesis: true mean is not equal to 0
95 percent confidence interval:
0.3539882 1.1509716
sample estimates:
mean SD
0.7524799 0.9539785
Multiple Imputation One Sample t-test
data: Variable variable
t = 9.1851, df = 19.617, p-value = 1
alternative hypothesis: true mean is less than -1
95 percent confidence interval:
-Inf 1.081861
sample estimates:
mean SD
0.7524799 0.9539785
Multiple Imputation One Sample t-test
data: Variable variable
t = 9.1851, df = 19.617, p-value = 7.679e-09
alternative hypothesis: true mean is greater than -1
95 percent confidence interval:
0.4230991 Inf
sample estimates:
mean SD
0.7524799 0.9539785
Paired t-test
data: D$variable and D$pair
t = -0.84172, df = 35, p-value = 0.4057
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
-0.6224989 0.2575965
sample estimates:
mean of the differences
-0.1824512
Multiple Imputation Paired t-test
data: Variables variable and pair
t = -1.1136, df = 39.142, p-value = 0.2723
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
-0.6063388 0.1757321
sample estimates:
mean of difference SD of difference
-0.2153033 1.2970098
```

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.