Skip to content
Prev 243978 / 398506 Next

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

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.

Cheers,

Josh

On Sun, Dec 5, 2010 at 12:19 PM, William Simpson
<william.a.simpson at gmail.com> wrote: