# [R] Mixed ANCOVA with between-Ss covariate?

Mark Difford mark_difford at yahoo.co.uk
Thu Feb 12 14:24:55 CET 2009

```Hi Mike,

>> I'm surprised there were no takers on this query; I thought it would
>> be an easy answer, particularly where I provided example data set and
>> code.

covariate_aov = aov(dv~(covariate+group+iv1+iv2)^2,data=a)

You can find out more about how to specify models in Chap. 11 of the manual
"An Introduction to R."

>> Did my request run afoul of the list etiquette?

I don't believe so. You can never be sure that someone who knew the answer

Regards, Mark.

Mike Lawrence-7 wrote:
>
> Hi all,
>
> I have data from an experiment with 3 independent variables, 2 are
> within and 1 is between. In addition to the dependent variable, I have
> a covariate that is a single measure per subject. Below I provide an
> example generated data set and my approach to implementing the ANCOVA.
> However the output confuses me; why does the covariate only appear in
> the first strata? Presumably it should appear in every strata in which
> there can be between-Ss effects or interactions with between-Ss
> effects, no?
>
> #generate data
> set.seed(1)
> a=rbind(
> 	expand.grid(
> 		id=1:20
> 		,iv1 = 1:2
> 		,iv2 = 1:2
> 	)
> )
> a\$group = factor(a\$id<11)
> a\$dv = rnorm(length(a[,1]))
> a\$covariate = NA
> for(i in unique(a\$id)){
> 	a\$covariate[a\$id==i]= rnorm(1)
> }
>
> #make sure id, iv1, and iv2 are factorized
> a\$id=factor(a\$id)
> a\$iv1=factor(a\$iv1)
> a\$iv2=factor(a\$iv2)
>
> #run ANCOVA
> covariate_aov = aov(dv~covariate+group*iv1*iv2+Error(id/(iv1*iv2)),data=a)
> summary(covariate_aov)
>
>
> --
> Mike Lawrence
> Department of Psychology
> Dalhousie University
> www.thatmike.com
>
> Looking to arrange a meeting? Check my public calendar:
> http://www.thatmike.com/mikes-public-calendar
>
> ~ Certainty is folly... I think. ~
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>

--
View this message in context: http://www.nabble.com/Mixed-ANCOVA-with-between-Ss-covariate--tp21942605p21976002.html
Sent from the R help mailing list archive at Nabble.com.

```