Learn R Programming

DescTools (version 0.99.6)

MeanDiffCI: Confidence Intervals for Difference of Means

Description

Calculates the confidence interval for the difference of two means either the classical way or with the bootstrap approach.

Usage

MeanDiffCI(x, y, type = c("classic", "norm", "basic", "stud", "perc", "bca"), 
           conf.level = 0.95, na.rm = FALSE, R = 999)

Arguments

x
a (non-empty) numeric vector of data values.
y
a (non-empty) numeric vector of data values.
type
a vector of character strings representing the type of intervals required. The value should be any subset of the values "norm", "basic", "stud", "perc", "bca". See
conf.level
confidence level of the interval.
na.rm
logical. Should missing values be removed? Defaults to FALSE.
R
the number of bootstrap replicates. Usually this will be a single positive integer. For importance resampling, some resamples may use one set of weights and others use a different set of weights. In this case R would be a vector of integers where each com

Value

  • a numeric vector with 3 elements:
  • meandiffthe difference: mean(x) - mean(y)
  • lwr.cilower bound of the confidence interval
  • upr.ciupper bound of the confidence interval

Details

This function collects code from two sources. The classical confidence interval is calculated by means of t.test. The bootstrap intervals are strongly based on the example in boot.

See Also

MeanCI, VarCI, MedianCI, boot.ci

Examples

Run this code
x <- d.pizza$price[d.pizza$driver=="Carter"]
y <- d.pizza$price[d.pizza$driver=="Miller"]

MeanDiffCI(x, y, na.rm=TRUE)
MeanDiffCI(x, y, conf.level=0.99, na.rm=TRUE)

# the different types of bootstrap confints
MeanDiffCI(x, y, type="norm", na.rm=TRUE)
MeanDiffCI(x, y, type="basic", na.rm=TRUE)
# MeanDiffCI(x, y, type="stud", na.rm=TRUE)
MeanDiffCI(x, y, type="perc", na.rm=TRUE)
MeanDiffCI(x, y, type="bca", na.rm=TRUE)

Run the code above in your browser using DataLab