[R-sig-ME] Multi-level Rasch Model Per Douglas Bates' paper

Rasmus Liland jr@| @end|ng |rom po@teo@no
Wed May 13 19:25:02 CEST 2020


On 2020-05-13 18:50 +0200, Rasmus Liland wrote:
> Indeed it does work now!  Thanks!

Right, so this code reproduces code until the 
easiness variable on page 15.  Perhaps this 
is useful?

data("lq2002", package="multilevel")
wrk <- lq2002
# wrk[1:5,]
for (i in 3:16) wrk[[i]] <- ordered(wrk[[i]])
for (i in 17:21) wrk[[i]] <- ordered(5 - wrk[[i]])
lql <- reshape(wrk,
  varying = list(names(lq2002)[3:21]),
  v.names = "fivelev",
  idvar = "subj",
  timevar = "item",
  drop = names(lq2002)[c(2, 22:27)],
  direction = "long")
lql$itype <-
  with(lql, factor(ifelse(item < 12, "Leadership",
    ifelse(item < 15, "Task Sig.", "Hostility")
  )))
for (i in c(1, 2, 4, 5)) lql[[i]] <- factor(lql[[i]])
lql$dichot <- factor(ifelse(lql$fivelev < 4, 0, 1))
# str(lql)
# summary(lql)

## 3.2 Fitting an initial multilevel Rasch model
(fm1 <- lme4::glmer(
  dichot ~ 0 + itype + (1 | subj) +
    (1 | COMPID) +
    (1 | item),
  lql,
  binomial))
rr <- lme4::ranef(fm1, condVar = TRUE)
str(rr$COMPID)
head(rr$COMPID)

qq <- lattice::qqmath(rr)
print(qq$subj)

## 3.3 Allowing for interactions of company and item type
(fm2 <- lme4::glmer(
  dichot ~ 0 + itype + (1 | subj) +
    (0 + itype | COMPID) +
    (1 | item),
  lql,
  binomial))

(fm3 <- lme4::glmer(
  dichot ~ 0 + itype + (1 | subj) +
    (1 | COMPID:itype) +
    (1 | item),
  lql,
  binomial))

(fm3a <- lme4::glmer(
  dichot ~ 0 + itype + (1 | subj) +
    (1 | COMPID:itype) +
    (1 | COMPID) +
    (1 | item),
  lql,
  binomial))

anova(fm3, fm3a, fm2)

str(imap <- unique(lql[, c("itype", "item")]))

(easiness <-
  lme4::ranef(fm2)$item[[1]] +
  glmmTMB::fixef(fm2)[imap$itype])

Best,
Rasmus



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