On Apr 17, 2013, at 7:23 AM, Liviu Andronic <landronim...@gmail.com> wrote:
> 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 If you only want up to say second order interactions: > summary(lm(mpg ~ (cyl + disp + hp + drat) ^ 2, data = mtcars)) Call: lm(formula = mpg ~ (cyl + disp + hp + drat)^2, data = mtcars) Residuals: Min 1Q Median 3Q Max -3.5487 -1.6998 0.0894 1.2366 4.6138 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 9.816e+01 4.199e+01 2.338 0.0294 * cyl -1.656e+01 1.226e+01 -1.351 0.1910 disp 1.333e-03 1.634e-01 0.008 0.9936 hp -1.936e-01 2.260e-01 -0.857 0.4014 drat -8.913e+00 8.745e+00 -1.019 0.3197 cyl:disp 2.134e-02 1.071e-02 1.992 0.0595 . cyl:hp 3.074e-02 1.970e-02 1.560 0.1337 cyl:drat 2.590e+00 2.601e+00 0.996 0.3307 disp:hp -3.846e-04 3.906e-04 -0.985 0.3359 disp:drat -3.518e-02 3.951e-02 -0.890 0.3834 hp:drat 1.210e-02 5.432e-02 0.223 0.8259 --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 Residual standard error: 2.717 on 21 degrees of freedom Multiple R-squared: 0.8623, Adjusted R-squared: 0.7967 F-statistic: 13.15 on 10 and 21 DF, p-value: 6.237e-07 This is covered in ?formula Regards, Marc Schwartz ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.