[R] lmer error confusion

Douglas Bates bates at stat.wisc.edu
Wed May 16 19:20:22 CEST 2007


On 5/16/07, Rick DeShon <deshon at msu.edu> wrote:
> Hi All.
>
> I'm trying to run a simple model from Baayan, Davidson, & Bates and getting
> a confusing error message.  Any ideas what I'm doing wrong here?
>
> # Here's the data.....
> Subj    <- factor(rep(1:3,each=6))
> Item    <- factor(rep(1:3,6))
> SOA     <- factor(rep(0:1,3,each=3))
> RT      <-
> c(466,520,502,475,494,490,516,566,577,491,544,526,484,529,539,470,511,528)
> priming <- data.frame(cbind(Subj,Item,SOA,RT))
>
> str(priming)
> 'data.frame':   18 obs. of  4 variables:
>  $ Subj: num  1 1 1 1 1 1 2 2 2 2 ...
>  $ Item: num  1 2 3 1 2 3 1 2 3 1 ...
>  $ SOA : num  1 1 1 2 2 2 1 1 1 2 ...
>  $ RT  : num  466 520 502 475 494 490 516 566 577 491 ...
>
> #Here's the call taken directly from the paper
> priming.lmer1 <- lmer(RT ~ SOA + (1 | Item) + (1 | Subj), data = priming)
>
> #Here's the error....
> Error in rbind(Item = <S4 object of class "dgCMatrix">, Subj = <S4 object of
> class "dgCMatrix">) :
>         cannot coerce type S4 to list vector
>
> Any idea what I'm doing wrong?
>
>
> sessionInfo()
> R version 2.5.0 (2007-04-23)
> i386-pc-mingw32
> other attached packages:
>        lme4      Matrix     lattice        nlme
> "0.9975-13" "0.99875-1"    "0.15-4"    "3.1-80"

It's a version skew problem (and thanks for including the
sessionInfo() output that makes it possible to detect this).  Changes
were made in version 0.99875-0 and later of the Matrix package that
require a new version of the lme4 package.  Please install version
0.99875-0 or later of lme4.

However, while we are discussing this example, notice that using the
cbind inside the call to data.frame causes the factors to become
numeric variables.  That is undesirable.  In this case it is benign
but it could be harmful.

A better approach is simply to give the variables and their names in
the call data.frame.  Also, the sequence factor(rep(...)) can be
written better as a call to the underutilized function gl.

> priming <- data.frame(Subj = gl(3,6), Item = gl(3,1,18), SOA = gl(2,3,18,labels = 0:1),
+   RT = c(466,520,502,475,494,490,516,566,577,491,544,526,484,529,539,470,511,528))
> str(priming)
'data.frame':   18 obs. of  4 variables:
 $ Subj: Factor w/ 3 levels "1","2","3": 1 1 1 1 1 1 2 2 2 2 ...
 $ Item: Factor w/ 3 levels "1","2","3": 1 2 3 1 2 3 1 2 3 1 ...
 $ SOA : Factor w/ 2 levels "0","1": 1 1 1 2 2 2 1 1 1 2 ...
 $ RT  : num  466 520 502 475 494 490 516 566 577 491 ...
> lmer2(RT ~ SOA + (1|Subj) + (1|Item), priming)
Linear mixed-effects model fit by REML
Formula: RT ~ SOA + (1 | Subj) + (1 | Item)
   Data: priming
   AIC BIC logLik MLdeviance REMLdeviance
 149.4 153 -70.72      154.4        141.4
Random effects:
 Groups   Name        Variance Std.Dev.
 Subj     (Intercept) 499.37   22.347
 Item     (Intercept) 607.80   24.654
 Residual             137.35   11.719
Number of obs: 18, groups: Subj, 3; Item, 3

Fixed effects:
            Estimate Std. Error t value
(Intercept)  522.111     19.604  26.633
SOA1         -18.889      5.525  -3.419

Correlation of Fixed Effects:
     (Intr)
SOA1 -0.141



More information about the R-help mailing list