[R] remove higher order interaction terms

Liviu Andronic landronimirc at gmail.com
Wed Apr 17 14:23:10 CEST 2013


Dear all,
Consider the model below:

> x <- lm(mpg ~ cyl * disp * hp * drat, mtcars)
> summary(x)

Call:
lm(formula = mpg ~ cyl * disp * hp * drat, data = mtcars)

Residuals:
    Min      1Q  Median      3Q     Max
-3.5725 -0.6603  0.0108  1.1017  2.6956

Coefficients:
                   Estimate Std. Error t value Pr(>|t|)
(Intercept)       1.070e+03  3.856e+02   2.776  0.01350 *
cyl              -2.084e+02  7.196e+01  -2.896  0.01052 *
disp             -6.760e+00  3.700e+00  -1.827  0.08642 .
hp               -9.302e+00  3.295e+00  -2.823  0.01225 *
drat             -2.824e+02  1.073e+02  -2.633  0.01809 *
cyl:disp          1.065e+00  5.034e-01   2.116  0.05038 .
cyl:hp            1.587e+00  5.296e-01   2.996  0.00855 **
disp:hp           7.422e-02  3.461e-02   2.145  0.04769 *
cyl:drat          5.652e+01  2.036e+01   2.776  0.01350 *
disp:drat         1.824e+00  1.011e+00   1.805  0.08990 .
hp:drat           2.600e+00  9.226e-01   2.819  0.01236 *
cyl:disp:hp      -1.050e-02  4.518e-03  -2.323  0.03368 *
cyl:disp:drat    -2.884e-01  1.392e-01  -2.071  0.05484 .
cyl:hp:drat      -4.428e-01  1.504e-01  -2.945  0.00950 **
disp:hp:drat     -2.070e-02  9.568e-03  -2.163  0.04600 *
cyl:disp:hp:drat  2.923e-03  1.254e-03   2.331  0.03317 *
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 2.245 on 16 degrees of freedom
Multiple R-squared: 0.9284,	Adjusted R-squared: 0.8612
F-statistic: 13.83 on 15 and 16 DF,  p-value: 2.007e-06


Is there a straightforward way to remove the highest order interaction
terms? Say:
cyl:disp:hp
cyl:disp:drat
cyl:hp:drat
disp:hp:drat
cyl:disp:hp:drat

I know I could do this:
> x <- lm(mpg ~ cyl * disp * hp * drat - cyl:disp:hp - cyl:disp:drat - cyl:hp:drat - disp:hp:drat - cyl:disp:hp:drat, mtcars)

But I was hoping for a more elegant solution. Regards,
Liviu



More information about the R-help mailing list