[R-sig-ME] 3 bugs in lmer

Terry Therneau therneau at mayo.edu
Thu Sep 25 19:51:50 CEST 2008


These are of the better-user-interface variety; features that are common to all 
the other model functions that I know of, but seem to be missing in lmer.  One 
could argue that "shortfalls" would be a better label than "bugs".  

> version
               _                           
platform       sparc-sun-solaris2.10       
arch           sparc                       
os             solaris2.10                 
system         sparc, solaris2.10          
status                                     
major          2                           
minor          7.1                         
year           2008                        
month          06                          
day            23                          
svn rev        45970                       
language       R                           
version.string R version 2.7.1 (2008-06-23)


#1 - subsets
fit1c <- lmer(il2 ~ (1|plate/id), data=allsets, subset=(il2>0) )
fit1d <- lmer(il2 ~ (1|plate/id), data=allsets, subset= il2>0)

  I always put subset arguments in parenthesis for readability.  (In the actual 
code that sparked this message, the subset expression was longer, and it helps 
more).  Both models fit ok, but the first one doesn't print.
  
> all.equal(coef(fit1c), coef(fit1d)
[1] TRUE
> print(fit1c)
Linear mixed model fit by REML 
Formula: il2 ~ (1 | plate/id) 
   Data: allsets 
Error in sprintf(gettext(fmt, domain = domain), ...) : 
  object "x" not found


#2 coefficients
  Like everyone else, I almost never type the full "coefficients" method and use 
the "coef" abbreviation.  But I happened to do so today:
  
> coefficients(fit1d)
Error in object$coefficients : $ operator not defined for this S4 class


#3  character variables

  I almost never, ever, turn a character variable into a factor.  We can argue 
about the wisdom of my choice another day, but you'll likely not sway me.  
Character variables work fine in model statements, being treated as factors; for 
models other than lmer.
  Here is a fit on my original data set, before I modified it for the benefit of 
 lmer:

> fit1b <- lmer(il2 ~ (1|plate/id), data=data2)        
Error in id:plate : NA/NaN argument
In addition: Warning messages:
1: In id:plate :
  numerical expression has 3184 elements: only the first used
2: In id:plate :
  numerical expression has 3184 elements: only the first used
3: In inherits(x, "factor") : NAs introduced by coercion

By the way, there are no odd or missing values in plate or id.  

Oops, I just realized the above is wrong: plate is an integer.  So try again:

>  table(data2$plate)

 1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 
80 80 70 80 80 80 46 78 80 80 80 80 80 64 80 80 80 80 80 80 76 80 80 80 80 80 
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 
80 70 80 80 80 80 80 80 80 80 64 80 80 80 80 

> fit1b <- lmer(il2 ~ (1|factor(plate)/id), data=data2)
Error in inherits(x, "factor") : object "plate" not found

> data2$plate2 <- factor(data2$plate)
> fit1b <- lmer(il2 ~ (1|plate2/id), data=data2)   

Error in id:plate2 : NA/NaN argument
In addition: Warning messages:
1: In id:plate2 :
  numerical expression has 3184 elements: only the first used
2: In id:plate2 :
  numerical expression has 3184 elements: only the first used
3: In inherits(x, "factor") : NAs introduced by coercion

> data2$id2 <- factor(data2$id)
> fit1b <- lmer(il2 ~ (1|plate2/id2), data=data2)   
>  # Finally works


	Terry Therneau




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