3. Previously in this group
n Introduction n Graphics
n Reading Data into R (1) n Groupwise, continuous
n Reading Data into R (2) n Linear regression
n Descriptive, continuous
n Descriptive, categorical
n Deducer
10. Models
Partial F-test
Difference in residual SS
Residual sum of squares
Residual degree of freedom Significant
11. Backward elimination
Specify full model
lm.step.bw <- step(lm.full, direction = "backward")
Final model object
12. Initial
AIC Removing ftv.cat
for full makes AIC smallest
model
Removing age
makes AIC smallest
Doing nothing
makes AIC smallest
13. Forward selection
Final model object
Specify null model
lm.step.fw <- step(lm.null,
scope = ~ age + lwt + smoke + ht + ui + ftv.cat +
race.cat + preterm,
direction = "forward")
formula for possible
variables
14. Initial
AIC
for Adding ui
null makes AIC smallest
model
Adding race.cat
makes AIC smallest
Adding smoke
makes AIC smallest
Still goes on ...
15. Stepwise selection/elimination
Final model object
Specify null model
lm.step.both <- step(lm.null,
scope = ~ age + lwt + smoke + ht + ui + ftv.cat +
race.cat + preterm,
direction = "both")
formula for possible
variables
16. Initial
AIC Adding ui
for makes AIC smallest
null
model
Adding race.cat
Removing is makes AIC smallest
also considered
Adding smoke
Removing is makes AIC smallest
also considered
Still goes on ...
17. F-test using drop1()
## age is the least significant by partial F test
drop1(lm.full, test = "F")
## After elimination, ftv.cat is the least significant
drop1(update(lm.full, ~ . -age), test = "F")
## After elimination, preterm is least significat at p = 0.12.
drop1(update(lm.full, ~ . -age -ftv.cat), test = "F")
## After elimination, all variables are significant at p < 0.1
drop1(update(lm.full, ~ . -age -ftv.cat -preterm), test = "F")
## Show summary for final model
summary(update(lm.full, ~ . -age -ftv.cat -preterm))
18. Updating models
## Remove age from full model
lm.age.less <- update(lm.full, ~ . -age)
all variables(.) minus age
## Adding ui to null model
lm.ui.only <- update(lm.null, ~ . +ui)
all variables (.) plus ui
19. test full model
age least significant
F-test comparing age-in
model to age-out model
remove age, and test
ftv.cat least significant
remove age, ftv.cat
20. F-test using add1()
## ui is the most significant variable
add1(lm.null, scope = ~ age + lwt + race.cat + smoke + preterm +
+ ui + ftv.cat, test = "F")
## After inclusion, race.cat is the most significant
add1(update(lm.null, ~ . +ui), scope = ~ age + lwt + race.cat +
smoke + preterm + ht + ui + ftv.cat, test = "F")
## After inclusion, smoke is the most significant
add1(update(lm.null, ~ . +ui +race.cat), scope = ~ age + lwt +
race.cat + smoke + preterm + ht + ui + ftv.cat, test = "F")
## After inclusion, ht is the most significant
add1(update(lm.null, ~ . +ui +race.cat +smoke), scope = ~ age + l
+ race.cat + smoke + preterm + ht + ui + ftv.cat, test = "F")
...
21. test null model
ui most significant
F-test comparing ui-out
model to ui-in model
add ui, and test
race.cat most significant
add ui and race.cat
28. subsets(regsubsets.out, statistic="cp", legend = FALSE,
min.size = 5, main = "Mallow Cp")
First model for which Mallow
Cp is less than number of
regressors + 1
~ lwt + smoke + ht + ui
+ race.cat + preterm