Construct Simultaneous Confidence Bands for a Logistic Regression Outcome
Source:R/regression_outcome_scb.R
SCB_logistic_outcome.RdThis function fits a logistic regression model and constructs simultaneous confidence bands (SCB) using a non-parametric bootstrap method for the mean outcome of regression on a fixed test set design matrix
Arguments
- df_fit
A data frame containing the training design matrix used to fit the logistic model.
- model
A character string representing the formula for the logistic model (e.g.,
"y ~ x1 + x2").- grid_df
A data frame specifying the covariate settings that define the mean outcome for which simultaneous confidence bands (SCB) are constructed. Each row represents one covariate combination at which predictions and SCBs are evaluated. Column names should match variables in the fitted model, but
grid_dfmay include only the subset of covariates of interest for the SCB (it is not required to cover all model variables). Default isNULL, in which case the SCB is constructed over the fitted values based on 'df_fit`.- n_boot
Number of bootstrap samples used in the non-parametric bootstrap procedure to generate the empirical distribution. Default is 1000.
- alpha
Significance level for the confidence band (e.g., 0.05 for 95% confidence). Default is 0.05.
Value
A data frame with the following columns:
- scb_low
Lower bound of the simultaneous confidence band.
- Mean
Predicted mean response from the fitted model.
- scb_up
Upper bound of the simultaneous confidence band.
- ...
All columns from
grid_df, representing the prediction grid.
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
set.seed(262)
x1 <- rnorm(100)
mu <- -1 + x1
p <- expit(mu)
y <- rbinom(100, size = 1, prob = p)
df <- data.frame(x1 = x1, y = y)
grid <- data.frame(x1 = seq(-1, 1, length.out = 100))
model <- "y ~ x1"
results <- SCB_logistic_outcome(df_fit = df, model = model, grid_df = grid, n_boot = 100)