# Including main effects in a model

I understand similar questions have been asked and thoroughly answered in this forum, but I wasn't sure whether they are applicable to the problem I have. Basically, I have two groups (g), and I want to know whether there is a difference between them in terms of the association between y and x (continuous). So, the linear model would be:

y ~ x + g + x:g


However, I'm not sure whether the inclusion of the main effects (x and g) is necessary in my case. Wouldn't it be fine to merely have:

y ~ x:g


It does change the p-value associated with the interactions depending on whether I include the main effects or not. So which of the above two models should I be using? Thanks!

• Try to state the model formula mathematically correct (instead of pseudo-math). Then maybe you can answer the question alone. Sep 11, 2016 at 9:14

I assume that you are using R. You definitely need the first model. The second formula you give defines two linear regression lines with a common intercept, which doesn't sound what you want. This model has only 3 parameters whereas you need 4 parameters to represent two independent regression lines. It estimates the two slopes but doesn't estimate any interaction parameters.

You actually need to fit two models, one with 2 parameters and one with 4, to test for a difference in association.

I'm make up some random data as an illustration:

> y <- rnorm(6)
> g <- factor(c(1,1,1,2,2,2))
> x <- rnorm(6)


First we fit the null hypothesis, which assumes a simple linear relationship between x and y, same for both groups:

> fit1 <- lm(y~x)


Then we fit the interaction model which allows different intercepts and slopes for the two groups:

> fit2 <- lm(y~g*x)


Then we do an F-test for whether the second model is a better fit than the first:

> anova(fit1, fit2)

Analysis of Variance Table
Model 1: y ~ x
Model 2: y ~ g * x
Res.Df     RSS Df Sum of Sq      F Pr(>F)
1      4 2.44208
2      2 0.92733  2    1.5147 1.6334 0.3797


This gives F=1.6 on 2 and 2 df, corresponding to P=0.3797. The F-test is an 2 df because we are testing equality of the two intercepts and of the two slopes at the same time.

Personally, I prefer to fit the interaction model like this:

> fit2 <- lm(y ~ 0+g+g:x)


because this formulation allows one to see the intercepts and slopes for groups 1 and 2:

> summary(fit2)

Call:
lm(formula = y ~ 0 + g + g:x)

Coefficients:
Estimate Std. Error t value Pr(>|t|)
g1    0.378765   0.964633   0.393    0.732
g2   -0.668657   0.462963  -1.444    0.285
g1:x  0.057329   1.764490   0.032    0.977
g2:x  0.008416   0.276834   0.030    0.979

Residual standard error: 0.6809 on 2 degrees of freedom
Multiple R-squared:  0.6523,    Adjusted R-squared:  -0.04298
F-statistic: 0.9382 on 4 and 2 DF,  p-value: 0.5745


Here the first two estimates are the intercepts and the 3rd and 4th are the slopes. However it makes no difference to the anova table which way the second model fit2 is parametrized -- rerunning the anova with this fit2 will give the same result as before.