Learn R Programming

ClusterBootstrap (version 2.0.0)

confint.clusterBootstrap: Confidence intervals for clusterBootstrap objects

Description

Computes confidence intervals for estimates obtained via clustered bootstrap resampling. Supported interval types are: percentile (default), normal approximation (parametric), and bias-corrected (BC).

Usage

# S3 method for clusterBootstrap
confint(
  object,
  parm = NULL,
  level = 0.95,
  type = c("percentile", "parametric", "bc"),
  ...
)

Value

A data.frame with one row per parameter and the following columns:

term

The name of the parameter.

type

The type of confidence interval used.

conf.low

The lower bound of the confidence interval.

conf.high

The upper bound of the confidence interval.

Arguments

object

An object of class "clusterBootstrap", as returned by clusterBootstrap.

parm

A character vector of parameter names to compute confidence intervals for. If NULL (default), intervals are computed for all parameters.

level

Confidence level, e.g., 0.95 for a 95% confidence interval.

type

Type of confidence interval. One of "percentile", "parametric", or "bc". The default is "percentile".

...

Currently ignored. Included for method compatibility.

Details

  • Percentile: uses the empirical quantiles of the bootstrap estimates.

  • Parametric: uses the bootstrap standard error and assumes normality.

  • Bias-corrected (BC): adjusts for bias in the bootstrap distribution. Note: acceleration (BCa) is not implemented.

See Also

clusterBootstrap, confint

Examples

Run this code
if (FALSE) {
set.seed(2025)
n_school  <- 30
n_class   <- 8
n_student <- 15

demo <- expand.grid(school  = paste0("S", 1:n_school),
                    class   = paste0("C", 1:n_class),
                    student = paste0("P", 1:n_student)) |>
  mutate(score1 = rnorm(n()),
  score2 = rnorm(n())) |>
  arrange(school, class, student) |>
  slice(1:(n() - 3)) # slightly unbalanced data
bootFun2 <- function(d) lm(score1 ~ score2, data = d)$coef
clusterBootstrap(df       = demo, 
                 clusters = c("school", "class", "student"),
                 replace  = c(TRUE, FALSE, TRUE),
                 stat_fun = bootFun2,
                 B        = 1000) |>
  confint()
}

Run the code above in your browser using DataLab