
Calculate confidence intervals from a 'boot' object
Source:R/calculate_boot_ci_from_boot.R
calculate_boot_ci_from_boot.RdThis function calculates multiple types of confidence intervals
(normal, basic, percentile, BCa) for a boot object using
boot::boot.ci().
Arguments
- boot_obj
A
bootobject (from the boot package).- type
A character vector specifying the type(s) of confidence intervals to compute. Options include:
"perc": Percentile interval"bca": Bias-corrected and accelerated interval"norm": Normal interval"basic": Basic interval"all": Compute all available interval types (default)
- conf
A numeric value specifying the confidence level of the intervals. Default is
0.95(95 % confidence level).- h
A function defining a transformation. The intervals are calculated on the scale of
h(t)and the inverse functionhinvapplied to the resulting intervals. It must be a function of one variable only. The default is the identity function.- hinv
A function, like
h, which returns the inverse ofh. It is used to transform the intervals calculated on the scale ofh(t)back to the original scale. The default is the identity function. Ifhis supplied buthinvis not, then the intervals returned will be on the transformed scale.- boot_args
Named list of additional arguments to pass to
boot::boot.ci().
Value
A tidy dataframe with columns:
stat_index: Index of statistic in the boot objectest_original: Original estimate from full datasetint_type: Interval typell: Lower confidence limitul: Upper confidence limitconf: Confidence level
See also
Other indicator_uncertainty_helper:
boot_list_to_dataframe(),
bootstrap_cube_raw(),
derive_bootstrap_method(),
resolve_bootstrap_method()
Examples
if (FALSE) { # \dontrun{
library(boot)
# Function to compute the mean
mean_fun <- function(data, indices) {
mean(data[indices])
}
# Bootstrap mean of the 'mpg' variable in mtcars
set.seed(123)
boot_obj <- boot(data = mtcars$mpg, statistic = mean_fun, R = 1000)
# Calculate confidence intervals for all types
ci_df <- calculate_boot_ci_from_boot(
boot_obj = boot_obj,
type = "all",
conf = 0.95
)
ci_df
} # }