unequal_clusters: Setup unbalanced cluster sizes

Description Usage Arguments Details Value See Also Examples

Description

Helps specifying unequal cluster sizes with study_parameters

Usage

1
unequal_clusters(..., func = NULL, trunc = 1, replace = 1)

Arguments

...

Any number of separate numeric arguments specifying each cluster's size

func

A function that generates cluster sizes, used instead of .... See Details.

trunc

Cutoff for values generated by func, x < trunc are replaced, used to avoid negative or 0 values.

replace

Indicates what value to replace cluster sizes less than trunc with.

Details

If func is used together with a function that generates random draws, e.g. rnorm or rpois, then cluster sizes (and possibly the number of clusters), will be treated as a random variable. The expected power is then reported by averaging over multiple realizations of the random variables.

Unless per_treatment is used, then the same realization of random cluster sizes will be used in both groups. To use independent realizations from the same distribution for each treatment group, simply combine the unequal_clusters with per_treatment.

Value

An object of type 'plcp_unequal_clusters'

See Also

per_treatment

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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
library(dplyr)
n2 <- unequal_clusters(5, 10, 15, 40)
p <- study_parameters(n1 = 11,
                      n2 = n2,
                      n3 = 6,
                      T_end = 10,
                      icc_pre_subject = 0.5,
                      icc_pre_cluster = 0,
                      sigma_error = 1,
                      var_ratio = 0.03,
                      icc_slope = 0.05,
                      cohend = -0.8)

# verify cluster sizes
d <- simulate_data(p)
d %>%
    filter(time == 0) %>%
    group_by(treatment, cluster) %>%
    summarise(n = n())

# Poisson distributed cluster sizes, same in both groups
n2 <- unequal_clusters(func = rpois(n = 5, lambda = 5))
p <- study_parameters(n1 = 11,
                      n2 = n2,
                      T_end = 10,
                      icc_pre_subject = 0.5,
                      icc_pre_cluster = 0,
                      sigma_error = 1,
                      var_ratio = 0.03,
                      icc_slope = 0.05,
                      cohend = -0.8)

# Independent draws from same dist
n2 <- unequal_clusters(func = rpois(n = 5, lambda = 5))
p <- study_parameters(n1 = 11,
                      n2 = per_treatment(n2, n2),
                      T_end = 10,
                      icc_pre_subject = 0.5,
                      icc_pre_cluster = 0,
                      sigma_error = 1,
                      var_ratio = 0.03,
                      icc_slope = 0.05,
                      cohend = -0.8)

# Use per_treatment() to specify per treatment ------------------------------
n2 <- per_treatment(unequal_clusters(2, 2, 2, 2, 3, 4, 5),
                     unequal_clusters(10, 15))
p <- study_parameters(n1 = 11,
                      n2 = n2,
                      n3 = 3,
                      T_end = 10,
                      icc_pre_subject = 0.5,
                      icc_pre_cluster = 0,
                      var_ratio = 0.03,
                      icc_slope = 0.05,
                      cohend = -0.8)

# verify cluster sizes
d <- simulate_data(p)
d %>%
    filter(time == 0) %>%
    group_by(treatment, cluster) %>%
    summarise(n = n())

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