[R] Doing a mixed-ANOVA after accounting for a covariate

David Winsemius dwinsemius at comcast.net
Sun Dec 26 17:08:51 CET 2010


On Dec 26, 2010, at 9:55 AM, Dror D Lev wrote:

> Thank you David, for the reference to Dalgaard's paper in  
> Rnews_2007-2.
>
> Unfortunately I don't seem to have the mathematical-statistical  
> sophistication required to adapt the example in Dalgaard's paper for  
> my case.
>
> I hope someone can suggest a less-mathematical direction for solution.

Here's what I would suggest if you want to stay more concrete. If you  
are not prepared to offer a minimal subset of your own data and also  
provide working or non-working code that uses it, then pick an  
available dataset that resembles it in structure and autocorrelation.  
One possibility would be the BodyWeight dataset in either the nlme or  
the MEMSS packages (although see below for my current level of  
uncertainty regarding your data).

require(nlme)
plot(BodyWeight)

>
> Thanks again,
> dror
>
> ----------------------------
>
> On Sun, Dec 26, 2010 at 3:59 PM, David Winsemius <dwinsemius at comcast.net 
> > wrote:
>
> On Dec 26, 2010, at 7:42 AM, Dror D Lev wrote:
>
> Dear r helpers,
>
> I would like to look at the interaction between two two-level  
> factors, one
> between and one within participants, after accounting for any  
> variance due
> to practice (31 trials in each of two blocks) in the task.
> It seems to require treating practice as a covariate.

I had trouble figuring out exactly what you meant by 31 trials in two  
blocks. Was that 31 trials by each participant? Or was it two trials  
by each of 31 participants divided unequally into two groups?

-- 
David.

>
> All the examples I noticed for handling covariates (i.e. ANCOVA,  
> including
> the ones in Faraway's "Practical regression and anova using r") use  
> lm(),
> but this doesn't handle repeated-measures.
>
> See if Dalgaard's piece in R-News offers better guidance:
>
> http://www.r-project.org/doc/Rnews/Rnews_2007-2.pdf
>
>
>
>
> I thought of a solution in the form of first running a regression on  
> the
> covariate:
> cov.accnt = lm (myMeasure ~ myCovMeasure, data=dat)
>
> and then run the aov() on the residuals:
> m.aov = aov (cov.accnt$residuals ~ withinVar*betweenVar +
> Error(subj/withinVar, data=dat)
>
> Does it seem to be a valid answer to my problem?
>
> Is there an existing function that can do this (perhaps more  
> appropriately)?
>
> Thank you for any help,
> dror
> -- 
>
> David Winsemius, MD
> West Hartford, CT
>
>

David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list