0

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

Melderon
  • 365
  • 1
  • 16

1 Answers1

2

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.

Erdne Htábrob
  • 819
  • 11
  • 29
  • Thanks for the response. So far, it is still running. Is This a bit more computationally taxing than the original model I made? – Melderon Apr 20 '17 at 20:54
  • This is the warning I get after killing the operation: Warning messages: 1: In commonArgs(par, fn, control, environment()) : maxfun < 10 * length(par)^2 is not recommended. 2: In optwrap(optimizer, devfun, getStart(start, rho$lower, rho$pp), : convergence code 1 from bobyqa: bobyqa -- maximum number of function evaluations exceeded – Melderon Apr 20 '17 at 21:06
  • did you check this thread on the error? https://stats.stackexchange.com/questions/97929/lmer-model-fails-to-converge Of course it is computationally more intense, you're estimating the variance of the slope of `line` based on each group defined by `rep` – Erdne Htábrob Apr 20 '17 at 22:18
  • Got these when I let it run for 16 hours! 3: In commonArgs(par, fn, control, environment()) : maxfun < 10 * length(par)^2 is not recommended. 4: In optwrap(optimizer, devfun, opt$par, lower = rho$lower, control = control, : convergence code 1 from bobyqa: bobyqa -- maximum number of function evaluations exceeded 5: In checkConv(attr(opt, "derivs"), opt$par, ctrl = control$checkConv, : unable to evaluate scaled gradient 6: In checkConv(attr(opt, "derivs"), opt$par, ctrl = control$checkConv, : Model failed to converge: degenerate Hessian with 10 negative eigenvalues – Melderon Apr 21 '17 at 13:21
  • I checked your resource but I don not understand it at all – Melderon Apr 21 '17 at 13:22