[R-sig-ME] scope for LHS of formula in lmList

Ken Knoblauch ken.knoblauch at inserm.fr
Mon Sep 6 12:46:35 CEST 2010


Ken Knoblauch <ken.knoblauch at ...> writes:
> I have a data frame
>   str(Context)
> 'data.frame':	120 obs. of  4 variables:
>   $ Obs     : Factor w/ 6 levels "A","B","C","D",..: 1 1 1
>   $ TargCntr: num  0 0.002 0.004 0.006 0.008 0 0.
>   $ NumYes  : int  0 0 5 18 23 24 22 22 22 24 ...
>   $ NumNo   : int  24 24 19 6 1 0 2 2 2 0 ...
> and find that if I run lmList as follows, I get an error message
> in which names from the data frame are not found if enclosed in
> a cbind for the LHS of formula (for a binomial family)
> lmList(cbind(NumYes, NumNo) ~ TargCntr | Obs,
> 	data = Context, family = binomial)
> Error in cbind(NumYes, NumNo) : object 'NumYes' not found
> ...
> but it works fine if I either define a 2 column matrix in my
> workspace or add one to the data frame.
> resp <- with(Context, cbind(NumYes, NumNo))
> lmList(resp ~ TargCntr | Obs, Context, binomial)
> Call: lmList(formula = resp ~ TargCntr | Obs, data = Context, family =  
> binomial)
> Coefficients:
>    (Intercept) TargCntr
> A  -0.8574118 369.1977
> B  -0.8048122 425.1355
>   ...
> 
<snip>
> 
> sessionInfo()
> R version 2.11.1 Patched (2010-08-30 r52847)
> Platform: i386-apple-darwin9.8.0/i386 (32-bit)
> 
> locale:
> [1] en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/en_US.UTF-8
> 
> attached base packages:
> [1] stats     graphics  grDevices utils     datasets  methods
> [7] base
> 
> other attached packages:
> [1] lme4_0.999375-35   Matrix_0.999375-44 lattice_0.19-11
> 
> loaded via a namespace (and not attached):
> [1] grid_2.11.1   MASS_7.3-7    nlme_3.1-96   stats4_2.11.1
> [5] tools_2.11.1
> 
Just a quick followup to my own message.  It isn't
specific to the LHS of the formula but seems to
affect variables that are isolated within a 
function call whether on the left or right hand
side, e.g., 


lmList(resp ~ I(1000 * TargCntr) | Obs, Context, binomial)
Error in unique(c("AsIs", oldClass(x))) : object 'TargCntr' not found
...

Thanks, 

Ken




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