[R] aov contrasts residual error calculation

Jacques Veslot jacques.veslot at good.ibl.fr
Fri Apr 21 17:57:52 CEST 2006


why not using lme() ?

first, you need transform data:
dat2 <- as.data.frame(lapply(subset(dat, sel=-c(A,B,C)), rep, 3))
dat2$y <- unlist(subset(dat, sel=c(A,B,C)), F, F)				
dat2$cond <- factor(rep(c("A","B","C"), each=nrow(dat)))

dat2$inter <- factor(dat2$map):factor(dat2$cond)

lme1 <- lme(fixed = y ~ mapping + cond + inter + other fixed effects,
	random = ~ 1 |subj, data=dat2,
	contrast=list(inter=poly(nlevels(dat2$inter)[,1:4]))							

				
	


Steven Lacey a écrit :
> Hi, 
>  
> I am using aov with an Error component to model some repeated measures data.
> By repeated measures I mean the data look something like this...
>  
> subj    A        B        C
> 1       4        11       15
> 2       3        12       17
> 3       5        9        14
> 4       6        10       18
>  
> For each subject I have 3 observations, one in each of three conditions (A,
> B, C). I want to test the following contrast (1, 0, -1). One solution is to
> apply the contrast weights at the subject level explicitly and then call
> t.test on the difference scores. However, I am looking for a more robust
> solution as I my actual design has more within-subjects factors and one or
> more between subjects factors.
>  
> A better solution is to specify the contrast in an argument to aov. The
> estimated difference of the contrast is the same as that in the paired
> t-test, but the residual df are double. While not what I expected, it
> follows from the documentation, which explicitly states that these contrasts
> are not to be used for any error term. Even though I specify 1 contrast,
> there are 2 df for a 3 level factor, and I suspect internally the error term
> is calculated by pooling across multiple contrasts. 
>  
> While very useful, I am wondering if there is way to get aov to calculate
> the residual error term only based on the specified contrasts (i.e., not
> assume homogeneity of variance and sphericity) for that strata?
>  
> If not, I could calculate them directly using model.matrix, but I've never
> done that. If that is the preferred solution, I'd also appreciate coding
> suggestions to do it efficiently. 
> 
> 
> How would I do the same thing with a two factor anova where one factor is
> within-subjects and one is between... 
>                                 Condition
> Mapping     Subject        A        B        C
> 1            1             4        11       15 
> 1            2
> 1            3
> 1            4
> 1            5
> 1            6
> 1            7
> 1            8
> 2            9
> 2            10
>  
> Mapping is a between-subject factor. Condition is a within-subject factor.
> There are 5 levels of mapping, 8 subjects nested in each level of mapping.
> For each of the 40 combinations of mapping and subject there are 3
> observations, one in each level of the condition factor. 
>  
> I want to estimate the pooled error associated with the following set of 4
> orthogonal contrasts:
>  
> condition.L:mapping.L
> condition.L:mapping.Q
> condition.L:mapping.C
> condition.L:mapping^4
>  
> What is the best way to do this? One way is to estimate the linear contrast
> for condition for each subject, create a 40 row matrix where the measure for
> each combination of mapping and subject is the linear contrast on condition.
> If I pass this dataframe to aov, the mse it returns is the value I am
> looking for. 
>  
> If possible, I would like to obtain the estimate without collapsing the
> dataframe, but am not sure how to proceed. Suggestions?
> 
> Thanks,
> Steve
> 
> ______________________________________________
> 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
> 


-- 
-------------------------------------------------------------------
Jacques.Veslot at good.ibl.fr
CNRS UMR 8090 - http://www-good.ibl.fr
Génomique et physiologie moléculaire des maladies métaboliques
I.B.L 2eme etage - 1 rue du Pr Calmette, B.P.245, 59019 Lille Cedex
Tel : 33 (0)3.20.87.10.44 Fax : 33 (0)3.20.87.10.31




More information about the R-help mailing list