[R] a question regarding leaps

John Fox jfox at mcmaster.ca
Fri Jan 30 04:24:51 CET 2004


Dear Rajarshi,

At 06:43 PM 1/29/2004 -0500, Rajarshi Guha wrote:
>Hi,
>   I'm using regsubsets from the leaps package to select subsets of
>variables. I'm calling the function as
>
>  lp <- regsubsets(x,y,nbest=5,nvmax=9)
>
>Then I call plot to see which variables turned up in the models. I use
>the R^2 scale and see my best model had a R^2 of 0.62.
>
>However when I make a linear model using lm() with the same x my R^2 is
>0.45. Should'nt I be seeing the same value of R^2?
>
>I must be making a mistake somewhere but I'm not sure where - could
>anybody provide a pointer as to what I'm doing wrong?


It's hard to know exactly from your description what the source of the 
problem is, but I'd guess that it's due to missing data: That is, the 
models fit by regsubsets() likely removed observations that were present 
when you fit the model by lm(). If this is the case, then you could make 
the two results consistent by filtering the missing data before using lm().

I hope that this helps,
  John

-----------------------------------------------------
John Fox
Department of Sociology
McMaster University
Hamilton, Ontario, Canada L8S 4M4
email: jfox at mcmaster.ca
phone: 905-525-9140x23604
web: www.socsci.mcmaster.ca/jfox




More information about the R-help mailing list