[R-lang] lmer for by item and by subject analysis
Roger Levy
rlevy at ucsd.edu
Thu May 8 15:23:18 PDT 2008
Tine Mooshammer wrote:
> I have RT for 20 subjects from a delayed naming experiment with
> different syllable structures (VC, CV, CVC etc.). Therefore, item and
> structure (the experimental condition) are confounded.
>
> Example for the data:
> sp code2 structure logAc
> 1 F01 cake CVC 5.544396
> 2 F01 cape CVC 5.459586
> 3 F01 Kay CV 5.450609
> 4 F01 lake CVC 4.830711
> 5 F01 lay CV 4.705016
> 6 F01 pape CVC 5.446306
> 7 F01 pate CVC 5.319590
> 8 F01 pay CV 5.535364
> 9 F01 skate CCVC 5.116795
> 10 F01 skay CCV 5.189060
>
hi Tine,
> The lmer works well for the simple model:
> RTE.lmer=lmer(logAc ~ structure + (1|sp) + (1|code2), latrmE)
Could you show us the output of this model?
>
> but I get the following error messages for the more complicated model:
> RTE.lmerS=lmer(logAc ~ structure + (1+structure|sp) + (1|code2), latrmE)
> Warning messages:
> 1: In .local(x, ..., value) :
> Estimated variance-covariance for factor ‘sp’ is singular
>
> 2: In .local(x, ..., value) :
> nlminb returned message false convergence (8)
>
> Does that mean that I don't have to account for different speaker slopes
> or is there an error in the specification of the model or empty cells in
> the data (I'm not aware of that)?
I'm going to guess that you might have a very small estimated random
effect of specific structure by speaker. See below as well.
>
> Furthermore, a slightly different specification for the model seems to be
>
> > RTE.lmerS=lmer(logAc ~ structure + (1|sp:structure) + (1|code2), latrmE)
Note that this really is a different model than the (1 + structure | sp)
model. In the (1 + structure | sp) model, speakers who are slow for one
structure will tend to be slow for other structures as well. This is
not the case for the (1 | sp:structure) model.
>
> but then I get the following error messages:
>
> Error in sp:structure : NA/NaN argument
> In addition: Warning messages:
> 1: In sp:structure :
> numerical expression has 520 elements: only the first used
> 2: In sp:structure :
> numerical expression has 520 elements: only the first used
> 3: In inherits(x, "factor") : NAs introduced by coercion
What version of lme4 are you using? With the development version (on
R-Forge), I am able to produce toy data that all three of your model
specifications work reasonably well on (appended at end).
This might also turn out to be a good question for the R-sig-ME list.
But you should probably give the development version of lme4 a try, if
that's not what you're using already.
Best
Roger
***
mu <- 6
nsubj <- 20
ncodes <- 20
struct.effect <- c(0,1)
subj.int <- rnorm(nsubj,0, 1)
subj.slope <- rnorm(nsubj, 0, 0.05)
code2.int <- rnorm(ncodes, 0, 1)
dat <- expand.grid(sp=1:nsubj, code2=1:ncodes)
dat$struct <- ifelse(dat$code2>(ncodes/2), 2, 1)
dat <- within(dat, logAc <- mu + struct.effect[struct] + subj.int[sp] +
subj.slope[sp]*struct + code2.int[code2] + rnorm(nsubj*ncodes, 0, 1))
dat
dat$struct <- factor(dat$struct)
dat$sp <- factor(dat$sp)
dat$code2 <- factor(dat$code2)
logAc.lmer1 <- lmer(logAc ~ struct + (1 | sp) + (1 | code2), data=dat,
method="ML")
logAc.lmer2 <- lmer(logAc ~ struct + (1 + struct | sp) + (1 | code2),
dat, method="ML")
logAc.lmer3 <- lmer(logAc ~ struct + (1 | sp:struct) + (1 | code2), dat,
method="ML")
> logAc.lmer1
Linear mixed model fit by maximum likelihood
Formula: logAc ~ struct + (1 | sp) + (1 | code2)
Data: dat
AIC BIC logLik deviance REMLdev
1292 1312 -640.8 1282 1283
Random effects:
Groups Name Variance Std.Dev.
sp (Intercept) 0.60403 0.77720
code2 (Intercept) 0.62855 0.79281
Residual 1.13088 1.06343
Number of obs: 400, groups: sp, 20; code2, 20
Fixed effects:
Estimate Std. Error t value
(Intercept) 6.1954 0.3142 19.719
struct2 0.6435 0.3702 1.739
Correlation of Fixed Effects:
(Intr)
struct2 -0.589
> logAc.lmer2
Linear mixed model fit by maximum likelihood
Formula: logAc ~ struct + (1 + struct | sp) + (1 | code2)
Data: dat
AIC BIC logLik deviance REMLdev
1295 1323 -640.7 1281 1282
Random effects:
Groups Name Variance Std.Dev. Corr
sp (Intercept) 0.636429 0.79776
struct2 0.035020 0.18714 -0.272
code2 (Intercept) 0.629427 0.79336
Residual 1.121574 1.05904
Number of obs: 400, groups: sp, 20; code2, 20
Fixed effects:
Estimate Std. Error t value
(Intercept) 6.1954 0.3168 19.555
struct2 0.6435 0.3726 1.727
Correlation of Fixed Effects:
(Intr)
struct2 -0.598
> logAc.lmer3
Linear mixed model fit by maximum likelihood
Formula: logAc ~ struct + (1 | sp:struct) + (1 | code2)
Data: dat
AIC BIC logLik deviance REMLdev
1313 1333 -651.6 1303 1304
Random effects:
Groups Name Variance Std.Dev.
sp:struct (Intercept) 0.61738 0.78573
code2 (Intercept) 0.63429 0.79643
Residual 1.12153 1.05902
Number of obs: 400, groups: sp:struct, 40; code2, 20
Fixed effects:
Estimate Std. Error t value
(Intercept) 6.1954 0.3161 19.60
struct2 0.6435 0.4470 1.44
Correlation of Fixed Effects:
(Intr)
struct2 -0.707
More information about the R-lang
mailing list