Construct Simultaneous Confidence Bands for Regression Coefficients
Source:R/regression_outcome_scb.R
SCB_regression_coef.RdThis function fits either a linear or logistic regression model and computes simultaneous confidence bands (SCBs) for the model coefficients using a non-parametric bootstrap procedure.
Arguments
- df_fit
A data frame containing the design matrix and response variable used to fit the model.
- model
A character string specifying the regression formula (e.g.,
"y ~ x1 + x2").- n_boot
Integer. Number of bootstrap samples to use for constructing the SCBs. Default is 5000.
- alpha
Numeric. Significance level for the confidence bands (e.g., 0.05 for 95% SCBs). Default is 0.05.
- type
A character string specifying the model type. Either
"linear"(default) or"logistic".
Value
A data frame with the following columns:
- scb_low
Lower bound of the simultaneous confidence band. The first row corresponds to the intercept, and subsequent rows correspond to regression coefficients.
- Mean
Estimated values. The first element is the intercept estimate, and the remaining are coefficient estimates.
- scb_up
Upper bound of the simultaneous confidence band. The first row corresponds to the intercept, and subsequent rows correspond to regression coefficients.
References
Ren, J., Telschow, F. J. E., & Schwartzman, A. (2024). Inverse set estimation and inversion of simultaneous confidence intervals. Journal of the Royal Statistical Society: Series C (Applied Statistics), 73(4), 1082–1109. doi:10.1093/jrsssc/qlae027
Examples
library(MASS)
set.seed(262)
M <- 5
rho <- 0.4
n <- 100
beta <- rnorm(M, mean = 0, sd = 1)
Sigma <- outer(1:M, 1:M, function(i, j) rho^abs(i - j))
X <- MASS::mvrnorm(n = n, mu = rep(0, M), Sigma = Sigma)
epsilon <- rnorm(n, mean = 0, sd = 1)
y <- X %*% beta + epsilon
df <- as.data.frame(X)
names(df) <- paste0("x", 1:M)
df$y <- as.vector(y)
model <- "y ~ ."
results <- SCB_regression_coef(df, model, n_boot = 100)