[R-sig-ME] Simulating beta-distributed outcome in glmmTMB
Simon Harmel
@|m@h@rme| @end|ng |rom gm@||@com
Tue Dec 10 03:47:21 CET 2024
Hello all,
I'm trying to simulate about 50 datasets each with a beta-distributed
outcome (Y) according to the R code below.
For each dataset, I would like to randomly determine the parameter
values for "beta=" and/or "theta=" arguments in my
glmmTMB::simulate_new() call such that I avoid getting Y values that
are close to 0 or 1.
I was wondering how you all suggest I can achieve this?
Thanks, Simon
## R code for 1 dataset:
library(tidyverse)
library(glmmTMB)
n_participant=100
n_time=3
groups = c("A","B", "Control")
set.seed(123)
dd <- data.frame(ID = ID <- rep(1:n_participant, each = n_time),
time = factor(rep(0:(n_time-1), n_participant),
levels=0:(n_time-1)),
group = factor(sample(groups, n_participant, replace=TRUE)[ID],
levels = groups))
dd$Y <- simulate_new(
~ group*time + (time | ID),
family = beta_family(),
newdata = dd,
newparams = list(beta = c(.2, .2, .3, .5, .1, 1.7, .9, .3, .1),
theta = c(-1.1, -1.25, -1.4, -1.2, -1.4, -1.3)))[[1]]
model <- glmmTMB(Y ~ group*time + (time | ID),
family = beta_family(),
data = dd)
VarCorr(model)
More information about the R-sig-mixed-models
mailing list