transform_to_posttest: Helper to transform the simulated longitudinal 'data.frame'

Description Usage Arguments Value See Also Examples

Description

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.

Usage

1

Arguments

data

a data.frame created using simulate_data

Value

a data.frame with y now only includes the posttest values. Also includes three new columns:

See Also

simulate.plcp, study_parameters

Examples

 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)

powerlmm documentation built on May 2, 2019, 3:10 a.m.