DescTools (version 0.99.8.1)

MeanCI: Confidence Interval for the Mean

Description

Calculates the confidence interval for the mean either the classical way or with the bootstrap approach.

Usage

MeanCI(x, trim = 0, method = 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.
trim
a (non-empty) numeric vector of data values.
method
A vector of character strings representing the type of intervals required. The value should be any subset of the values "classic", "norm", "basic", "stud", "perc", "bca".
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:
  • meanmean
  • lwr.cilower bound of the confidence interval
  • upr.ciupper bound of the confidence interval

Details

Interfaces for data.frames are widely deprecated nowadays and so we abstained to implement one. Use do.call, rbind and lapply for getting a matrix with estimates and confidence intervals for more than 1 column. (See examples!)

See Also

MeanDiffCI, MedianCI, VarCI

Examples

Run this code
x <- d.pizza$price[1:20]

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

# the different types of bootstrap confints
MeanCI(x, method="norm", na.rm=TRUE)
MeanCI(x, method="norm", trim=0.1, na.rm=TRUE)
MeanCI(x, method="basic", trim=0.1, na.rm=TRUE)
# MeanCI(x, method="stud", trim=0.1, na.rm=TRUE), this needs some more information
MeanCI(x, method="perc", trim=0.1, na.rm=TRUE)
MeanCI(x, method="bca", trim=0.1, na.rm=TRUE)


# Getting the MeanCI for more than 1 column
round( do.call("rbind", lapply(d.pizza[,1:4],  MeanCI, na.rm=TRUE)), 3)

Run the code above in your browser using DataLab