# NOT RUN {
# Two-level ---------------------------------------------------------------
p <- study_parameters(n1 = 11,
n2 = 25,
sigma_subject_intercept = 1.44,
sigma_subject_slope = 0.2,
sigma_error = 1.44,
effect_size = cohend(0.5))
f <- sim_formula("y ~ treatment * time + (1 + time | subject)")
res <- simulate(object = p,
nsim = 1000,
formula = f,
satterthwaite = TRUE,
progress = FALSE,
cores = 1,
save = FALSE)
summary(res)
# Three-level (nested) ------------------------------------------------------
p <- study_parameters(n1 = 10,
n2 = 20,
n3 = 4,
sigma_subject_intercept = 1.44,
icc_pre_cluster = 0,
sigma_subject_slope = 0.2,
icc_slope = 0.05,
sigma_error = 1.44,
effect_size = 0)
## compare correct and miss-specified model
f0 <- "y ~ treatment * time + (1 + time | subject)"
f1 <- "y ~ treatment * time + (1 + time | subject) + (0 + time | cluster)"
f <- sim_formula_compare("correct" = f1,
"wrong" = f0)
res <- simulate(object = p,
nsim = 1000,
formula = f,
satterthwaite = TRUE,
progress = FALSE,
cores = 1,
save = FALSE)
summary(res)
## Compare random effects using LRT,
## summarise based on best model from each sim
summary(res,
model_selection = "FW",
LRT_alpha = 0.1,
para = "treatment:time")
# Partially nested design ---------------------------------------------------
p <- study_parameters(n1 = 11,
n2 = 10,
n3 = 4,
sigma_subject_intercept = 1.44,
icc_pre_cluster = 0,
sigma_subject_slope = 0.2,
cor_subject = -0.5,
icc_slope = 0.05,
sigma_error = 1.44,
partially_nested = TRUE,
effect_size = cohend(-0.5))
f <- sim_formula("y ~ treatment * time + (1 + time | subject) +
(0 + treatment:time | cluster)")
res <- simulate(object = p,
nsim = 1000,
formula = f,
satterthwaite = TRUE,
progress = FALSE,
cores = 4,
save = FALSE)
summary(res)
# Run multiple designs -----------------------------------------------------
p <- study_parameters(n1 = 10,
n2 = 20,
n3 = c(2, 4, 6),
sigma_subject_intercept = 1.44,
icc_pre_cluster = 0,
sigma_subject_slope = 0.2,
icc_slope = 0.05,
sigma_error = 1.44,
effect_size = cohend(0.5))
f0 <- "y ~ treatment * time + (1 + time | subject)"
f1 <- "y ~ treatment * time + (1 + time | subject) + (0 + time | cluster)"
f <- sim_formula_compare("correct" = f1,
"wrong" = f0)
res <- simulate(object = p,
nsim = 1000,
formula = f,
satterthwaite = TRUE,
progress = FALSE,
cores = 1,
save = FALSE)
# Summarize 'time:treatment' results for n3 = c(2, 4, 6) for 'correct' model
summary(res, para = "time:treatment", model = "correct")
# Summarize cluster-level random slope for n3 = c(2, 4, 6) for 'correct' model
summary(res, para = "cluster_slope", model = "correct")
# }
Run the code above in your browser using DataLab