[R] effects in ANCOVA
Chuck Cleland
ccleland at optonline.net
Fri Nov 17 19:27:07 CET 2006
Tomas Goicoa wrote:
> Dear R users,
>
> I am trying to fit the following ANCOVA model in R2.4.0
>
> Y_ij=mu+alpha_i+beta*(X_ij-X..)+epsilon_ij
>
> Particularly I am interested in obtaining estimates for mu, and the effects
> alpha_i
>
>
> I have this data (from the book Applied Linear Statistical Models by Neter
> et al (1996), page 1020)
>
>
> y<-c(38,43,24,39,38,32,36,38,31,45,27,21,33,34,28)
> x<-c(21,34,23,26,26,29,22,29,30,28,18,16,19,25,29)
> xmean<-x-mean(x)
> grupo<-factor(rep(c(1,2,3),5))
> datos<-data.frame(y,xmean,grupo)
>
> and I have done the following
>
> modelo<-lm(y~xmean+grupo,data=datos)
>
> summary(modelo)
>
> Call:
> lm(formula = y ~ xmean + grupo, data = datos)
>
> Residuals:
> Min 1Q Median 3Q Max
> -2.4348 -1.2739 -0.3363 1.6710 2.4869
>
> Coefficients:
> Estimate Std. Error t value Pr(>|t|)
> (Intercept) 39.8174 0.8576 46.432 5.66e-14 ***
> xmean 0.8986 0.1026 8.759 2.73e-06 ***
> grupo2 -5.0754 1.2290 -4.130 0.00167 **
> grupo3 -12.9768 1.2056 -10.764 3.53e-07 ***
> ---
> Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
>
> Residual standard error: 1.873 on 11 degrees of freedom
> Multiple R-Squared: 0.9403, Adjusted R-squared: 0.9241
> F-statistic: 57.78 on 3 and 11 DF, p-value: 5.082e-07
>
>
> In the book, the estimates are
>
> From this book,
>
> mu=33.8
> alpha_1=6.017
> alpha_2=0.942
> beta=0.899
>
> Is it possible to obtain this estimates and their standard errors from the
> model I fitted?
Yes, just change the default contrast for the grupo factor:
y<-c(38,43,24,39,38,32,36,38,31,45,27,21,33,34,28)
x<-c(21,34,23,26,26,29,22,29,30,28,18,16,19,25,29)
xmean<-x-mean(x)
grupo<-factor(rep(c(1,2,3),5))
datos<-data.frame(y,xmean,grupo)
contrasts(datos$grupo) <- contr.sum(3)
modelo<-lm(y~xmean+grupo,data=datos)
summary(modelo)
Call:
lm(formula = y ~ xmean + grupo, data = datos)
Residuals:
Min 1Q Median 3Q Max
-2.4348 -1.2739 -0.3363 1.6710 2.4869
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 33.8000 0.4835 69.908 6.37e-16 ***
xmean 0.8986 0.1026 8.759 2.73e-06 ***
grupo1 6.0174 0.7083 8.496 3.67e-06 ***
grupo2 0.9420 0.6987 1.348 0.205
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 1.873 on 11 degrees of freedom
Multiple R-Squared: 0.9403, Adjusted R-squared: 0.9241
F-statistic: 57.78 on 3 and 11 DF, p-value: 5.082e-07
> Thanks in advance
>
> Tomas Goicoa
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at stat.math.ethz.ch 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.
>
--
Chuck Cleland, Ph.D.
NDRI, Inc.
71 West 23rd Street, 8th floor
New York, NY 10010
tel: (212) 845-4495 (Tu, Th)
tel: (732) 512-0171 (M, W, F)
fax: (917) 438-0894
More information about the R-help
mailing list