# Understanding the random effect in linear mixed models (lme4, R) [duplicate]

I am familiar with linear regression models but the random section of linear mixed models just melts my mind. I did find an excellent guide that could have helped me but the languageR package is not compatible with newer versions of lme4 so I've been unable to implement it in my work.

For me the fixed effects are very understandable (below lactation and a higher yr2 value both contribute to a higher weight but the lactation effect is more consistent which results in a higher t-value).

The first problem is to understand what I am actually putting in. To a certain extent I understand that (1|P$grupp) means that the mixed model add to the base line (intercept) while (P$grupp|P$lweek) mean that belong to a group is expected to affect the average weight increase (or decrease) while P$lweek adds to the baseline value. But why does all tutorials seem to favor write ups like (1+P$fgrupp|P$lweek) rather than (P$grupp|P$lweek)?

Now on to the actual output (see below for full output). I've used the following models (sorry for the Swenglish but the sample is the weight of cows P$vikt is the weight at certain time points and P$lweek is the time since a calf was born, P$fgrupp is a factor telling if the cow belongs to feed group 1,2 or 3): Formula: P$vikt ~ P$lweek + P$laktation + P$yr + (1 | P$fgrupp)            #$Formula: P$vikt ~ P$lweek + P$laktation + P$yr + (1 + P$fgrupp | P$lweek)  Where I understand it as the first one being rather useless (essentially it tells us that the average weight of the cows isn't affected of which feed group it belongs too). This is reflected by fgrupp having variance 0 in the first formula below. The second is more interesting as the P$fgrupp|P$lweek as I understand it should show if different feed groups affect the weight increase of cows as function of the time. But I am really not competent enough to understand the input. I understand that variance somehow mean that belonging to group2 or 3 explain some of the variation in the growth curves but I really don't understand how to interpret this. Random effects: Groups Name Variance Std.Dev. Corr P$lweek  (Intercept)   13.068  3.6149                                     #$P$fgrupp2     77.230  8.7881  1.000                              #$P$fgrupp3     81.188  9.0104  1.000 1.000                        #$Residual 4031.831 63.4967 Number of obs: 1048, groups: P$lweek, 84


Full output

#First model#
Linear mixed model fit by REML
Formula: P$vikt ~ P$lweek + P$laktation + P$yr + (1 | P$fgrupp) #$
AIC   BIC logLik deviance REMLdev
11703 11732  -5845    11698   11691
Random effects:
Groups   Name        Variance Std.Dev.
P$fgrupp (Intercept) 0.0 0.000 #$
Residual             4139.9   64.342
Number of obs: 1048, groups: P$fgrupp, 3 #$

Fixed effects:
Estimate Std. Error t value
(Intercept)  509.593      4.683  108.82
P$lweek 1.028 0.105 9.79 #$
P$laktation 22.789 1.454 15.67 #$
P$yr2 35.294 4.093 8.62 #$

Correlation of Fixed Effects:
(Intr) P$lwek P$lktt                                           #$P$lweek     -0.560                                                         #$P$laktation -0.636  0.030                                                  #$P$yr2       -0.240 -0.034 -0.141                                           #$#Second model# Linear mixed model fit by REML Formula: P$vikt ~ P$lweek + P$laktation + P$yr + (1 + P$fgrupp | P$lweek) #$
AIC   BIC logLik deviance REMLdev
11707 11761  -5842    11693   11685
Random effects:
Groups   Name        Variance Std.Dev. Corr
P$lweek (Intercept) 13.068 3.6149 #$
P$fgrupp2 77.230 8.7881 1.000 #$
P$fgrupp3 81.188 9.0104 1.000 1.000 #$
Residual             4031.831 63.4967
Number of obs: 1048, groups: P$lweek, 84 #$

Fixed effects:
Estimate Std. Error t value
(Intercept) 508.2291     5.1770   98.17
P$lweek 1.0662 0.1192 8.94 #$
P$laktation 22.6525 1.4459 15.67 #$
P$yr2 35.6343 4.0848 8.72 #$

Correlation of Fixed Effects:
(Intr) P$lwek P$lktt                                           #
P$lweek -0.627 #$
P$laktation -0.570 0.025 #$
P$yr2 -0.224 -0.018 -0.136 #$


## marked as duplicate by gung♦ r StackExchange.ready(function() { if (StackExchange.options.isMobile) return; $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() { var$hover = $(this).addClass('hover-bound'),$msg = $hover.siblings('.dupe-hammer-message');$hover.hover( function() { $hover.showInfoMessage('', { messageElement:$msg.clone().show(), transient: false, position: { my: 'bottom left', at: 'top center', offsetTop: -7 }, dismissable: false, relativeToBody: true }); }, function() { StackExchange.helpers.removeMessages(); } ); }); }); Sep 20 '16 at 16:21

• In the first model you fit a random intercept with fgrupp as a grouping factor. In the second model you fit a random intercept and a random slope for fgrupp with lweek as a grouping factor. You probably want (1 + P$lweek | P$fgrupp). – Roland Oct 18 '12 at 13:28