[R] Intercept in lm and in library(car): Anova

John Fox jfox at mcmaster.ca
Fri Sep 14 20:29:20 CEST 2007


Dear Stefan,

> -----Original Message-----
> From: r-help-bounces at r-project.org 
> [mailto:r-help-bounces at r-project.org] On Behalf Of Stefan Th. Gries
> Sent: Friday, September 14, 2007 2:09 PM
> To: R-help at stat.math.ethz.ch
> Subject: [R] Intercept in lm and in library(car): Anova
> 
> Hi
> 
> I have two questions regarding the meaning of intercept outputs of lm.
> 
> Question 1: In data set 1 (a fully-balanced design), the line with
> (Intercept) contains the overall mean, and the estimates 
> contain the differences from the overall mean (matching those 
> from model.tables).
> But in data set 2, the line with the intercept does not 
> correspond to the overall mean and the estimates don't 
> correspond to the differences outputted by model.tables. What 
> does the output contain here?

In both datasets, the intercept is the "grand mean", which in a two-way
ANOVA (parametrized with sum-to-zero contrasts) is the mean of the cell
means. In the first case, because the data are balanced, the mean of the
cell means corresponds to the mean of Y1. In the second case, where there
are unequal cell counts, the mean of the cell means is different from the
mean of Y2 (but equal to the estimated intercept):

> mean(tapply(Y2, list(M2, N2), mean))
[1] 45.02083

The line in the output from Anova() in the package for the intercept tests
the null hypothesis that the intercept parameter is different from 0, which
rarely would be of interest.

I hope this helps,
 John

> 
> #####
> rm(list=ls(all=TRUE))
> options(contrasts=c("contr.sum", "contr.poly"))
> 
> # data set 1
> Y1<-c(43, 23, 88, 45, 2, 68, 39, 41, 55, 64, 91, 9, 90, 37, 
> 88, 41) M1<-factor(c("k", "g", "k", "g", "k", "k", "g", "g", 
> "g", "g", "k", "k", "g", "g", "k", "k")) N1<-factor(c("k", 
> "g", "g", "k", "k", "g", "k", "g", "k", "g", "g", "k", "g", 
> "k", "g", "k"))
> 
> # linear model 1
> model1<-lm(Y1~M1*N1); summary(model1)
> model.tables(aov(Y1~M1*N1), "means")
> model.tables(aov(Y1~M1*N1))
> 
> # data set 2
> Y2<-c(34, 16, 46, 5, 2, 78, 31, 39, 25, 64, 45, 92, 65, 91, 
> 60, 12, 33, 40, 72, 61, 49, 59) M2<-factor(c(rep("a", 10), 
> rep("b", 12))) N2<-factor(c(rep("d", 4), rep("e", 6), 
> rep("d", 8), rep("e", 4)))
> 
> # linear model 2
> model2<-lm(Y2~M2*N2); summary(model2)
> model.tables(aov(Y2~M2*N2), "means")
> model.tables(aov(Y2~M2*N2))
> #####
> 
> 
> Question 2: what does the line with (Intercept) mean that the 
> following lines produce?
> 
> #####
> library(car)
> Anova(model, type=c("III"))
> #####
> 
> Any help would be much appreciated. Thx, STG
> 
> ______________________________________________
> R-help at 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.
>



More information about the R-help mailing list