This function calculates CIs for the population value of mean(x) - mean(y). The default is Student's method with Welch's correction for unequal variances, but also bootstrap CIs are available.
A numeric vector.
A numeric vector.
Lower and upper probabilities, by default c(0.025, 0.975)
.
Should the two variances be treated as being equal?
The default is FALSE
. If TRUE
, the pooled variance is used to estimate
the variance of the mean difference. Otherweise, Welch's approach is used.
This also applies to the "stud" bootstrap.
Type of CI. One of "t" (default), or "bootstrap".
Type of bootstrap CI. Only used for type = "bootstrap"
.
The number of bootstrap resamples. Only used for type = "bootstrap"
.
An integer random seed. Only used for type = "bootstrap"
.
Further arguments passed to boot::boot()
.
An object of class "cint", see ci_mean()
for details.
The default bootstrap type is "stud" (bootstrap t) as it has a stable variance
estimator (see Efron, p. 188). Resampling is done within sample.
When boot_type = "stud"
, the standard error is estimated by Welch's method
if var.equal = FALSE
(the default), and by pooling otherwise.
Thus, var.equal
not only has an effect for the classic Student approach
(type = "t"
) but also for boot_type = "stud"
.
Efron, B. and Tibshirani R. J. (1994). An Introduction to the Bootstrap. Chapman & Hall/CRC.
x <- 10:30
y <- 1:30
ci_mean_diff(x, y)
#>
#> Two-sided 95% t confidence interval for the population value of
#> mean(x)-mean(y)
#>
#> Sample estimate: 4.5
#> Confidence interval:
#> 2.5% 97.5%
#> 0.2766822 8.7233178
#>
t.test(x, y)$conf.int
#> [1] 0.2766822 8.7233178
#> attr(,"conf.level")
#> [1] 0.95
ci_mean_diff(x, y, type = "bootstrap", R = 999) # Use larger R
#>
#> Two-sided 95% bootstrap confidence interval for the population value of
#> mean(x)-mean(y) based on 999 bootstrap replications and the student
#> method
#>
#> Sample estimate: 4.5
#> Confidence interval:
#> 2.5% 97.5%
#> 0.2700011 9.0850971
#>