calculate_ci: Function to calculate confidence intervals (CIs), usually...

View source: R/calculate_ci.R

calculate_ciR Documentation

Function to calculate confidence intervals (CIs), usually based on population standard deviation.

Description

The CI calculations use the smean.cl.normal and smean.cl.boot functions from the Hmisc package that were developed by Frank Harrell. These functions are also used internally by ggplot2.

Usage

calculate_ci(x, level = 0.95, method = "standard", n_samples = 1000)

Arguments

x

Numeric vector.

level

Confidence interval to calculate. This is a decimal, i.e., 0.95 is the 95 % CI.

method

Method to use for CI calculation. Can be one of two methods: standard or bootstrap. standard calculates the sample mean and lower and upper Gaussian confidence limits based on the t-distribution. bootstrap uses non-parametric bootstrapping for calculating the lower and upper limits without assuming normality.

n_samples

When method is bootstap, how many bootstrap samples should be taken?

Value

A tibble with one row.

Author(s)

Stuart K. Grange and Frank Harrell.

See Also

calculate_quantiles, calculate_range

Examples


# Calculate confidence intervals
x <- c(44617L, 7066L, 17594L, 2726L, 1178L, 18898L, 5033L, 37151L,  4514L, 4000L)

calculate_ci(x)
calculate_ci(x, level = 0.9)
calculate_ci(x, method = "bootstrap")


skgrange/threadr documentation built on April 15, 2024, 9:35 p.m.