head(mtcars)
mpg cyl disp hp drat wt qsec vs am gear carb
Mazda RX4 21.0 6 160 110 3.90 2.620 16.46 0 1 4 4
Mazda RX4 Wag 21.0 6 160 110 3.90 2.875 17.02 0 1 4 4
Datsun 710 22.8 4 108 93 3.85 2.320 18.61 1 1 4 1
Hornet 4 Drive 21.4 6 258 110 3.08 3.215 19.44 1 0 3 1
Hornet Sportabout 18.7 8 360 175 3.15 3.440 17.02 0 0 3 2
Valiant 18.1 6 225 105 2.76 3.460 20.22 1 0 3 1
unique(mtcars$cyl)
[1] 6 4 8
unique(mtcars$gear)
[1] 4 3 5
summary(lm(mpg ~ as.factor(cyl) * as.factor(gear),data=mtcars))
Call:
lm(formula = mpg ~ as.factor(cyl) * as.factor(gear), data = mtcars)
Residuals:
Min 1Q Median 3Q Max
-5.525 -1.800 0.075 1.425 6.975
Coefficients: (1 not defined because of singularities)
Estimate Std. Error t value Pr(>|t|)
(Intercept) 21.500 3.349 6.421 1.22e-06 ***
as.factor(cyl)6 -1.750 4.101 -0.427 0.6734
as.factor(cyl)8 -6.450 3.485 -1.851 0.0766 .
as.factor(gear)4 5.425 3.552 1.527 0.1397
as.factor(gear)5 6.700 4.101 1.634 0.1154
as.factor(cyl)6:as.factor(gear)4 -5.425 4.585 -1.183 0.2483
as.factor(cyl)8:as.factor(gear)4 NA NA NA NA
as.factor(cyl)6:as.factor(gear)5 -6.750 5.800 -1.164 0.2559
as.factor(cyl)8:as.factor(gear)5 -6.350 4.833 -1.314 0.2013
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 3.349 on 24 degrees of freedom
Multiple R-squared: 0.761, Adjusted R-squared: 0.6913
F-statistic: 10.92 on 7 and 24 DF, p-value: 3.921e-06
What are the correct values for the main and interaction effects of the reference categories? If listed, I imagine they would hypothetically be:
Estimate Std. Error t value Pr(>|t|)
as.factor(cyl)4 0 0 0 0
as.factor(gear)3 0 0 0 0
as.factor(cyl)4:as.factor(gear)3 0 0 0 0
Thank you!