[R-lang] lmer for by item and by subject analysis
Tine Mooshammer
tine at haskins.yale.edu
Fri May 9 08:16:38 PDT 2008
>
> 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?
yes, sure:
Linear mixed-effects model fit by REML
Formula: logAc ~ structure + (1 | sp) + (1 | code2)
Data: latrmE
AIC BIC logLik MLdeviance REMLdeviance
-489 -459.2 251.5 -524 -503
Random effects:
Groups Name Variance Std.Dev.
code2 (Intercept) 0.0069926 0.083622
sp (Intercept) 0.0454584 0.213210
Residual 0.0164155 0.128123
number of obs: 520, groups: code2, 26; sp, 20
Fixed effects:
Estimate Std. Error t value
(Intercept) 5.64618 0.06193 91.17
structureCV -0.12430 0.05590 -2.22
structureCVC -0.09259 0.05039 -1.84
structureCCV -0.39861 0.05930 -6.72
structureCCVC -0.37137 0.05930 -6.26
Correlation of Fixed Effects:
(Intr) strcCV strCVC strCCV
structureCV -0.451
structurCVC -0.501 0.555
structurCCV -0.426 0.471 0.523
structrCCVC -0.426 0.471 0.523 0.444
For model 1+structure|sp
Linear mixed-effects model fit by REML
Formula: logAc ~ structure + (1 + structure | sp) + (1 | code2)
Data: latrmE
AIC BIC logLik MLdeviance REMLdeviance
-486.3 -397 264.2 -549.4 -528.3
Random effects:
Groups Name Variance Std.Dev. Corr
code2 (Intercept) 0.0070048 0.083695
sp (Intercept) 0.0374311 0.193471
structureCV 0.0030771 0.055472 -0.348
structureCVC 0.0100272 0.100136 -0.348 0.812
structureCCV 0.0014262 0.037765 -0.298 0.632 0.955
structureCCVC 0.0088162 0.093895 -0.298 0.632 0.955 1.000
Residual 0.0147228 0.121338
number of obs: 520, groups: code2, 26; sp, 20
Fixed effects:
Estimate Std. Error t value
(Intercept) 5.64618 0.05848 96.55
structureCV -0.12430 0.05701 -2.18
structureCVC -0.09259 0.05493 -1.69
structureCCV -0.39861 0.05962 -6.69
structureCCVC -0.37137 0.06264 -5.93
Correlation of Fixed Effects:
(Intr) strcCV strCVC strCCV
structureCV -0.520
structurCVC -0.587 0.566
structurCCV -0.475 0.475 0.528
structrCCVC -0.497 0.480 0.580 0.462
>>
>> 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).
I'm using the current version, 0.99875-9
With your data I still get a warning for logAc.lmer2
Warning message:
In .local(x, ..., value) :
Estimated variance-covariance for factor ‘sp’ is singular
Does this mean that the variance of struct on sp is so small that it can
be neglected?
Sorry for stupid questions... And thanks for your quick answer.
Tine
>
> 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
--
++++++++++++++++++++++++++++++++
Dr. Christine Mooshammer
New address/Neue Adresse:
Haskins Laboratories
300 George St., Suite 900
New Haven, CT 06511
USA
Phone: ++1 203 865 6163 315
Email: tine at haskins.yale.edu
+++++++++++++++++++++++++++++++++
More information about the R-lang
mailing list