if (requireNamespace("logistf", quietly = TRUE)) {
library(logistf)
data <- mtcars
data$am <- as.factor(data$am)
regression_model <- logistf(am ~ mpg + cyl + disp, data = data)
# Perform backward stepwise, forcing 'cyl' to remain
stepwise <- step_bw_firth(
regression_model,
forced = c("cyl"),
p_threshold = 0.05,
trace = FALSE
)
final_model <- stepwise$final_model
# Show steps and summary
stepwise$steps
summary(final_model)
}
Run the code above in your browser using DataLab