Stepwise regression is a statistical technique used for model selection. This package streamlines stepwise regression analysis by supporting multiple regression types(linear, Cox, logistic, Poisson, Gamma, and negative binomial), incorporating popular selection strategies(forward, backward, bidirectional, and subset), and offering essential metrics. It enables users to apply multiple selection strategies and metrics in a single function call, visualize variable selection processes, and export results in various formats. StepReg offers a data-splitting option to address potential issues with invalid statistical inference and a randomized forward selection option to avoid overfitting. We validated StepReg's accuracy using public datasets within the SAS software environment. For an interactive web interface, users can install the companion 'StepRegShiny' package. The methodology is described in Li et al. (2026)

StepReg is an R package that streamlines stepwise regression analysis by supporting multiple regression types, incorporating popular selection strategies, and offering essential metrics.
pak::pkg_install("StepReg")
or
install.packages("StepReg")
devtools::install_github("JunhuiLi1017/StepReg")
library(StepReg)
# Basic linear regression
data(mtcars)
formula <- mpg ~ .
res <- stepwise(
formula = formula,
data = mtcars,
type = "linear",
strategy = "bidirection",
metric = "AIC"
)
# View results
res
summary(res$bidirection$AIC)
library(survival)
data(lung)
lung$sex <- factor(lung$sex)
# Cox regression with strata
formula <- Surv(time, status) ~ age + sex + ph.ecog + strata(inst)
res <- stepwise(
formula = formula,
data = lung,
type = "cox",
strategy = "forward",
metric = "AIC"
)
data(mtcars)
mtcars$am <- factor(mtcars$am)
# Nested effects
formula <- mpg ~ am + wt:am + disp:am + hp:am
res <- stepwise(
formula = formula,
data = mtcars,
type = "linear",
strategy = "bidirection",
metric = "AIC"
)
StepReg should NOT be used for statistical inference unless the variable selection process is explicitly accounted for, as it can compromise the validity of the results. This limitation does not apply when StepReg is used for prediction purposes.
If you use StepReg in your research, please cite:
citation("StepReg")
Please raise an issue here.