Description Usage Arguments Value See Also Examples
This is en example of a data transformation applied during simulation. It takes the longitudinal data and transforms it into a pretest-posttest model in wide format. Useful if you want to compare the longitudinal LMM with e.g. AN(C)OVA models.
1 |
data |
a |
a data.frame
with y
now only includes the posttest values.
Also includes three new columns:
pre
subject-level pretest scores.
pre_cluster
cluster-level pretest scores.
pre_subject_c
subject-level pretest scores center
around the cluster-level pretest.
simulate.plcp
, study_parameters
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | # Compare longitudinal 3-level model to 2-level model
# fit to just the posttest data
#
# Both models are fit to the same dataset during simulation.
p <- study_parameters(n1 = 11,
n2 = 20,
n3 = 3,
icc_pre_subject = 0.5,
icc_pre_cluster = 0.1,
icc_slope = 0.05,
var_ratio = 0.03)
# simulation formulas
# analyze as a posttest only 2-level model
f_pt <- sim_formula("y ~ treatment + (1 | cluster)",
test = "treatment",
data_transform = transform_to_posttest)
# analyze as 3-level longitudinal
f_lt <- sim_formula("y ~ time*treatment +
(1 + time | subject) +
(1 + time | cluster)")
f <- sim_formula_compare("posttest" = f_pt,
"longitudinal" = f_lt)
## Not run:
res <- simulate(p,
formula = f,
nsim = 2000,
cores = parallel::detectCores(),
satterthwaite = TRUE)
summary(res)
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.