[R] scope argument in step function

Prof Brian Ripley ripley at stats.ox.ac.uk
Sat Jul 2 08:41:44 CEST 2005


>  What I wondered is if I pass the 'upper=~.' ,
> it seems step() thinks the full model is current one. Not adding
> anymore. If this is the right answer, is there a better way than
> creating fmla argument in the above?

Yes, that is exactly what the help page for step says it means. (So why 
are you unsure and asking?)

upper = terms(Response ~ ., data=ds3))

would appear to be a simpler way to get your intention.


On Fri, 1 Jul 2005, Young Cho wrote:

> Thanks a lot for help in advance. I am switching from matlab to R and I 
> guess I need some time to get rolling. I was wondering why this code :
>
>> fit.0 <- lm( Response ~ 1, data = ds3)
>> step(fit.0,scope=list(upper=~.,lower=~1),data=ds3)
> Start:  AIC= -32.66
> Response ~ 1
>
> Call:
> lm(formula = Response ~ 1, data = ds3)
> Coefficients:
> (Intercept)
>      1.301
>
>
> is not working different from the following:
>
>>
>> cnames <- dimnames(ds3)[[2]]
>> cnames <- cnames[-444]        # last col is Response
>>
>> fmla <- as.formula(paste(" ~ ",paste(cnames,collapse="+")))
>> step(fit.0,scope=list(upper=fmla,lower=~1),data=ds3)
> Start:  AIC= -32.66
> Response ~ 1
>> fmla <- as.formula(paste(" ~ ",paste(cnames,collapse="+")))
>> fit.s <- step(fit.0,scope=list(upper=fmla,lower=~1),data=ds3)
>
> Step:  AIC= -Inf
> Response ~ ENTP9324 + CH1W0281
>           Df Sum of Sq     RSS  AIC
> <none>                        0 -Inf
> - CH1W0281  3   0.00381 0.00381 -115
> - ENTP9324  9         1       1  -34
>
> The dataframe ds3 is 17 by 444 and I understand it is not smart thing to 
> run stepwise regression. What I wondered is if I pass the 'upper=~.' , 
> it seems step() thinks the full model is current one. Not adding 
> anymore. If this is the right answer, is there a better way than 
> creating fmla argument in the above?


-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595




More information about the R-help mailing list