Skip to content
Prev 78652 / 398502 Next

Glmm for multiple outcomes

Does the following help:

n.subjects <- 3
J <- 4
K <- 5
n.ijk <- rep(2, each=n.subjects*J*K)

x <- rep(1:K, n.subjects, each=J)

subj <- factor(rep(1:n.subjects, each=K*J))

sa.subject <- 1
sb.subject <- 1

set.seed(2)
a.subj <- rep(sa.subject*rnorm(n.subjects), each=K*J)
b.subj <- rep(sb.subject*rnorm(n.subjects), each=K*J)

Z <- a.subj+b.subj*x

library(boot)
Y <- (rbinom(n.subjects*K*J, n.ijk, inv.logit(Z))
          /n.ijk)

Dat <- data.frame(subj=subj, x=x, y=Y)

library(lme4)

fit <- lmer(y~x+(x|subj), Dat)
Linear mixed-effects model fit by REML
Formula: y ~ x + (x | subj)
    Data: Dat
       AIC      BIC    logLik MLdeviance REMLdeviance
  51.63172 64.19779 -19.81586    33.1066     39.63172
Random effects:
  Groups   Name        Variance  Std.Dev. Corr
  subj     (Intercept) 0.0446346 0.211269
           x           0.0032613 0.057108 1.000
  Residual             0.0879438 0.296553
# of obs: 60, groups: subj, 3

Fixed effects:
              Estimate Std. Error DF t value Pr(>|t|)
(Intercept)  0.350000   0.151459 58  2.3109  0.02442 *
x            0.033333   0.042661 58  0.7814  0.43777
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

	  spencer graves
Abderrahim Oulhaj wrote: