[R-sig-eco] Orthogonal contrasts and ANCOVA in R

Martin Weiser weiser2 at natur.cuni.cz
Mon Apr 7 10:00:40 CEST 2014


Greg McClelland píše v Pá 04. 04. 2014 v 13:22 -0500:
> Hi everyone,
> 
> Using the following data, I need to determine if, independent of mass, 
> the observed response is associated with sex, location, and/or age
> 
> |example<-data.frame(response=c(2.401,2.588,2.293,2.880,2.655,2.830,3.165,2.665,3.126,2.973,1.725,1.889,2.631,1.750,2.271,2.347,2.173,1.962,1.599,2.297,1.894,2.030),mass=c(460,510,500,475,450,470,600,570,480,560,410,370,425,385,400,420,490,450,390,465,360,490),
> loc=c("K","K","K","K","K","K","K","K","K","K","R","R","R","R","R","R","R","R","R","R","R","R"),sex=c("F","M","M","F","M","F","M","M","F","M","F","F","M","F","F","F","M","F","F","M","F","F"),|
> |age 
> =c(48,49,47,45,49,49,50,48,49,48,47,48,47,50,48,50,48,50,48,50,50,50))|
> 
> This should be relatively simple but I've been hung up on it for a few 
> days now and could use a hand. If I understand it correctly, in order to 
> run an ANCOVA in R I need to set the contrasts from their default 
> (non-orthogonal) to orthogonal. 

> I'm struggling to find the best method 
> to do this. Admittedly, contrast matrices are a new challenge I have yet 
> to master which isn't helping. Any assistance would be greatly appreciated.
> 
> Once the orthogonal contrasts are set, I'm guessing everything else is 
> straightforward (with pkg 'car' installed):
> 
> model.1=aov(response~mass+loc+sex+age,data=example)
> Anova(model.1,type="III")
> Summary.lm(model.1)
> |
> Many thanks in advance,
> G

Hi Greg,

AFAIK you do not need to perform such an exercise.

On orthogonality: it is great if you have *data* collection design that
makes them orthogonal and balanced according to factors of your
interest. That means: same count of males and females, same count of
individuals per locality, all ages groups in all localities, and all
these combined. If data come from observation, this is improbable, but
closer to this the better.

By default, contrasts in factors (predictors) are set to "treatment" by
default in R - and these are orthogonal, too. Orthogonality in this
context (I guess/hope someone will correct me) means that R squeezes as
much variance per factor level as it could and puts these into
comparison. "Treatment contrasts" means: effects shown are differences
between particular level mean and mean of the subgroup that comes first
in the alphabet (i.e. locality "K", sex "F",...).  If this does not suit
you, You can change the reference group using "relevel()", specify
another way of comparing level means (you can compare them to overall
mean, mean of the preceding levels in sequence, ... - "sum" and
"helmert" contrast are built in) or by setting your own contrast matrix,
which comes handy if you wish e.g. to compare treatments pairwise.

In short:
run 
model.1=aov(response~mass+loc+sex+age,data=example)
or 
model.1=aov(response~mass*loc*sex*age,data=example) 
or something in between.
 
In M. Crawley's "R book", look at the Chapter 12: Analysis of covariance
and Sub-chapters of ch. 9: "Statisticall modelling" - 9.22 and 9.23 
(Here I reference second edition).

HTH.

Martin

> 
> 	[[alternative HTML version deleted]]
> 
> _______________________________________________
> R-sig-ecology mailing list
> R-sig-ecology at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-ecology




-- 

------------------------------
Pokud je tento e-mail součástí obchodního jednání, Přírodovědecká fakulta 
Univerzity Karlovy v Praze:
a) si vyhrazuje právo jednání kdykoliv ukončit a to i bez uvedení důvodu,
b) stanovuje, že smlouva musí mít písemnou formu,
c) vylučuje přijetí nabídky s dodatkem či odchylkou,
d) stanovuje, že smlouva je uzavřena teprve výslovným dosažením shody na 
všech náležitostech smlouvy.



More information about the R-sig-ecology mailing list