5
$\begingroup$

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

$\endgroup$
9
  • $\begingroup$ Have you had a look at the lmerTest Package? It has a lsmeans function. $\endgroup$
    – Daniel
    Commented May 20, 2015 at 6:26
  • $\begingroup$ @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 $\endgroup$
    – ghonke
    Commented May 20, 2015 at 15:26
  • 2
    $\begingroup$ 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. $\endgroup$ Commented May 20, 2015 at 17:30
  • $\begingroup$ @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 $\endgroup$
    – ghonke
    Commented May 20, 2015 at 23:34
  • $\begingroup$ 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. $\endgroup$ Commented May 21, 2015 at 0:40

1 Answer 1

2
$\begingroup$

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

require(lmerTest)

lsmeans(mymodel, test.effs=NULL, method.grad='simple')

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 ***
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.