# Why random effect has variance when covariate added but not when estimating the intercept alone in GLMM

Hi I am trying to determine whether I need a random effect in my model. I originally thought a random effect was necessary due to the output of my full model:

full.model<-lmer(y~x+(1|Plot),data=data)


For the summary I get:

    Random effects:
Groups   Name        Variance Std.Dev.
Plot     (Intercept) 10.55    3.248
Residual             20.87    4.568
Number of obs: 31, groups:  Plot, 16


However, when I fit a model with just the intercept term:

null.model<-lmer(y~1+(1|Plot),data=data)


For the summary I get:

Random effects:
Groups   Name        Variance Std.Dev.
Plot     (Intercept)  0.00    0.000
Residual             34.12    5.841
Number of obs: 31, groups:  Plot, 16


Based on the zero variance here, I interpret this as the random effect is not needed (all the variance between plots can be explained by the residual term). Is this interpretation correct? If so, why when a covariate is added (as seen above) does the random effect term gain variation?

I also tried incorporating the random effect on the slope and not intercept of the model:

full.model.slope<-lmer(y~x+(0+x|Plot),data=data)


But for the summary, the random effect variance went back to zero

Random effects:

Groups   Name     Variance Std.Dev.
Plot     x         0.00    0.000
Residual          30.89    5.558
Number of obs: 31, groups:  Plot, 16


Why is the variance of the random effect changing based on the covariates here? Any insight would be appreciated. Thanks!

• I assume the effect of x is significant. You then can't test the random intercept without this covariate. You could compare your first model with a model including the fixed effect only (using AIC or a likelihood-ratio test).. – Roland Apr 17 '18 at 6:50
• @Roland thanks for your response. So essentially you cannot test the need for the random factor unless all significant predictors are included in the model? – broch789 Apr 18 '18 at 16:16