8

I'm doing Linear mixed-effects model fit by REML in nlme package. And these are codes that work for me:

# Linear mixed-effects model fit by REML (intercept and not slope)
x <- lme (DV ~ IV1 + IV2 + IV1*IV2, data=a.frame, random=~1|speaker)
summary(x)

# Linear mixed-effects model fit by REML (slope and no intercept)
x1 <- lme (DV ~ IV1 + IV2 + IV1*IV2, data=a.frame, random=~IV3-1|speaker)
summary(x1)

# Linear mixed-effects model fit by REML (slope and intercept)
x2 <- lme (DV ~ IV1 + IV2 + IV1*IV2, data=a.frame, random=~IV3|speaker)
summary(x2)

#nested random effect
x5 <- lme (DV ~ IV1 + IV2 + IV1*IV2, data=a.frame, random=~1|speaker/item)
summary(x5)

What I really would like to do is having a model with both speaker and item as random effects separately. I had tried to use this formula:

x4 <- lme (DV ~ IV1 + IV2 + IV1*IV2, data=a.frame, random=~1|speaker + 1|item)

However, this formula gives me the following warning message:

Warning message:
In Ops.factor(speaker, 1) : + not meaningful for factors

Do you have any idea what this means? And how can I fit both speaker and item as random effects separately?

Cœur
  • 37,241
  • 25
  • 195
  • 267
user3288202
  • 313
  • 1
  • 4
  • 14
  • Use package lme4. It gives you more flexibility in defining the random part of the model. – Roland Feb 08 '14 at 22:11
  • But I can't get the p-value directly from that package as I'm using the new version of R, can I? I have tried that package before and I can't use the 'pval' function. / This package is convenient in that it directly gives me p-value. / I have tried these formula: – user3288202 Feb 08 '14 at 22:28
  • 4
    x <- lme (DV ~ IV1, data=a.frame, random=list(~1|speaker, ~1|item)) and this gives me the same results as... x1 <- lme (DV ~ IV, data=a.frame, random=~1|speaker/item) Actually the random effects of the second formula should mean 'item nested in speaker' and the first one should mean 'item and speakers as random effects separately. In the output, I don't know why both of them give me the formulas in the summaries as: Random effects: Formula: ~1|speaker Formula: ~1|item %in% speaker with exactly the same values and everything. instead of: Random effects: Formula: ~1|speaker Formula: ~1|item – user3288202 Feb 08 '14 at 22:31
  • 6
    if you use `lme4` in conjunction with the `lmerTest` package you can specify the model *and* get the p-values you want (via Satterthwaite or Kenward-Roger approximation). The chances are reasonably good that `lme` wouldn't be giving you the **correct** p-value anyway ... – Ben Bolker May 06 '14 at 18:13
  • Thanks Ben Bolker. Now it seems that I don't have to use lmerTest anymore, as I do the pairwise comparisons after LMM using lsmeans and this gives me p value directly. – user3288202 May 09 '14 at 09:38

1 Answers1

2

I think it is possible to include two random effects seperately (one for speaker and one for time) using lme() by the following code:

x4 <- lme (DV ~ IV1 + IV2 + IV1*IV2, data=a.frame, random=~ speaker + item -1 | id),

with id a higher level variable in which both speaker and item are nested. If you don't have such a variable, you could introduce it as a new variable with value 1 for all observations.

Uwe
  • 41,420
  • 11
  • 90
  • 134
Fien
  • 31
  • 5