Error mixed model lme4

What is wrong in the following model:

 # simulated data yr = 2; vg = 4, fm = 5, gen = 5
    mbb <- data.frame( trait1 = rnorm(200, 15, 4),yr = c(rep (1:2, each = 100)), 
   vg = c(rep(rep(1:4, each =25), 2)), fm = rep(rep(1:5, each = 5), 8), 
    gen = sample(c(1:5), 200, replace = T))
    require(lme4) 
    lmer(trait1 ~ (yr + vg + gen)^3 + (yr + vg + gen|fm:vg), data= mbb)# full model 

I get the following error:

Error in validObject(.Object) : 
  invalid class "mer" object: Slot Zt must by dims['q']  by dims['n']*dims['s']
In addition: Warning messages:
1: In fm:vg : numerical expression has 200 elements: only the first used
2: In fm:vg : numerical expression has 200 elements: only the first used
+5
source share
2 answers

The problem is that fm, and vgare stored as numerical and not as factors, so lmertry to interpret fm:vgthe operator sequence (see. ?seq), Rather than the interaction operator (see. ?interaction). You can:

  • fm vg (mbb <- transform(mbb,vg=factor(vg),fm=factor(fm))) [ , , vg fm ... , ... , , ...]
  • interaction(fm,vg)
  • ((yr+vg+gen|factor(fm):factor(vg)))
  • .

    , , , .

+7

mbb.

mbb$fmvg <- with(mbb, interaction(fm,vg, sep=":"))

lmer(trait1 ~ (yr + vg + gen)^3 + (yr + vg + gen|fmvg), data= mbb)
+3

All Articles