forward: F-test based model effect selection for linear models.

Description Usage Arguments Details Value Author(s) Examples

Description

Adaptation of existing methods based on AIC/BIC.

Usage

1
2
3
4
forward(model, alpha = 0.2, full = FALSE, force.in)
backward(model, alpha = 0.2, full = FALSE, hierarchy = TRUE, force.in)
stepWise(model, alpha.enter = 0.15, alpha.remove = 0.15, full = FALSE)
stepWiseBack(model, alpha.remove = 0.15, alpha.enter = 0.15, full = FALSE)

Arguments

model

object class lm to select effects from.

alpha

numeric p-value cut-off for inclusion/exclusion.

full

logical indicating extended output of forward/backward selection.

force.in

character vector indicating effects to keep in all models.

alpha.enter

numeric p-value cut-off for inclusion.

alpha.remove

numeric p-value cut-off for exclusion.

hierarchy

logical indicating if hierarchy should be forced in backward selection.

Details

F-based versions of built in stepwise methods.

Value

The final linear model after selection is returned.

Author(s)

Kristian Hovde Liland

Examples

1
2
3
4
5
6
7
8
data <- data.frame(y = rnorm(8),
				   x = factor(c('a','a','a','a','b','b','b','b')),
				   z = factor(c('a','a','b','b','a','a','b','b')))
mod <- lm(y ~ x + z, data=data)
forward(mod)
backward(mod)
stepWise(mod)
stepWiseBack(mod)

Example output

Attaching package:mixlmThe following objects are masked frompackage:stats:

    glm, lm

Forward selection, alpha-to-enter: 0.2

Full model: y ~ x + z
<environment: 0x55edd72c0290>

  Step    RSS     AIC   R2pred     Cp F value Pr(>F)
z    1 3.9168 -1.7133 -0.27761 1.6044  2.3489 0.1763

Call:
lm(formula = y ~ z, data = data)

Coefficients:
(Intercept)         z(a)  
     0.6047       0.4378  

Backward elimination, alpha-to-remove: 0.2

Full model: y ~ x + z
<environment: 0x55edd7655908>

  Step    RSS     AIC   R2pred     Cp F value Pr(>F)
x    1 3.9168 -1.7133 -0.27761 1.6044  0.6044 0.4721

Call:
lm(formula = y ~ z, data = data)

Coefficients:
(Intercept)         z(a)  
     0.6047       0.4378  

Stepwise regression (forward-backward), alpha-to-enter: 0.15, alpha-to-remove: 0.15

Full model: y ~ x + z
<environment: 0x55edd785d848>

[1] "No iterations performed (re-run using extended output for details)"

Call:
lm(formula = y ~ 1, data = data)

Coefficients:
(Intercept)  
     0.6047  

Stepwise regression (backward-forward), alpha-to-remove: 0.15, alpha-to-enter: 0.15

Full model: y ~ x + z
<environment: 0x55edd797a008>

  Step InOut    RSS     AIC   R2pred     Cp F value Pr(>F)
x    1    -1 3.9168 -1.7133 -0.27761 1.6044  0.6044 0.4721
z    2    -1 5.4502 -1.0703 -0.30612 1.7984  2.3489 0.1763

Call:
lm(formula = y ~ 1, data = data)

Coefficients:
(Intercept)  
     0.6047  

mixlm documentation built on May 2, 2019, 6:08 p.m.

Related to forward in mixlm...