# The examples reproduce the National Youth Survey illustration of
# Raudenbush and Liu (2001, p. 393). One observation per year
# (frequency = 1) over a four-year study (duration = 4) gives
# M = frequency * duration + 1 = 5 equally spaced occasions. The
# standardized slope difference is -0.40, the slope variance is
# tau = 0.003, and the level-one error variance is 0.0262, so the slope
# reliability is 0.53.
# (1) Power at a given sample size. With N = 238 (119 per group) the
# design has power 0.61 (Raudenbush and Liu, 2001, Table 1, D = 4,
# f = 1).
ss_power_pcm(beta = -.4, tau = .003, level_1_variance = .0262,
frequency = 1, duration = 4, N = 238)
# (2) Sample size for a target power. Solving the same design for 0.80
# power returns N = 370 (185 per group), between their Table 2 cells
# N = 300 (power 0.71) and N = 400 (power 0.83).
ss_power_pcm(beta = -.4, tau = .003, level_1_variance = .0262,
frequency = 1, duration = 4, desired_power = .80)
# (3) Unstandardized slope. The unstandardized slope difference is
# beta * sqrt(tau) = -0.40 * sqrt(0.003) = -0.0219. Passing it with
# standardized = FALSE reproduces the power of 0.61 from example (1).
ss_power_pcm(beta = -.0219, tau = .003, level_1_variance = .0262,
frequency = 1, duration = 4, N = 238, standardized = FALSE)
# (4) Longer study, same number of occasions. Doubling the duration to
# D = 8 while keeping M = 5 (so frequency = 0.5, one observation every
# two years) raises the slope reliability to 0.82 and power to about
# 0.80. Spreading the same five occasions over a longer span sharply
# increases power (Raudenbush & Liu, 2001, p. 393).
ss_power_pcm(beta = -.4, tau = .003, level_1_variance = .0262,
frequency = .5, duration = 8, N = 238)
# (5) More frequent sampling over a shorter span, same occasions. Halving
# the duration to D = 2 while keeping M = 5 (so frequency = 2) drops
# the slope reliability to 0.22 and power to about 0.31. Sampling more
# often over a shorter study does little for power (Raudenbush & Liu,
# 2001, p. 393).
ss_power_pcm(beta = -.4, tau = .003, level_1_variance = .0262,
frequency = 2, duration = 2, N = 238)
# (6) One-sided test. A directional test of the base design places the
# whole Type I error rate in the predicted tail, raising power from
# 0.61 to about 0.73.
ss_power_pcm(beta = -.4, tau = .003, level_1_variance = .0262,
frequency = 1, duration = 4, N = 238, directional = TRUE)
# (7) A higher-order trend. The same machinery plans power for the group
# difference in any polynomial change coefficient. Here the target is
# the quadratic trend (curvature / acceleration): with eight occasions
# (frequency = 1, duration = 7), a between-subject quadratic-coefficient
# variance tau = 0.002, level-one error variance 0.05, and a
# standardized quadratic difference of 0.45, the design is planned for
# 0.80 power. A quadratic trend needs at least three occasions; a cubic
# at least four (trend = "cubic" or trend = 3), and so on.
ss_power_pcm(beta = 0.45, tau = 0.002, level_1_variance = 0.05,
frequency = 1, duration = 7, desired_power = .80,
trend = "quadratic")
Run the code above in your browser using DataLab