stepwise_regression: Perform automated stepwise regression

View source: R/stepwise_regression.R

stepwise_regressionR Documentation

Perform automated stepwise regression

Description

stepwise_regression() performs automated stepwise regression on a set of models differing by an independent variable of interest. All original full models share the same dependent variable and covariates, but differ by their independent variable of interest.

From each original full model, a minimal model (dependent variable ~ independent variable of interest), a forward selection model, a stepwise selection model and a backward elimination model are generated. For each independent variable of interest, 5 distinct models are therefore produced (original full, minimal, forward selection, stepwise selection, backward elimination).

For all models, the adjusted R square, the F statistic, and the t statistic related to the independent variable of interest are computed. For stepwise regression models only (forward selection, stepwise selection, backward elimination), the AIC value is also computed. Note that the AIC and F values are computed only if df > 0, which implies n.obs > n.independent.variables +1 (intercept).

Models which display an F p value <= 0.05 AND a t p value (related to the independent variable of interest) <= 0.05 are labelled sign = TRUE.

Usage

stepwise_regression(tibble, dep_var, indep_oi, grps, hackfull = FALSE)

Arguments

tibble

a tibble containing ONLY i) the column with the values of the dependent variable, ii) the column with the names of the independent variables of interest, iii) the column with the values of the independent variables of interest, iv) the column(s) with the categorical variable(s) on which the independent variables of interest should be conditioned, and v) the column(s) with the values of the covariate(s).

dep_var

a string indicating the column with the values of the dependent variable.

indep_oi

a string indicating the column with the values of the independent variables of interest.

grps

a character vector indicating i) the column with the names of the independent variables of interest, and optionally ii) the column(s) with the categorical variable(s) on which the independent variables of interest should be conditioned.

hackfull

a logical indicating whether the analysis should be restricted to the full models.

Value

A tibble containing, for each (possibly conditioned) independent variable of interest, all five models (original full, minimal, forward selection, stepwise selection, backward elimination) and their respective statistics (AIC, adjusted R square, F statistic, t statistic related to the independent variable of interest, "sign" label).


benvallin/banban documentation built on Sept. 29, 2023, 5:46 a.m.