Re: [R] lm() and interactions in model formula for x passed as matrix

2010-12-05 Thread William Simpson
Thanks for the replies. I was just thinking that, for a two variable example, doing X<-cbind(x1,x2,x1*x2) lm(y~X) would work. So maybe that's what I'll do. This also allows me to pick and choose which interactions to include. Cheers Bill On Sun, Dec 5, 2010 at 8:19 PM, William Simpson wrote: >

Re: [R] lm() and interactions in model formula for x passed as matrix

2010-12-05 Thread Joshua Wiley
Hi Bill, If you can put all (and only) your variables into a dataframe, (for example: X <- data.frame(y, x1, x2, x3) ) then another alternative to David's solution would be: lm(y ~ .^3, data = X) '.' will expand to every column except y, and then the ^3 will get you up to 3-way interactions. C

Re: [R] lm() and interactions in model formula for x passed as matrix

2010-12-05 Thread David Winsemius
On Dec 5, 2010, at 3:19 PM, William Simpson wrote: Suppose I have x variables x1, x2, x3 (however in general I don't know how many x variables there are). I can do X<-cbind(x1,x2,x3) lm(y ~ X) This fits the no-interaction model with b0, b1, b2, b3. How can I get lm() to fit the model that incl

[R] lm() and interactions in model formula for x passed as matrix

2010-12-05 Thread William Simpson
Suppose I have x variables x1, x2, x3 (however in general I don't know how many x variables there are). I can do X<-cbind(x1,x2,x3) lm(y ~ X) This fits the no-interaction model with b0, b1, b2, b3. How can I get lm() to fit the model that includes interactions when I pass X to lm()? For my example