## See vignette for the sampling scheme.
set.seed(1)
N <- 500
ncategories <- 4
clsize <- 3
Xmat <- matrix(rnorm(N), N, ncategories)
betas <- c(1, 2, 3, 4, 5, 6)
lin.pred <- matrix(c(betas[c(2, 4, 6)], 0), N, 4, byrow=TRUE) * Xmat +
matrix(c(betas[c(1, 3, 5)], 0), N, 4, byrow=TRUE)
lin.pred <- matrix(lin.pred, N, ncategories*clsize)
cor.matrix <- diag(1, 12)
## Fit a GEE model (Touloumis et al., 2013) to estimate the regression coefficients,
## i.e., the beta stars.
library(multgee)
Y <- rmult.bcl(clsize, ncategories, lin.pred, cor.matrix)$Ysim
data <- cbind(c(t(Y)), c(t(Xmat[,-ncategories])))
data <- data.frame(data)
data$id <- rep(1:N, each=clsize)
data$time <- rep(1:clsize, N)
colnames(data) <- c("y", "x", "id", "time")
fitmod <- nomLORgee(y~x, id=id, repeated=time, data=data, add=0.01)
coef(fitmod)
Run the code above in your browser using DataLab