pStepwise: Selects the best predictors for a linear model based on...

Description Usage Arguments Value Author(s) See Also Examples

Description

This function will attempt to create the "best' linear model by finding the most significant predictors. A predictor will be included/excluded in the final model if when it is added/removed its p-value is below/above a certain threshold.

Usage

1
2
3
pStepwise(response, fullmodel, aEnter = 0.1,
                 aRemove = 0.1, forcedIn = NULL, forcedOut = NULL,
                 method = "both", plotRes = FALSE)

Arguments

response

the response variable of interest in the model

fullmodel

a linear model containing all possible predictors, typically of the form lm(y ~ ., data = data)

aEnter

the threshold for adding new predictors, set to 0.1 by default

aRemove

the threshold for removing predictors from the current model, set to 0.1 by default

forcedIn

a vector of predictors that will be forced into the final model regardless of their p-values

forcedOut

a vector of predictors that will not be included in the final model regardless of their p-values

method

"forward" will only add predictors, "backward" will only remove predictors and "both" will perfrom stepwise. "both" by default

plotRes

option to print residual plots. plotRes = TRUE will include normailty plot and fit vs. residual plots. FALSE by defult.

Value

a linear model of type lm containing the "best" predictors

Author(s)

Cory Langille <lang1729@gmail.com>

See Also

extractp, stepfwd, stepbwd, fMaker

Examples

1
2
3
4
5
6
7
#Using the leafshape dataset from the DAAG package
data(leafshape)
attach(leafshape)
response <- "bladelen"
fullmodel <- lm(bladelen ~ . , data = leafshape)
forcedOut <- c("loglen", "logwid", "logpet" )
pStepwise(response, fullmodel, forcedOut = forcedOut)

c-langille/pStepwise documentation built on May 13, 2019, 9:55 a.m.