Here we applied StepReg to the well-known mtcars data and lung data for clarifying how to perform linear, logistic and Cox stepwise regression.
#install.package("StepReg") library(StepReg)
formula <- mpg ~ . sForwAIC <- stepwise(formula=formula, data=mtcars, selection="forward", select="AIC") sForwAIC
From the above result, we can see that stepwise() output a list with 5 tables.
'Summary of Parameters' tells you what parameters is used for this function, where Intercept equals to 1 showing that this stepwise regression has a intercept, otherwise 0 has not a intercept.
'Variables Type' is the summary of the type of all variables.
'Process of Selection' let you know how variables are selected, we used AIC as the criteria so the last column is value of AIC.
'Coefficients of the Selected Variables' is the coefficients of all selected variable.
formula <- mpg ~ . sBidiSL <- stepwise(formula=formula, data=mtcars, selection="bidirection", select="SL", sle=0.15, sls=0.15) sBidiSL
The output of this time is similar to the last time except that the last column name of 'Process of Selection' is SL.
#formula <- mpg ~ . -1 formula <- mpg ~ . + 0 sBackSBC <- stepwise(formula=formula, data=mtcars, selection="backward", select="SBC") sBackSBC
Note that 0 instead of 1 in table 'Summary of Parameters' and 'Selected Varaibles'.
formula <- cbind(mpg,drat) ~ cyl+disp+hp+wt+vs+am stepwise(formula=formula, data=mtcars, include='wt', selection="score", select="AICc")
formula <- am ~ . stepwiseLogit(formula=formula, data=mtcars, selection="forward", select="AIC")
formula <- am ~ . stepwiseLogit(formula=formula, data=mtcars, selection="score", select="SL", best=3)
lung <- survival::lung my.data <- na.omit(lung) my.data$status1 <- ifelse(my.data$status==2,1,0) data <- my.data formula = Surv(time, status1) ~ . - status stepwiseCox(formula=formula, data=my.data, selection="forward", select="IC(1)")
formula = Surv(time, status1) ~ . - status stepwiseCox(formula=formula, data=my.data, selection="score", select="SL", best=3)
sessionInfo()
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.