Reputation: 365
I have a set of data that looks like this:
rep stage line temp surv
1 L 149 18 0.6
2 L 149 18 0.7
3 L 149 18 0.25
1 A 149 18 1
2 A 149 18 1
3 A 149 18 1
1 L 149 25 0
2 L 149 25 0.2
3 L 149 25 0.3
1 A 149 25 1
2 A 149 25 1
3 A 149 25 1
1 L 208 18 0.6
2 L 208 18 0.4
3 L 208 18 0.55
1 A 208 18 1
2 A 208 18 1
3 A 208 18 1
1 L 208 25 0
2 L 208 25 0.05
3 L 208 25 0.05
1 A 208 25 1
2 A 208 25 0.857142857
3 A 208 25 0.7
Where rep is replicate, stage is the life stage of fruit fly I am working with (L = larvae, A = adult), line is a number assignment of the genetic line, temp is the rearing temperature, and surv is proportion that survived.
What I want to do, using the lme4 package in R, is fit a 3-way interaction model (linear mixed model) to run an ANOVA. My original model:
surv_3w.aov<-lmer(surv~stage*line*temp + (1|rep), data=dat_3w)
works but I want to treat line as a random effect. I think I am correctly treating rep as a grouping variable, (1|rep)
, but I am not sure.
I tried this model:
surv_3w.aov<-lmer(surv~stage*temp*(1|line) + (1|rep), data=dat_3w)
but then my 3-way interaction is gone.
Basically, I am asking help making a 3-way interaction model between line, stage, and temp where line is random and rep is a grouping variable
Upvotes: 0
Views: 1819
Reputation: 879
duplicate of a lot of similar questions, but this for example.
The code for the 3-way interaction model you're asking is:
surv_3w.aov<-lmer(surv~stage*line*temp + (1 + line |rep), data=dat_3w)
Whether this is really what you need, I don't know.
Upvotes: 2