[R-sig-ME] How to handle tabular form data in lmer/glmer without (or with) expanding the data into binary outcome form?

Dale Steele dale.w.steele at gmail.com
Wed May 20 01:10:22 CEST 2009


A recent thread
<https://stat.ethz.ch/pipermail/r-help/2009-April/194750.html>
suggested the glmer can handle data in tabular form.  I'm working
through (not homework) the simple random effects example from Agresti,
An Introduction to Categorical Data Analysis, 2nd Ed. (pg 303 - 304)
and am having problems...

# Data from Table 10.2 n_i: number of free throws, p_i: observed
proportion of successes

id <- seq(1:15)
n <- c(13,10,15,14,6,10,10,4,11,10,8,9,9,8,6)
p <- c(.769, .9, .667, .643, .667, .9, .6, 1, .545, .9, .5, .889,
.778, .625, .167)
(success <- round(n * p))
fail <- n - success
data <- cbind(success, fail)

# Model to fit: logit(pi_i) = mu_i + alpha

library(lme4)
#  Model
m1 <- glmer(data ~ 1 + (1 | id), family="binomial", nAGQ=50)
summary(m1)

The code runs, and produces results similar, but not exactly what
Agresti gets (alpha_hat=0.908 and sigma_hat=0.422). Shouldn't the
'number of obs' be 143 rather than 15?  Am I doing something wrong?

 > summary(m1)
> m1 <- glmer(data ~ 1 + (1 | id), family="binomial", nAGQ=50)
> summary(m1)

Generalized linear mixed model fit by the adaptive Gaussian Hermite
approximation
Formula: data ~ 1 + (1 | id)
  AIC   BIC logLik deviance
 32.8 34.21  -14.4     28.8
Random effects:
 Groups Name        Variance Std.Dev.
 id     (Intercept) 0.16258  0.40321
Number of obs: 15, groups: id, 15

Fixed effects:
            Estimate Std. Error z value Pr(>|z|)
(Intercept)   0.9059     0.2142    4.23 2.34e-05 ***

I tried to run the same model by expanding the tabular data. Easy
enough to expand the id variable.
#
(subj <- rep(id,n))

However, I'm stuck on how to expand outcome variable for each player
and concatenate as a single vector...
# first player
oc1 <- rep(c(1,0), sf[1,])

Appreciate any insight anyone may provide on how to use tabular data
directly and how to expand tubular data.  Thanks! --Dale




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