[R] lm() with same formula but different column/factor combinations in data frame

2008-12-26 Thread Murtaza Das
Hi, I am trying to find an efficient way of applying a linear regression model to different factor combinations in a data frame. I want to obtain the output with minimal or no use of loops if possible. Please let me know if this query is unclear. Thanks, Murtaza

Re: [R] lm() with same formula but different column/factor combinations in data frame

2008-12-26 Thread Gabor Grothendieck
See the leaps package. On Fri, Dec 26, 2008 at 12:37 PM, Murtaza Das murtaza...@gmail.com wrote: Hi, I am trying to find an efficient way of applying a linear regression model to different factor combinations in a data frame. I want to obtain the output with minimal or no use of loops if

Re: [R] lm() with same formula but different column/factor combinations in data frame

2008-12-26 Thread Murtaza Das
Thanks for replying Gabor. I checked the leaps() function and i think it is intended to find the best combination of predictors in the linear model. Does leaps have a way to combine different factor columns in my data frame as follows : I have the regression model fixed. The combination of

Re: [R] lm() with same formula but different column/factor combinations in data frame

2008-12-26 Thread Gabor Grothendieck
Try variations of this: library(leaps) b-regsubsets(Fertility~.,data=swiss) w - summary(b)$which lapply(1:nrow(w), function(i) coef(lm(Fertility ~., swiss[w[i, ]]))) On Fri, Dec 26, 2008 at 1:57 PM, Murtaza Das murtaza...@gmail.com wrote: Thanks for replying Gabor. I checked the leaps()