Skip to content
Prev 18599 / 20628 Next

Simulating mixed-effects longitudinal logistic data in R

You can keep the same exact code with some changes:

- If you want to use logistic regression to recover the population
parameters, set: eij <- rlogis(J * n.time, scale = 1)

- If you use the normal distribution (rnorm), you will need probit
regression to recover population parameters: eij <- rnorm(J * n.time,
sd = 1)

- Note that the sd/scale has to be 1 as the estimated parameters will
be re-scaled by the value of sd(eij)

- Your y then will have to be as below to create a binary variable: y
<- ((rowSums(X * betaj[st.id, ]) + eij) > 0) + 0. Basically, you
dichotomize the generated y at 0. If you dichotomize at some other
value, the estimated intercept will shift accordingly.

- Finally, your population parameters have to make sense of the logit
scale. Intercept values of 300 and coefficients values of 25 are
unbelievable log-odds. You will generate all 1s with these population
parameters.

This is the latent variable approach to setting up the binary outcome
model.

The other answers do not use an error term to set up the model. For
these responses, you generate probabilities using either pnorm(LP)
(probit) or plogis(LP) (logistic) where LP is the linear predictor,
then pass the probabilities to rbinom() to obtain a binary variable.

James.
On Sun, 2020-07-12 at 17:11 -0500, Simon Harmel wrote:
https://urldefense.com/v3/__https://drizopoulos.github.io/GLMMadaptive/articles/GLMMadaptive_basics.html__;!!KGKeukY!jq0K6FHI0BtJ8LoX0xkhk9pv-4RgkiFLMeqSS8izqfz60XgQKODdgFKHcwYytJ5tqjwbaith3Ks$
https://urldefense.com/v3/__https://eur01.safelinks.protection.outlook.com/?url=https*3A*2F*2Fstat.ethz.ch*2Fmailman*2Flistinfo*2Fr-sig-mixed-models&amp;data=02*7C01*7Cd.rizopoulos*40erasmusmc.nl*7Cf46c256b636848749fc608d826a46b4e*7C526638ba6af34b0fa532a1a511f4ac80*7C0*7C0*7C637301834909767585&amp;sdata=GjOGQ*2Fv5aMwH8PK*2FuM*2FEeHkElDFwB6*2BaD8UZy2wVdx4*3D&amp;reserved=0__;JSUlJSUlJSUlJSUlJSUlJSUlJQ!!KGKeukY!jq0K6FHI0BtJ8LoX0xkhk9pv-4RgkiFLMeqSS8izqfz60XgQKODdgFKHcwYytJ5tqjwbWhOO65s$
https://urldefense.com/v3/__https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models__;!!KGKeukY!jq0K6FHI0BtJ8LoX0xkhk9pv-4RgkiFLMeqSS8izqfz60XgQKODdgFKHcwYytJ5tqjwbOi_tX1Q$
https://urldefense.com/v3/__https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models__;!!KGKeukY!jq0K6FHI0BtJ8LoX0xkhk9pv-4RgkiFLMeqSS8izqfz60XgQKODdgFKHcwYytJ5tqjwbOi_tX1Q$
https://urldefense.com/v3/__https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models__;!!KGKeukY!jq0K6FHI0BtJ8LoX0xkhk9pv-4RgkiFLMeqSS8izqfz60XgQKODdgFKHcwYytJ5tqjwbOi_tX1Q$