Using confintr

knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  warning = FALSE,
  message = FALSE
)

Introduction

The aim of this vignette is to introduce the R package confintr for calculating one- and two-sided classic and bootstrap confidence intervals.

Confidence intervals for the following parameters are available:

Many of the classic confidence intervals on this list are discussed in [@smithson2003].

We offer different types of bootstrap intervals:

  1. Normal ("norm") bootstrap confidence interval: This is the Wald/Student confidence interval using as standard error the standard deviation of the bootstrap distribution plus a bootstrap bias correction. Simple, but only first-order accurate and not transformation respecting.

  2. Percentile ("perc") bootstrap confidence interval: Uses quantiles of the bootstrap distribution as confidence limits. Simple, but only first order accurate. Transformation respecting.

  3. Basic ("basic") or reverse bootstrap confidence interval: Flipped version of the percentile approach, dealing with bias but at the price of having very unnaturally tailed sampling distributions. Only first order accurate.

  4. Bias-corrected and accelerated ("bca") confidence interval: Refined version of the percentile bootstrap which is second order accurate and transformation respecting. Needs more replications than observations. Usually our default.

  5. Student-t ("stud") bootstrap confidence interval: Refined version of the normal bootstrap that replaces the Student quantile by a custom quantile obtained from bootstrapping the variance of the bootstrapped statistic. Second order accurate but not transformation respecting. Requires a formula for the variance of the estimator, which confintr provides for the mean, the mean difference, the variance (and standard deviation) as well as for the proportion. Used as the default for the mean and the mean difference.

For details on bootstrap confidence intervals, we refer to [@efron1993]. We provide them through the widely used boot package [@ripley2019].

Installation

From CRAN:

install.packages("confintr")

Latest version from github:

library(devtools)
install_github("mayer79/confintr")

Examples

library(confintr)

set.seed(1)

# Mean
ci_mean(1:100)
ci_mean(1:100, type = "bootstrap")

# 95% value at risk
ci_quantile(rexp(1000), q = 0.95)

# IQR
ci_IQR(rexp(100), R = 999)

# Correlation
ci_cor(iris[1:2], method = "spearman", type = "bootstrap", R = 999)

# Proportions
ci_proportion(10, n = 100, type = "Wilson")
ci_proportion(10, n = 100, type = "Clopper-Pearson")

# R-squared
fit <- lm(Sepal.Length ~ ., data = iris)
ci_rsquared(fit, probs = c(0.05, 1))

# Kurtosis
ci_kurtosis(1:100)

# Mean difference
ci_mean_diff(10:30, 1:15)
ci_mean_diff(10:30, 1:15, type = "bootstrap", R  = 999)

# Median difference
ci_median_diff(10:30, 1:15, R  = 999)

References



Try the confintr package in your browser

Any scripts or data that you put into this service are public.

confintr documentation built on Sept. 29, 2022, 5:13 p.m.