[R] Parameter estimates from an ANCOVA

jgar jgaroftheeast at gmail.com
Wed Oct 15 22:35:03 CEST 2008


Hi all,

This is probably going to come off as unnecessary (and show my ignorance)
but I am trying to understand the parameter estimates I am getting from R
when doing an ANCOVA.  Basically, I am accustomed to the estimate for the
categorical variable being equivalent to the respective cell means minus the
grand mean.  I know is the case in JMP - all other estimates from these data
match the output from R, except I don't understand why the parameter
estimate for the categorical factor differs.

library(car)
options(contrasts=c("contr.Sum","contr.Poly"))

cont=as.numeric(rep(10:20, 2))  # fake data 
categ=as.factor(c(rep("A", 11), rep("B", 11)))
y=(c(cont[1:11]*4 , cont[1:11]*2))+rnorm(mean=0, sd=.05, 22)  

fit=lm(y~categ*cont)
scatterplot(y~cont|categ)   # shows interaction
scatterplot(y~categ|cont)   # shows effect of the categorical variable,
irrespective of cont

summary(fit); anova(fit)

coeff=coef(summary(fit))[,1]  # column of estimates to "coeff"

grandmean=coeff[1]+ mean(cont)*coeff[3]  #GM = intercept +
mean(cont)*regression_slope = 45.00677
slope_A=coeff[3]+coeff[4]  #slope of individual regression for A  = 3.998
slope_B=coeff[3]+(-coeff[4])  #slope of individual regression for B = 2.002

tapply(y, categ, mean) #these are what I want to get back out from the
parameter estimates
# in my world the parameter estimate should be cell mean(A) - grand mean =
60.02271 - 45.00677 = 15.01595
# the estimate is 0.99688227
#cell means   A        B 
#          60.0227  29.99082 

Any help is greatly appreciated. 

J
-- 
View this message in context: http://www.nabble.com/Parameter-estimates-from-an-ANCOVA-tp20001809p20001809.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list