Compute a confidence interval around a summary statistic. Currently, only simulation-based methods are supported.

Learn more in vignette("infer").

get_confidence_interval(
x,
level = 0.95,
type = "percentile",
point_estimate = NULL
)

get_ci(x, level = 0.95, type = "percentile", point_estimate = NULL)

Arguments

x Data frame of calculated statistics or containing attributes of theoretical distribution values. Currently, dependent on statistics being stored in stat column as created in calculate() function. A numerical value between 0 and 1 giving the confidence level. Default value is 0.95. A string giving which method should be used for creating the confidence interval. The default is "percentile" with "se" corresponding to (multiplier * standard error) and "bias-corrected" for bias-corrected interval as other options. A numeric value or a 1x1 data frame set to NULL by default. Needed to be provided if type is "se" or "bias-corrected".

Value

A 1 x 2 tibble with 'lower_ci' and 'upper_ci' columns. Values correspond to lower and upper bounds of the confidence interval.

Details

A null hypothesis is not required to compute a confidence interval, but including hypothesize() in a chain leading to get_confidence_interval() will not break anything. This can be useful when computing a confidence interval after previously computing a p-value.

Aliases

get_ci() is an alias of get_confidence_interval(). conf_int() is a deprecated alias of get_confidence_interval().

Examples


boot_distr <- gss %>%
# We're interested in the number of hours worked per week
specify(response = hours) %>%
# Generate bootstrap samples
generate(reps = 1000, type = "bootstrap") %>%
# Calculate mean of each bootstrap sample
calculate(stat = "mean")

boot_distr %>%
# Calculate the confidence interval around the point estimate
get_confidence_interval(
# At the 95% confidence level; percentile method
level = 0.95
)
#> # A tibble: 1 x 2
#>   lower_ci upper_ci
#>      <dbl>    <dbl>
#> 1     40.1     42.7
# For type = "se" or type = "bias-corrected" we need a point estimate
sample_mean <- gss %>%
specify(response = hours) %>%
calculate(stat = "mean") %>%
dplyr::pull()

boot_distr %>%
get_confidence_interval(
point_estimate = sample_mean,
# At the 95% confidence level
level = 0.95,
# Using the standard error method
type = "se"
)
#> # A tibble: 1 x 2
#>   lower_ci upper_ci
#>      <dbl>    <dbl>
#> 1     40.1     42.7
# More in-depth explanation of how to use the infer package
if (FALSE) {
vignette("infer")
}