Consider the below ANCOVA example in which I am trying to predict a continuous varibale `y`

by two variables `x`

(continuous) and `a`

(nominal) and their interaction. As I am also interested in the intercept I am using `summary.lm()`

instead of `summary.aov()`

. My question is: does the significant intercept in the below example represent an overall intercept (across factor levels of `a`

) or does this indicate that there is only a significant intercept in the first factor level (this is suggested here)?

If yes, is there a way to test for an overall intercept within the ANCOVA model?

`set.seed(123) sd1 <- 1 sd2 <- 3.5 n <- 100 x1 <- 2+rnorm(n,0,sd1) x2 <- 2+rnorm(n,0,sd1) y1 <- x1+2+rnorm(n,0,sd2) y2 <- -x2-2+rnorm(n,0,sd2) a <- as.factor(c(rep("a1", n), rep("a2", n))) x <- c(x1,x2) y <- c(y1,y2) m1 <- lm(y1~x1); m2 <- lm(y2~x2) summary(m1); summary(m2) model <- lm(y~x*a) summary.lm(model) `

**Contents**hide

#### Best Answer

The default for (non-ordered) factors in R are treatment contrasts, where the means of the factor levels are tested against the reference category (the first level). In this case, the intercept of the model (and all other coefficients) only hold for the reference level of the categorial variable.

Hence, in your model

`lm(y ~ x * a) `

the coefficients of both the intercept and the predictor `x`

are estimated for the first level of `a`

.

If you want to test the overall intercept, you need to specify another contrast for `a`

, for example a sum contrast. (If `a`

had more than two levels, you had to contstruct a different type of contrast coding to achieve the same tests like treatment contrasts.)

The type of contrast used by `lm`

can be specified with the `contrasts`

parameter:

`lm(y ~ x * a, contrasts = list(a = contr.sum)) `

The p-values of both `a`

and the interaction between `a`

and `x`

will be the same as in your model, but you inherently will obtain different results for the intercept and `x`

.