I have a model
lm = a ~ b
I would like to include c, d , e that represent interactions terms with b =>
lm = a ~ b + b:c + b:d + b:e.
Is there a rapid way to obtain this result without taping each variable? I have more than 10 variables.
In R formulas, .
is a placeholder for all non-response variables present in the data.
coef(lm(mpg ~ wt:(.), data = mtcars))
# (Intercept) wt wt:cyl wt:disp wt:hp wt:drat wt:qsec
# 41.044844014 -16.742131313 0.028771226 0.006485611 -0.005048411 0.447194218 0.423909109
# wt:vs wt:am wt:gear wt:carb
# -0.087023686 0.402891966 -0.142805986 0.156345459
a ~ b + b:c + b:d + b:e
. You can use parentheses to save a tiny bit of typing,a ~ b + b:(c + d + e)
. You can use.
as a stand-in for all non-response variables in the data,a ~ b:(.)
. Is that what you're looking for?b:(.)
it is then.