# Intercept of random effect - library(sommer)

When I'm 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
```

What Can I do to overcome that?

### 1 Answer

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
```

storaged
posted this

## Have an answer?

JD