[R] lm() and interactions in model formula for x passed as matrix
William Simpson
william.a.simpson at gmail.com
Sun Dec 5 22:57:57 CET 2010
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
<william.a.simpson at gmail.com> 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 includes interactions when I
> pass X to lm()? For my example,
> lm(y~x1*x2*x3)
> I am looking for something along the lines of
> lm(y~X ...)
> where ... is some extra stuff I need to fill in.
>
> Thanks for any help.
> Bill
>
More information about the R-help
mailing list