Jalles10
Jalles10

Reputation: 429

Intercept of random effect - library(sommer)

When I run this mixed model, I get all of the statistics I need.

library(sommer)
data(example)
#Model without intercept - OK
ans1 <- mmer2(Yield~Env,
              random= ~ Name + Env:Name,
              rcov= ~ units,
              data=example, silent = TRUE)
summary(ans1)
ans1$u.hat #Random effects

However if I try to get the intercept to random effects, like in the R library lme4, I get a error like:

Error in dimnames(x) <- dn : 
  length of 'dimnames' [2] not equal to array extent


#Model with intercept
ans2 <- mmer2(Yield~Env,
              random= ~ 1+Name + Env:Name,
              rcov= ~ units,
              data=example, silent = TRUE)
summary(ans2)
ans2$u.hat #Random effects

How can I overcome that?

Upvotes: 0

Views: 229

Answers (2)

Covaruber
Covaruber

Reputation: 376

Your model:

ans1 <- mmer2(Yield~Env,
              random= ~ Name + Env:Name,
              rcov= ~ units,
              data=example, silent = TRUE)

is equivalent to:

ans1.lmer <- lmer(Yield~Env + (1|Name) + (1|Env:Name),
              data=example)

using lme4. Please notice that lme4 uses the notation (x|y) to specify if there is for example different intercepts (x term) for each level of the second term (y term) which is a random regression model. If you specify:

ans2.lmer <- lmer(Yield~Env + (Env|Name),
              data=example)

you get three variance components, one for each of the 3 levels in the Env term. The equivalent in sommer is not a random regression but a heterogeneous variance model using the diag() functionality:

ans2 <- mmer2(Yield~Env,
              random= ~ diag(Env):Name,
              rcov= ~ units,
              data=example, silent = TRUE)

## or in sommer >=3.7

ans2 <- mmer(Yield~Env,
              random= ~ vs(ds(Env),Name),
              rcov= ~ units,
              data=example, silent = TRUE)

The first 2 models above are equivalent because both models assume there's no different intercepts, whereas the last two models tackle the same problem but with two different approaches that are not exactly the same; random regression versus heterogeneous variance model.

In short, sommer doesn't have random regression implemented yet so you cannot use random intercepts in sommer like you do in lme4, but instead use a heterogeneous variance models.

Cheers,

Upvotes: 2

storaged
storaged

Reputation: 1847

I know it is not an elegant solution, but how about adding intercept to the data, so you can easily use it in the model?

What I mean is:

example <- cbind(example, inter=1)
ans2 <- mmer2(Yield~Env,
          random= ~ Name + Env:Name + inter, #here inter are 1's
          rcov= ~ units,
          data=example, silent = TRUE)
summary(ans2)
ans2$u.hat

Upvotes: 0

Related Questions