[R-sig-ME] incorrect weights type in lmer

Douglas Bates bates at stat.wisc.edu
Tue May 22 23:44:08 CEST 2007


On 5/22/07, Sundar Dorai-Raj <sundar.dorai-raj at pdf.com> wrote:
> Hi, all,
>
> I'm receiving an error I don't understand regarding a weights argument
> to lmer. Here's an example:
>
> library(lme4)
> set.seed(1)
> tmp.df <- expand.grid(A = factor(1:3), B = 1:3, C = 1:10)
> tmp.df$w <- as.integer(rpois(nrow(tmp.df), 50))
> tmp.df$p <- 0.5 + with(tmp.df, ifelse(B%%2, -0.1, 0.1))
> tmp.df$p <- with(tmp.df, p + ifelse(B%%2 & C%%2, -0.1, 0.1))
> tmp.df$y <- rbinom(nrow(tmp.df), tmp.df$w, tmp.df$p)/tmp.df$w
> tmp.df[2:3] <- lapply(tmp.df[2:3], factor)
> fit <- lmer(y ~ A + (1 | B) + (1 | B:C), tmp.df, binomial, weights = w)
>
> Error in lmer(y ~ A + (1 | B) + (1 | B:C), tmp.df, binomial, weights = w) :
>         object `weights' of incorrect type
>
> What sort of object is lmer expecting for weights?

Thanks for pointing out the problem, Sundar.  Although this is not
documented the weights need to be double precision and you are using
integers.  Your example works with weights = as.double(w) or weights =
as.numeric(w).

Most of the time R will quietly coerce integers to numeric as needed
but not in this case.




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