reduce_model: Reduce a linear model

Description Usage Arguments Details Value Author(s) See Also Examples

View source: R/reduce_model.R

Description

The procedure takes a linear model of class lm (including the output from a stepwise procedure given by step) and reduces it by iteratively deleting predictors based on pvalues of the t-tests (see 'Details').

Usage

1
2
3
4
reduce_model(model, ...)

## S3 method for class 'lm'
reduce_model(model, data, alpha = 0.05, intercept = TRUE)

Arguments

model

An object of class "lm".

data

A data.frame or data.table with all components of model.

alpha

The significance level at which to cut off predictors. Default is 5%.

intercept

Specify whether the reduction procedure has to consider an intercept or not. Default is TRUE.

Details

The procedure makes use of the workhorse function of lm: lm.fit. This allows to explicitly specify the design matrix which enables to split main effects from interactions. In particular, conversely to what the function lm currently does, it allows the inclusion of just high order effects. For instance, it can fit just interaction terms given by x1*x2 or x1:x2 passed with the usual R formula notation.

Value

reduce_model returns an object of class "lm" with the same components (see lm for a complete list).

Author(s)

Francesco Grossetti francesco.grossetti@gmail.com.

See Also

lm.fit lm step

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
data_factor = mtcars
data_factor$am = as.factor( data_factor$am )
levels( data_factor$am ) = c( "no", "yes" )

complete_model = lm( hp ~ qsec + cyl + mpg + disp + drat + wt + qsec + vs +
                     am + gear + carb + am:qsec, data = data_factor )
summary( complete_model )

reduced_model = reduce_model( complete_model, data = data_factors )
summary( reduced_model )

contefranz/statutils documentation built on May 13, 2019, 10:50 p.m.