[R] Using model operator in stepwise function's upper scope formula
Yu Shao
yshao at wadsworth.org
Tue Oct 5 01:39:33 CEST 2004
Hello:
I am doing forward stepwise analysis on the glm model. I am trying to use model
operator in the "upper" scope formula, for example,
scope=list(lower=~1,upper=~ .^2)
but the upper bound of the scope seems to be ignored and add1 is not performed
at all, while if the terms are explicitly listed in the formula, the step
function seems to work properly. Example:
> version
platform sparc-sun-solaris2.9
arch sparc
os solaris2.9
system sparc, solaris2.9
status
major 1
minor 9.0
year 2004
month 04
day 12
language R
> testdata
effect fa1 fa2 fa3
1 0.5054526 -1.4 1 -15.42
2 0.1366526 -2.5 3 -14.72
3 0.4798526 -1.1 3 -16.43
4 0.5566526 -4.6 2 -17.62
5 0.6568526 -3.5 7 -5.41
6 0.6653526 0.0 5 -11.88
7 0.6376526 0.0 5 -11.72
8 0.5203526 -2.9 -1 -14.72
9 0.4905526 -2.1 2 -17.68
10 0.6376526 -1.1 1 -13.39
> step (glm(effect ~ 1 , data=testdata), scope=list(lower=~1,upper=~.),
direction='forward')
Start: AIC= -5.89
effect ~ 1
Call: glm(formula = effect ~ 1, data = testdata)
Coefficients:
(Intercept)
0.5287
Degrees of Freedom: 9 Total (i.e. Null); 9 Residual
Null Deviance: 0.2178
Residual Deviance: 0.2178 AIC: -5.89
================================================================
But if I listed the term explicitly in the formula, then step function seemed to
work correctly:
> step (glm(effect ~ 1 , data=testdata),
scope=list(lower=~1,upper=~fa1+fa2+fa3), direction='forward')
Start: AIC= -5.89
effect ~ 1
Df Deviance AIC
+ fa3 1 0.1778 -5.9188
<none> 0.2178 -5.8901
+ fa2 1 0.2023 -4.6271
+ fa1 1 0.2065 -4.4194
Step: AIC= -5.92
effect ~ fa3
Df Deviance AIC
<none> 0.1778 -5.9188
+ fa1 1 0.1698 -4.3783
+ fa2 1 0.1770 -3.9605
Call: glm(formula = effect ~ fa3, data = testdata)
Coefficients:
(Intercept) fa3
0.78310 0.01830
Degrees of Freedom: 9 Total (i.e. Null); 8 Residual
Null Deviance: 0.2178
Residual Deviance: 0.1778 AIC: -5.919
================================================================
I've lookup the online manual of step function but couldn't find a solution.
Thanks in advance,
Yu Shao
Wadsworth Center, New York State Department of Health,
Albany, NY 12208
More information about the R-help
mailing list