This function calculates confidence intervals 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 confidence intervals are available.
ci_mean_diff(
x,
y,
probs = c(0.025, 0.975),
var.equal = FALSE,
type = c("t", "bootstrap"),
boot_type = c("stud", "bca", "perc", "norm", "basic"),
R = 9999,
seed = NULL,
...
)
A numeric vector.
A numeric vector.
Error probabilites. The default c(0.025, 0.975) gives a symmetric 95% confidence interval.
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" boostrap.
Type of confidence interval. One of "t" (default), or "bootstrap".
Type of bootstrap confidence interval ("stud", "bca", "perc", "norm", "basic"). 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
.
A list with class cint
containing these components:
parameter
: The parameter in question.
interval
: The confidence interval for the parameter.
estimate
: The estimate for the parameter.
probs
: A vector of error probabilities.
type
: The type of the interval.
info
: An additional description text for the interval.
Bootstrap confidence intervals are calculated by the package "boot". The default bootstrap type for the mean difference is "stud" (bootstrap t) as it enjoys the property of being second order accurate and has a stable variance estimator (see Efron, p. 188).
The resampling is done within sample. If 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
has not only 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.
Canty, A and Ripley B. (2019). boot: Bootstrap R (S-Plus) Functions.
# NOT RUN {
x <- 10:30
y <- 1:30
ci_mean_diff(x, y)
t.test(x, y)$conf.int
ci_mean_diff(x, y, type = "bootstrap", R = 999)
# }
Run the code above in your browser using DataLab