# How to simulate binomial mixed effects data?

This R code simulates Gaussian mixed effects data with one random effect and one fixed effect. How would I modify that code to simulate Binomial mixed effects data with one random effect and one fixed effect?

-

I believe I solved this myself (R code here). The only difference is that the line:

data$value[data$unit==i] = as.numeric(mm %*% means[i,]) + rnorm(k*2,0,sqrt(noise))


gets replaced by :

data$value[data$unit==i] = rbinom(k*2,1,plogis(as.numeric(mm %*% means[i,])))


in the binomial(link='logit') case, while in the binomial(link='probit') case, use this:

data$value[data$unit==i] = rbinom(k*2,1,pnorm(as.numeric(mm %*% means[i,])))


(The difference between the logit and probit cases is the use of plogis in the former and pnorm in the latter)

-