Skip to content
Prev 2382 / 7419 Next

glm coefficients

In your example there is not categorical variables and you need at least one 
for ANCOVA.
Try the following, is the same dataset using factor() to create a 
categorical variable (named CatVar):

dat <- data.frame(response = rnorm(9), size = rnorm(9),  CatVar =
factor(c(1,1,1,1,0,0,0,0,0)))
model <- glm(response ~ size * CatVar, data = dat)
coef(model)

You will get:

(Intercept)         size      CatVar1 size:CatVar1
   0.2141371   -0.7847063   -1.8409264    3.3637699

The first coefficient (labeled "Intercept") is the intercept for CatVar = 0.
The second coefficient (labeled "size") is the slope for CatVar=0
The third coefficient (labeled "CatVar1") is the difference between the 
intercept for CatVar = 0 and the intercept for CatVar = 1
The fourth coefficient ("labeled size:CatVar") is the difference between the 
slope for CatVar = 0 and the slope for CatVar = 1

You can check it plotting this:

plot(dat$size,dat$response,col=dat$CatVar)
abline(a=coef(model)[1],b=coef(model)[2],col=1)
abline(a=sum(coef(model)[c(1,3)]),b=sum(coef(model)[c(2,4)]),col=2)

This way of presenting coefficients is the default in R (treatment contrast) 
but there are other alternatives, see ?contr.treatment.

Hope it helps,

Aitor


--------------------------------------------------
From: "Scott Chamberlain" <scttchamberlain4 at gmail.com>
Sent: Friday, September 23, 2011 5:59 PM
To: <R-sig-ecology at r-project.org>
Subject: [R-sig-eco] glm coefficients