[R] creating subsets within lm()

Alain Zuur highstat at highstat.com
Thu Jul 30 12:32:04 CEST 2009



Thomas A. Groen wrote:
> 
> Dear All,
> 
> the lm() function has the possibility to create a subset of the
> possible explaining variables that you have. However, in the help
> there is no example how to use this subset option. I tried the
> following:
> 
> model<-lm(dependent.data$MPFD~.,data=explaining.data,subset=c(1,0,0,0,0,0,0,0,1,1,0,0))
> 
> MPFD is the dependent variable stored in the data frame
> dependent.data, and all 12 explaining variables are stored in the data
> frame explaining.data.
> 
> However, this yields a model with only an intercept, and the comment
> 
> "Coefficients: (12 not defined because of singularities)"
> 
> I hope anyone would be able to give me an example how to do this
> correctly.
> 
> Kind regards,
> Thomas
> 
> 
> 
> 
> 
> 
> 
> 
> _______________________________
> 
> 



The subset option works on the rows of the data set. Not on the covariates.
You would have to do something like:

lm(blah blah, data=explaining.data[, pick your columns])
 

Alain Zuur

-----
--------------------------------------------------------------------
Dr. Alain F. Zuur
First author of:

1. Analysing Ecological Data (2007).
Zuur, AF, Ieno, EN and Smith, GM. Springer. 680 p.

2. Mixed effects models and extensions in ecology with R. (2009).
Zuur, AF, Ieno, EN, Walker, N, Saveliev, AA, and Smith, GM. Springer.

3. A Beginner's Guide to R (2009).
Zuur, AF, Ieno, EN, Meesters, EHWG. Springer


Statistical consultancy, courses, data analysis and software
Highland Statistics Ltd.
6 Laverock road
UK - AB41 6FN Newburgh
Email: highstat at highstat.com
URL: www.highstat.com



-- 
View this message in context: http://www.nabble.com/creating-subsets-within-lm%28%29-tp24735798p24735931.html
Sent from the R help mailing list archive at Nabble.com.




More information about the R-help mailing list