Solved – What’s the interpretation of ranef, fixef, and coef in mixed effects model using lmer

mixed modelr

I have two observations from a person each, where every observation corresponds to a different treatment. The treatments are fixed effects, the persons are random effects. I use the command:

model <- lmer(response ~ treatment + (1|Person))

When I run summary() on this model, I get variances for the residual and the random person effect. I also get the mean values corresponding to what treatment was given. I understand this.

But what's the output from ranef? fixef? coef? I don't understand what these things do. I also know nothing about mixed models other than the very basic definition, so I would like a non-technical explanation as opposed to one that says "oh ranef just gives you the insert technical term here ").

EDIT:

Playing around with things, it seems that the output of 'coef' are sums of the fixef and ranef outputs. The fixed outputs seem to have an obvious explanation, so I guess my question reduces to an inquiry on 'ranef' and 'fitted'. What do these do?

I believe it is especially 'ranef' that I don't undertand. How are these random effects (that's what ranef stands for, no?) when the only estimates we have to work with are parameter estimates for the mean values and a variance estimate for the random effect and a variance estimate for the residual "noise"?

Best Answer

  • fixef() is relatively easy: it is a convenience wrapper that gives you the fixed-effect parameters, i.e. the same values that show up in summary(). Unless you are specifying your model in a very particular way, these are not the "mean values corresponding to what treatment was given" as suggested in your question; rather they are contrasts among treatments. Using R's default setup, the first parameter ("Intercept") is the mean response for the first treatment level, while the remaining parameters are the difference between the mean responses for levels 2 and higher and the mean response for level 1. (From Jake Westfall in comments: "Another way of explaining fixef() is that it returns essentially the same thing as when you call coef() on an lm regression object -- that is, it returns the (mean) regression coefficients.")

  • ranef() gives the conditional modes, that is the difference between the (population-level) average predicted response for a given set of fixed-effect values (treatment) and the response predicted for a particular individual. You can think of these as individual-level effects, i.e. how much does any individual differ from the population? They are also, roughly, equivalent to the modes of the Bayesian posterior densities for the deviations of the individual group effects from the population means (but note that in most other ways lme4 is not giving Bayesian estimates).

    It's not that easy to give a non-technical summary of where the conditional modes come from; technically, they are the solutions to a penalized weighted least-squares estimation procedure. Another way of thinking of them is as shrinkage estimates; they are a compromise between the observed value for a particular group (which is what we would estimate if the among-group variance were infinite, i.e. we treated groups as fixed effects) and the population-level average (which is what we would estimate if the among-group variance were 0, i.e. we pooled all groups), weighted by the relative proportions of variance that are within vs among individuals. For further information, you can search for a non-technical explanation of best linear unbiased predictions (or "BLUPs"), which are equivalent to the conditional modes in this (simple linear mixed model) case ...

  • coef() gives the predicted effects for each individual; in the simple example you give, coef() is basically just the value of fixef() applicable to each individual plus the value of ranef().

I agree with comments that it would be wise to look for some more background material on mixed models:

  • Gelman and Hill's Applied Regression Modeling
  • Pinheiro and Bates Mixed-Effects Models in S and S-PLUS
  • various books by Zuur et al.
  • McElreath's Rethinking Statistics
  • (shameless plug) chapter 13 in Fox et al. Ecological Statistics