getConfidenceInterval | R Documentation |
Calculate or bootstrap a confidence interval.
getConfidenceInterval(
data,
variance = stats::var(data, na.rm = TRUE),
conf.level = 0.95,
method = "t-distr",
resamples = 1000,
FUN = mean
)
data |
A numeric vector. |
variance |
Set the variance (e.g. when the population variance is known). Only used for method='t-distr'. |
conf.level |
Set the confidence level (.50 < conf.level < 1.00, default: 0.95). |
method |
One of 't-distr' or 'bootstrap' to either use the sample t-distribution to _calculate_ the confidence interval or to bootstrap it by resampling from the sample in 'data'. Using the sample t-distribution can be much faster and allows overriding the sample variance, and according to the central limit theorem, the distribution of sample means is normal, so that is fine. Bootstrapping is slower but works on any data distribution and allows other descriptors like the median, or variance by setting FUN. |
resamples |
The number of samples to draw with replacement from the data to bootstrap values of the descriptor. |
FUN |
The function to use as descriptor for every sample when bootstrapping. |
Tell a story here.
A vector with the upper and lower bound of the confidence interval.
# for normally distributed data, using a t-interval is fine:
normal <- rnorm(1000)
getConfidenceInterval(normal)
getConfidenceInterval(normal, variance=1)
# but perhaps we want to bootstrap it for other distributions:
exponential <- rexp(1000)
getConfidenceInterval(exponential)
getConfidenceInterval(exponential,method='bootstrap')
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.