[R] ANCOVA
John Fox
jfox at mcmaster.ca
Sun Aug 29 01:44:38 CEST 2004
Dear Matt,
The sequential sums of squares produced by anova() test for g ignoring x
(and the interaction), x after g (and ignoring the interaction), and the x:g
interaction after g and x. The second and third test are generally sensible,
but the first doesn't adjust for x, which is probably not what you want in
general (although you've constructed x to be independent of g, which is
typically not the case). Note that you would not usually want to test for
equal intercepts in the model that doesn't constrain the slopes to be equal
(though you haven't done this): Among other things, 0 is outside the range
of x.
The Anova() function in the car package will produce so-called type-II
tests.
I hope that this helps.
John
> -----Original Message-----
> From: r-help-bounces at stat.math.ethz.ch
> [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Matt Oliver
> Sent: Friday, August 27, 2004 4:10 PM
> To: R-help at stat.math.ethz.ch
> Subject: [R] ANCOVA
>
> Dear R-help list,
>
> I am attempting to understand the proper formulation of
> ANCOVA's in R. I would like to test both parallelism and
> intercept equality for some data sets, so I have generated an
> artificial data set to ease my understanding.
>
> This is what I have done
>
> #Limits of random error added to vectors min <- -0.1 max <- 0.1
>
> x <- c(c(1:10), c(1:10))+runif(20, min, max)
> x1 <- c(c(1:10), c(1:10))+runif(20, min, max) y <- c(c(1:10),
> c(10:1))+runif(20, min, max) z <- c(c(1:10),
> c(11:20))+runif(20, min, max) g <- as.factor(c(rep(1, 10),
> rep(2, 10)))
>
> #x and x1 have similar slopes and have the similar
> intercepts, #x and y have different slopes and different
> intercepts #x and z have similar slopes with different intercepts
>
> #These are my full effects models
>
> fitx1x <- lm(x1~g+x+x:g)
> fityx <- lm(y~g+x+x:g)
> fitzx <- lm(z~g+x+x:g)
>
>
> anova(fitx1x)
>
> Analysis of Variance Table
>
> Response: x1
> Df Sum Sq Mean Sq F
> value Pr(>F)
> g 1 0.002 0.002 0.3348
> 0.5709
> x 1 163.927 163.927 23456.8319
> <2e-16 ***
> g:x 1 0.002 0.002 0.2671
> 0.6123
> Residuals 16 0.112 0.007
> ---
> Signif. codes: 0 `***' 0.001 `**' 0.01 `*' 0.05 `.' 0.1 ` ' 1
>
> These results confirm that x and x1 do not have significantly
> different means with respect to g; There is a significant
> linear relationship between x and x1 independent of g There
> is no evidence that the slopes of x and x1 in the two g
> groups is different
>
> anova(fityx)
>
> Analysis of Variance Table
>
> Response: y
> Df Sum Sq Mean Sq F
> value Pr(>F)
> g 1 0.012 0.012
> 1.7344
> 0.2064
> x 1 0.003 0.003
> 0.4399
> 0.5166
> g:x 1 164.947 164.947
> 24274.4246 <2e-16 ***
> Residuals 16 0.109 0.007
> ---
> Signif. codes: 0 `***' 0.001 `**' 0.01 `*' 0.05 `.' 0.1 ` ' 1
>
> These results confirm that x and y do not have significantly
> different means with respect to g; There is a not a
> significant linear relationship between x and y independent
> of g There is evidence that the slopes of x and y in the two
> g groups is significantly different.
>
>
> anova(fitzx)
>
> Analysis of Variance Table
>
> Response: z
> Df Sum Sq Mean Sq F
> value Pr(>F)
> g 1 501.07 501.07
> 52709.9073 <2e-16 ***
> x 1 165.39 165.39
> 17398.4057 <2e-16 ***
> g:x 1 0.02 0.02 1.7472
> 0.2048
> Residuals 16 0.15 0.01
> ---
> Signif. codes: 0 `***' 0.001 `**' 0.01 `*' 0.05 `.' 0.1 ` ' 1
>
> These results confirm that x and z have significantly
> different means with respect to g; There is a a significant
> linear relationship between x and z independent of g There is
> no evidence that the slopes of x and z in the two g groups is
> significantly different.
>
>
> What I don't understand is how to formulate the model so that
> I can tell if the intercepts between the g groups are different.
> Also, how would I formulate an ANCOVA if I am dealing with
> Model II regressions?
>
>
> Any help would be greatly appreciated.
>
> Matt
>
>
>
> ==============================
> When you reach an equilibrium in biology, you're dead. - A.
> Mandell ============================== Matthew J. Oliver
> Institute of Marine and Coastal Sciences
> 71 Dudley Road, New Brunswick
> New Jersey, 08901
> http://marine.rutgers.edu/cool/
>
> ______________________________________________
> 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
More information about the R-help
mailing list