2

I need to write a model in R by using nlme library with multiple random intercepts and slopes.

What I need is:

  1. Random intercept for Participants,
  2. Random intercept for TargetID,
  3. Random slope to see how the effect of OrderofImages varies across participants,
  4. Random slope to see how the effect of OrderofImages varies across TargetID (meaning different targets)

MyModel

lme(Ratings ~ OrderofImages, 
    random = list(
      1|Participants, 
      1|TargetID, 
      OrderofImages|Participants, 
      OrderofImages|TargetID), 
    data = myData, 
    na.action = na.exclude)

Many thanks for your help!

MrFlick
  • 195,160
  • 17
  • 277
  • 295
Yesim
  • 193
  • 1
  • 1
  • 7
  • 3
    So what exactly is your question here? – MrFlick Feb 04 '20 at 22:15
  • 1
    These look like crossed random effects, so it may be easier to use `lme4` instead. – Axeman Feb 04 '20 at 22:21
  • Hi, participants rated the target images. So, yes crossed random effects. I am sorry that I was not clear. The order of the images being shown might affect the ratings among participants, and also order of the images can affect the ratings depending on the image being shown. – Yesim Feb 05 '20 at 10:39

1 Answers1

6

I agree with @Axeman: it's hard to know for sure, but it seems almost certain your grouping variables (participant and targetID) are crossed, that is that you have multiple targets with the same identity across participants (i.e., targetID "A" (or whatever) is the same target for participants Smith and Jones). If so, then doing what you want with lme will be difficult; lme4::lmer is much better at crossed random effects, which would be specified as follows:

lme4::lmer(Ratings ~ OrderofImages  + 
      (1 + OrderofImages|Participants) + 
      (1 + OrderofImages|TargetID), 
    data = myData, 
    na.action = na.exclude)
  • if you need 'denominator degrees of freedom' (F/t tests rather than chi-square/LRT/Z tests), try the lmerTest package
  • these effects might be nested, if say targetID "A" is different for different participants: see the GLMM FAQ, or this CrossValidated question, for a little more discussion of "nested vs. crossed"
  • there is one crossed random-effect example with lme in Pinheiro and Bates's book (p. 163ff)
Ben Bolker
  • 211,554
  • 25
  • 370
  • 453
  • 1
    Also see https://stats.stackexchange.com/questions/228800/crossed-vs-nested-random-effects-how-do-they-differ-and-how-are-they-specified – Axeman Feb 04 '20 at 22:30
  • I actually used nlme library because my dependent variable was not normally distributed. Can I still use lmer with non-Gaussian data? – Yesim Feb 05 '20 at 10:38
  • 1
    I'm a bit puzzled. `lme` doesn't handle non-Gaussian responses (except via the `glmmPQL` extension, in the `MASS` package. You can use `lme4::glmer` to fit non-Gaussian (exponential family) responses, or `lme4::glmer.nb` for negative binomial responses, or the `glmmTMB` package for some other response distributions. – Ben Bolker Feb 05 '20 at 12:38