Cross Validated is a question and answer site for people interested in statistics, machine learning, data analysis, data mining, and data visualization. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

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)
share|improve this question

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.

share|improve this answer
thanks for the helpful answer! Does this also apply to the lme() function? – jokel Nov 4 '12 at 0:00
@jokel Yes, this does also apply to the lme function. – Sven Hohenstein Nov 4 '12 at 6:46

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.