# calculating adjusted means from lmer

How can I calculate adjusted means for a regression model with fixed and random effects? I'd like to calculate the adjusted means for a lme regression with this formula

mymodel <- myDV ~ experiment_condition + (1|subject_aptitude) + (1|subjects_teacher/subjects_class)


where myDV is the dependent variable, experiment_condition is an independent fixed effect and subject_aptitude (participants past class average) and subjects_teacher/subjects_class (classroom nested within teacher) are random effects

The ultimate goal here is to visualize this data with adjusted means because the raw means (before the random effects variance is removed) do not accurately depict the results of the LMER

• Have you had a look at the lmerTest Package? It has a lsmeans function. May 20, 2015 at 6:26
• @Daniel, appreciate the pointer. I'd been reading about lsmeans but needed that extra confirmation that it was a good way to go. thanks again May 20, 2015 at 15:26
• Asking for R code is off-topic here. But you could ask how this is done (ie conceptually &/or mathematically) w/o regard for the R code. The answer may be sufficiently obvious you wouldn't need help w/ the code; alternatively, code might come along w/ an answer anyway. May 20, 2015 at 17:30
• @gung, interesting. I've read that this is a bit of a contentious issue but understand why you would say so. In this case I felt that I was well within the grey area May 20, 2015 at 23:34
• It is a long-running & contentious issue, & I do think your particular Q does fall into a gray area. That is why I thought it would be OK w/ a slight shift in emphasis. On a different note, thanks for the respect, but you shouldn't take my rep seriously. May 21, 2015 at 0:40

Per Daniel's suggestion in the comments, I wanted to close the loop about the solution. This code did the trick

require(lmerTest)



and the output (drawn from my real data):

             cond_e1 Estimate Standard Error   DF t-value Lower CI Upper CI
cond_e1  wsh     4.0   0.5568         0.0328 11.6 16.9800    0.485    0.628
cond_e1  msd     1.0   0.6201         0.0327 11.3 18.9600    0.548    0.692
cond_e1  sgl     2.0   0.6399         0.0320 10.7 19.9700    0.569    0.711
cond_e1  spc     3.0   0.6056         0.0335 12.2 18.1000    0.533    0.678
p-value
cond_e1  wsh  <2e-16 ***
cond_e1  msd  <2e-16 ***
cond_e1  sgl  <2e-16 ***
cond_e1  spc  <2e-16 ***