StepReg is an R package that streamlines stepwise regression analysis by supporting multiple regression types, incorporating popular selection strategies, and offering essential metrics.
::pkg_install("StepReg") pak
or
install.packages("StepReg")
::install_github("JunhuiLi1017/StepReg") devtools
library(StepReg)
# Basic linear regression
data(mtcars)
<- mpg ~ .
formula <- stepwise(
res formula = formula,
data = mtcars,
type = "linear",
strategy = "bidirection",
metric = "AIC"
)
# View results
ressummary(res$bidirection$AIC)
library(survival)
data(lung)
$sex <- factor(lung$sex)
lung
# Cox regression with strata
<- Surv(time, status) ~ age + sex + ph.ecog + strata(inst)
formula <- stepwise(
res formula = formula,
data = lung,
type = "cox",
strategy = "forward",
metric = "AIC"
)
data(mtcars)
$am <- factor(mtcars$am)
mtcars
# Nested effects
<- mpg ~ am + wt:am + disp:am + hp:am
formula <- stepwise(
res 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.