[R-sig-ME] Simulating mixed-effects longitudinal logistic data in R
D. Rizopoulos
d@r|zopou|o@ @end|ng |rom er@@mu@mc@n|
Sun Jul 12 23:58:34 CEST 2020
Have a look in this example: https://drizopoulos.github.io/GLMMadaptive/articles/GLMMadaptive_basics.html
Best,
Dimitris
��
Dimitris Rizopoulos
Professor of Biostatistics
Erasmus University Medical Center
The Netherlands
________________________________
From: R-sig-mixed-models <r-sig-mixed-models-bounces using r-project.org> on behalf of Simon Harmel <sim.harmel using gmail.com>
Sent: Sunday, July 12, 2020 10:44:17 PM
To: r-sig-mixed-models <r-sig-mixed-models using r-project.org>
Subject: [R-sig-ME] Simulating mixed-effects longitudinal logistic data in R
Good afternoon,
I know to simulate a linear mixed-effects longitudinal data in R, I can use
the procedure below.
But I wonder how to generate a similar design, but for a logistic model in
R?
I appreciate your suggestions,
Simon
#------------- linear mixed-effects longitudinal data in R-------
library(MASS)
growth.sim <- function(J, n.time, gammas, G, sigma = 1, seed = NULL) {
X <- cbind(1, seq_len(n.time) - 1) # time indicators for each individual
X <- X[rep(seq_len(n.time), J), ] # Repeat each row n.time times
st.id <- seq_len(J) # individual id
st.id <- rep(st.id, each = n.time) # repeat each ID n.time times
set.seed(seed) ## what should go below, possibly correlated Beta?
uj <- MASS::mvrnorm(J, mu = rep(0, 2), Sigma = G) # Generate u0 and u1
random effects for intercepts and slopes
## I think no error term is needed for logistic version?
eij <- rnorm(J * n.time, sd = sigma) # Generate error
term for observations
betaj <- matrix(gammas, nrow = J, ncol = 2, byrow = TRUE) + uj #
Compute beta_j's
y <- rowSums(X * betaj[st.id, ]) + eij # Compute outcome
based on Yij = sum(Xij*Bj) + eij:
dat <- data.frame(st.id, time = X[ , 2], y) # Output a data frame
return(dat) # Return data}
*##==== Example of use: =====*
growth.sim(10, 4, gammas = c(300, 25),
G = matrix(c(0.1, 0,
0, 0.01), nrow = 2))
[[alternative HTML version deleted]]
_______________________________________________
R-sig-mixed-models using r-project.org mailing list
https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fstat.ethz.ch%2Fmailman%2Flistinfo%2Fr-sig-mixed-models&data=02%7C01%7Cd.rizopoulos%40erasmusmc.nl%7Cf46c256b636848749fc608d826a46b4e%7C526638ba6af34b0fa532a1a511f4ac80%7C0%7C0%7C637301834909767585&sdata=GjOGQ%2Fv5aMwH8PK%2FuM%2FEeHkElDFwB6%2BaD8UZy2wVdx4%3D&reserved=0
[[alternative HTML version deleted]]
More information about the R-sig-mixed-models
mailing list