nested factor in repeated mesures ezANOVA

423 views
Skip to first unread message

erika.s...@gmail.com

unread,
Jan 22, 2015, 2:12:32 PM1/22/15
to ez...@googlegroups.com
Hello all, 

I am trying to run a repeated measures anova (my first!) and am not sure about the syntax to include a nested factor ...

I am looking at the growth of snails in response to 2 diet treatments (Treatment), where growth (Change) of each individual snails is measured at 4 times (Week). As well, the diet treatments are applied to containers that each contain 8 snails, so Container is nested within Treatment. (There are 15 containers in each treatment)

I think the aov model would be (?): 
aov(Change~Treatment/Container*Week + Error(Snail/(Container*Week))

but the data is unbalanced, so I need to use type 3 sums of squares. 

I have tried the ezANOVA formulation: 
ezANOVA(data=growrm, dv=.(Change), wid=.(Snail), within=.(Week,Container), between=.(Treatment), type=3)
which returns the error
Error in ezANOVA_main(data = data, dv = dv, wid = wid, within = within,  : 
  One or more cells is missing data. Try using ezDesign() to check your data.
ezPrecis does not list any missing data.
I believe the error may occur because container is nested within treatment, and therefore there are (many) treatment container combinations that do not exist?

How would I indicate that container is nested in treatment in my call to ezANOVA?

Please let me know if you need any more information, and thanks for your time!

Erika


Mike Lawrence

unread,
Jan 22, 2015, 3:07:36 PM1/22/15
to ez...@googlegroups.com
ezANOVA expects levels of the "wid" variable to be unique across between-manipulated variables. If you have the same label for two different individuals from two groups, then it throws that error. Try:

growrm$Snail = factor(paste(growrm$Treatment, growrm$Snail)

Then try your anova again:

ezANOVA(
    data=growrm
    , dv=.(Change)
    , wid=.(Snail)
    , within=.(Week,Container)
    , between=.(Treatment)
    , type=3
)


--
Mike Lawrence
Graduate Student
Department of Psychology & Neuroscience
Dalhousie University

~ Certainty is (possibly) folly ~

--
You received this message because you are subscribed to the Google Groups "ez4r" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ez4r+uns...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

erika.s...@gmail.com

unread,
Jan 22, 2015, 3:39:46 PM1/22/15
to ez...@googlegroups.com
Mike, thanks for the quick reply.

Each snail is identified by a unique number already. The numbers are only repeated across the different sampling weeks. 

I tried the code below just in case, but it didn't have any effect, it still throws the same error. 

Any other thoughts? 

I've attached my data as a .csv this time

Erika
Snail growth for rm.csv

Daniel Zingaro

unread,
Jan 22, 2015, 4:32:28 PM1/22/15
to ez...@googlegroups.com
Hi all,

Hopefully others who know more can pipe in. I played around a bit with
nlme and Anova because I couldn't get it to work with ez.

library(car)
library(nlme)

df <- read.csv('snail.csv')
names(df) <- tolower(names(df))

# my attempt to use nlme
# we want the fixed effect of week, treatment, and the interaction
# we have snails nested in containers
# (isn't treatment between-groups so no nesting?)
fit <- lme(change ~ week*treatment, random=~1 | container / snail,
data=df, method="ML")

I also wondered whether we could use Anova from the car package to get
type III (is this valid?):

fit2 <- Anova(lm(aov(change~treatment/container*week +
Error(snail/(container*week)), data=df)), type="III")

Dan
> <https://groups.google.com/d/optout>.
>
>
> --
> You received this message because you are subscribed to the Google
> Groups "ez4r" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to ez4r+uns...@googlegroups.com
> <mailto:ez4r+uns...@googlegroups.com>.

erika.s...@gmail.com

unread,
Jan 22, 2015, 5:32:59 PM1/22/15
to ez...@googlegroups.com
Thanks for the suggestions Dan.

Using Anova from car doesn't seem to work in this way, 
ie. Anova(lm(aov(change~treatment/container*week + Error(snail/(container*week)), data=df)), type="III").
In fact, that was the first thing I tried (it crashed R on my computer). Reading online, there does seem to be a way to implement repeated measures in car::Anova, but I was confused about the syntax and data set up, hence the move to ezANOVA.

I haven't used lme much, as I much prefer anovas were I can check the dfs and MS ratios against what I'm expecting to insure I've formulated the model properly.

That said, 
 fit<-lme(change ~ week*treatment, random=~1 | container / snail, data=df, method="ML") 
seems to give correct/reasonable degrees of freedom for treatment and week when I do anova(fit)
Is anova(fit) legitimate if the data is unbalanced?

Robert Day

unread,
Nov 19, 2016, 9:59:16 AM11/19/16
to ez4r
Erika,
I may be missing something here, but it seems to me that your diets are applied to containers, not individual snails, so that your error variation should involve the variation between containers, and not variation between snails. In the Ez setup, it would be simpler to calculate mean growth for the snails in each container, and then run the ANOVA.
Rob Day
Reply all
Reply to author
Forward
0 new messages