[R-sig-ME] help in coding random effects in lmer

Mike Lawrence Mike.Lawrence at dal.ca
Sun Aug 1 03:07:57 CEST 2010


I'm still learning mixed effects modelling myself, but one thing pops
out at me: In your formulae, you have the variable "meanRT"; I presume
this reflects the fact that you aggregated your data to means within
conditions prior to submitting it to lmer? If so, you have done
yourself a disservice; lmer can analyze the raw, trial-by-trial data
and you'll find that you can achieve higher power by providing it will
all the data. Now, a problem arises whereby RT data are  typically
positively skewed and violate the normality assumption; I feel there
is still a gap in the literature on how to deal with this (because
there are plenty of examples where this skew has been found to be
affected by experimental manipulations differentially from central
tendency), but a reciprocal transform at least seems to do well at
normalizing the residuals (Kliegl, Masson & Richter, 2009, compare
various transforms).

So, where "a" is your trial-by-trial data, I suggest you try:
a$rrt = 1/a$rt
fit1 = lmer(
    formula = rrt ~ (angle+laterality+condition:laterality)+(1|subject)
    , data = a
)

and let us know if you still get wonky results.

As a side note, l *think* that the difference between the two models
you posted was that the second permitted the effects to vary Ss-by-Ss,
which may be plausible but I assume costs power. As I understand it,
unless you are really interested in individual differences in the
effect (eg. for correlations, etc), it's better to avoid letting
effects vary Ss-by-Ss. (Again, I'm still getting to grips with mixed
effects modelling, so I may be entirely incorrect on these points!).

On Sat, Jul 31, 2010 at 8:41 AM, nuala brady <nuala.brady at ucd.ie> wrote:
> Dear lmer people & Dr Bates
>
>  I  am a cognitive psychologist who needs to leave the  world of ANOVA and move to lmer. I am looking for advice on coding  random effects in lmer.
>
>   My experiment is: 30 subjects judge the laterality of a hand (i.e.. say whether it is a left or right hand) presented onscreen which varies in its
>  (A) Laterality (2 levels, right/left) and
>  (B) Orientation (8 levels, 0 to 315 degs in steps of 45 degs) while holding their own hands in one of 3 postures
>  (C) Postures (3 levels, coded as both, minusRight & minusLeft).
>
>  The dependent variable is reaction time (RT).
>
>  Laterality, Orientation & Posture are fixed effects (all  coded as categorical variables), the random effects come from the  subjects i.e.,
>  all 30 subjects respond in all possible combinations of the  experimental variables and we need to generalise from them to the  population ...
>
>  My expectation (based on theory & previous studies) is that there will be a sig. main effect of angle, of laterality & possibly a condition by laterality interaction;
>  and graphing shows this.
>
>  The traditional way to analyse such data  in psychology, where we typically look at all main effects & possible  interactions as a first pass,  is via a repeated measures
>  (or within-subjects) ANOVA and the  code in R is
>
>  aov(RT~Laterality*Angle*Posture+Error(subject/(Laterality*Angle*Posture)),data=RTdata)
>
>  moving to lmer, simplifying the model to just look at effects I am interested in, and specifying the random effects as shown in many examples online as follows:
>
>  model2a<-lmer(meanRT~(angle+laterality+condition:laterality)+(1|subject),data=RTdata)
>
>  I receive the output shown below as OUTPUT 1. Looking at the table of fixed effects I note that the Std. Err. within a specific explanatory variable (e.g, Angle) is constant across all levels of that variable. Obviously I am on the wrong track as this is not an assumption I want to  make. One of the reasons I am moving from ANOVA to lmer is because variance is not constant across the levels of some factors (both angle & laterality) as seen from graph, by running levene's test etc
>
>  Rerunning as:
>  model2<-lmer(meanRT~(angle+laterality+condition:laterality)+(angle|subject)+(laterality|subject)+(condition:laterality|subject),data=RTdata)
>
>  (...and quite honestly, I am generalizing here from how one might specify error in aov....)
>
>  I receive the output shown below as OUTPUT 2. Scrolling down to the fixed effects, the Std., Errs are looking a lot better to me, BUT I am unsure whether I am using the
>  syntax correctly
>
>
>  can anyone advise?  I  appreciate this may be a very basic question, but I have not found many  examples in my reading except for nested designs (which do not apply here, as least in my understanding of 'nested designs' ), and crossed random effects (which seem more complex than I need, having more than 1 source of random effects)
>
>  thanks in advance, - Nuala
>
>  ps - in case the description of the experiment is not clear, I copy data for s1 (aine) at the very end of the email - this pattern will repeat for s2 to s30
>
>  OUTPUT 1: summary(model2a)
>  Linear mixed model fit by REML
>  Formula: meanRT ~ (angle + laterality + condition:laterality) + (1 | subject)
>     Data: data
>     AIC   BIC logLik deviance REMLdev
>   20620 20699 -10295    20700   20590
>  Random effects:
>   Groups   Name        Variance Std.Dev.
>   subject  (Intercept) 124335   352.61
>   Residual              94809   307.91
>  Number of obs: 1440, groups: subject, 30
>
>  Fixed effects:
>                                      Estimate Std. Error t value
>  (Intercept)                          1218.82      70.70  17.240
>  angle45                                13.49      32.46   0.416
>  angle90                               217.20      32.46   6.692
>  angle135                              499.11      32.46  15.378
>  angle180                              961.80      32.46  29.633
>  angle225                              471.60      32.46  14.530
>  angle270                              228.82      32.46   7.050
>  angle315                               62.12      32.46   1.914
>  lateralityright                      -122.60      28.11  -4.362
>  lateralityleft:conditionminusLeft      14.23      28.11   0.506
>  lateralityright:conditionminusLeft    -27.28      28.11  -0.971
>  lateralityleft:conditionminusRight    -33.77      28.11  -1.201
>  lateralityright:conditionminusRight    35.94      28.11   1.279
>
>
>  OUTPUT 2: summary(model2)
>   Linear mixed model fit by REML
>  Formula: meanRT ~ (angle + laterality + condition:laterality) + (angle | subject) + (laterality | subject) + (condition:laterality |subject)
>     Data: data
>     AIC   BIC logLik deviance REMLdev
>   19918 20345  -9878    19867   19756
>  Random effects:
>   Groups   Name                                Variance   Std.Dev.   Corr
>   subject  (Intercept)                         3.5601e+04 188.681267
>            angle45                             3.5488e+01   5.957191  1.000
>            angle90                             1.9515e+04 139.697353  1.000
>            angle135                            7.8349e+04 279.909544  0.704
>            angle180                            3.3373e+05 577.689525  0.390
>            angle225                            7.1096e+04 266.638569  0.462
>            angle270                            1.7412e+04 131.954987  0.695
>            angle315                            7.1155e+03  84.353226  0.759
>   subject  (Intercept)                         2.5444e-04   0.015951
>            lateralityright                     5.2171e-05   0.007223 -1.000
>   subject  (Intercept)                         1.4016e+04 118.388702
>            conditionboth:lateralityleft        1.2554e+04 112.046691  0.327
>            conditionminusLeft:lateralityleft   3.0653e+04 175.080964  0.257
>            conditionminusRight:lateralityleft  1.6837e+04 129.758438 -0.019
>            conditionboth:lateralityright       1.0627e+04 103.089657 -0.340
>            conditionminusLeft:lateralityright  9.6021e+03  97.990531 -0.822
>            conditionminusRight:lateralityright 1.0345e+04 101.711720 -0.453
>   Residual                                     4.2251e+04 205.549629
>
>
>
>    1.000
>    0.704  0.704
>    0.390  0.390  0.847
>    0.462  0.462  0.837  0.889
>    0.695  0.695  0.711  0.609  0.867
>    0.759  0.759  0.324 -0.042  0.021  0.317
>
>
>
>
>    0.424
>    0.196  0.569
>    0.428 -0.431 -0.555
>   -0.112 -0.364 -0.475  0.730
>   -0.451 -0.211  0.622 -0.400 -0.094
>
>  Number of obs: 1440, groups: subject, 30
>
>  Fixed effects:
>                                      Estimate Std. Error t value
>  (Intercept)                          1218.82      52.37  23.273
>  angle45                                13.49      21.69   0.622
>  angle90                               217.20      33.47   6.490
>  angle135                              499.11      55.51   8.992
>  angle180                              961.80     107.67   8.933
>  angle225                              471.60      53.29   8.850
>  angle270                              228.82      32.40   7.062
>  angle315                               62.12      26.58   2.337
>  lateralityright                      -122.60      28.20  -4.348
>  lateralityleft:conditionminusLeft      14.23      35.18   0.404
>  lateralityright:conditionminusLeft    -27.28      23.13  -1.180
>  lateralityleft:conditionminusRight    -33.77      33.79  -0.999
>  lateralityright:conditionminusRight    35.94      36.48   0.985
>
>
>  Example data for 1 subject
>  data[1:48,1:5] - RT is actially mean RT of 18 trails
>     subject laterality  posture angle    RT
>  1     aine       left       both     0  844.8000
>  2     aine       left       both    45  796.4706
>  3     aine       left       both    90 1007.5722
>  4     aine       left       both   135 1214.7556
>  5     aine       left       both   180 1249.9625
>  6     aine       left       both   225 1305.0500
>  7     aine       left       both   270 1043.8000
>  8     aine       left       both   315  814.6833
>  9     aine       left  minusLeft     0  817.3778
>  10    aine       left  minusLeft    45  951.0588
>  11    aine       left  minusLeft    90 1044.5706
>  12    aine       left  minusLeft   135 1345.5625
>  13    aine       left  minusLeft   180 1482.8333
>  14    aine       left  minusLeft   225 1331.3588
>  15    aine       left  minusLeft   270  985.1000
>  16    aine       left  minusLeft   315  995.2563
>  17    aine       left minusRight     0  986.8556
>  18    aine       left minusRight    45  903.2176
>  19    aine       left minusRight    90  947.8059
>  20    aine       left minusRight   135 1453.8750
>  21    aine       left minusRight   180 1698.8278
>  22    aine       left minusRight   225 1337.1200
>  23    aine       left minusRight   270 1109.2467
>  24    aine       left minusRight   315  929.0412
>  25    aine      right       both     0  913.5944
>  26    aine      right       both    45  930.5056
>  27    aine      right       both    90 1093.9167
>  28    aine      right       both   135 1275.9647
>  29    aine      right       both   180 1489.1750
>  30    aine      right       both   225 1188.1333
>  31    aine      right       both   270 1054.7778
>  32    aine      right       both   315  904.8722
>  33    aine      right  minusLeft     0  888.9375
>  34    aine      right  minusLeft    45  915.0706
>  35    aine      right  minusLeft    90 1060.3167
>  36    aine      right  minusLeft   135 1240.0867
>  37    aine      right  minusLeft   180 1772.4611
>  38    aine      right  minusLeft   225 1168.5625
>  39    aine      right  minusLeft   270 1093.1889
>  40    aine      right  minusLeft   315  842.2667
>  41    aine      right minusRight     0  971.3944
>  42    aine      right minusRight    45  974.3333
>  43    aine      right minusRight    90 1064.9833
>  44    aine      right minusRight   135 1389.0059
>  45    aine      right minusRight   180 1575.9000
>  46    aine      right minusRight   225 1322.6444
>  47    aine      right minusRight   270 1053.7389
>  48    aine      right minusRight   315 1077.0529
>
>
>  Nuala Brady
>  School of Psychology
>  University College Dublin
>  Belfield, D4
>  IRELAND
>
>  +353 (0)1 716 8247
>  nuala.brady at ucd.ie
>
>
>
>        [[alternative HTML version deleted]]
>
>
> _______________________________________________
> R-sig-mixed-models at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models
>
>



-- 
Mike Lawrence
Graduate Student
Department of Psychology
Dalhousie University

Looking to arrange a meeting? Check my public calendar:
http://tr.im/mikes_public_calendar

~ Certainty is folly... I think. ~




More information about the R-sig-mixed-models mailing list