# The family in one panel: five Richards curves sharing alpha, beta,
# gamma, and zeta and differing only in the shape parameter delta.
# delta near 0 is the Gompertz, delta = 1 is the logistic, and
# larger delta pushes the inflection later than halfway. Each curve
# is its own population of size one, so a single call draws the whole panel.
panel <- simulate_longitudinal_richards(
n = 1, target_times = seq(0, 12, by = 0.1),
fixed_parameters = list(
c(alpha = 80, beta = 6, gamma = 0.9, delta = 0.02, zeta = 10),
c(alpha = 80, beta = 6, gamma = 0.9, delta = 0.25, zeta = 10),
c(alpha = 80, beta = 6, gamma = 0.9, delta = 1.00, zeta = 10),
c(alpha = 80, beta = 6, gamma = 0.9, delta = 3.00, zeta = 10),
c(alpha = 80, beta = 6, gamma = 0.9, delta = 8.00, zeta = 10)),
error_variance = 0
)
plot_trajectories(panel, id = "id", time = "time",
outcome = "true_score", group = "population")
# Individual differences in a single parameter: only the shape
# varies (a named entry leaves the other variances at zero), so the
# curves agree on floor, ceiling, timing, and curvature yet turn
# from acceleration to deceleration at different heights.
set.seed(113)
d_delta <- simulate_longitudinal_richards(
n = 25, target_times = seq(0, 12, by = 0.5),
fixed_parameters = c(alpha = 80, beta = 6, gamma = 0.9,
delta = 1, zeta = 10),
random_variances = c(delta = 0.04), error_variance = 0
)
plot_trajectories(d_delta, id = "id", time = "time",
outcome = "true_score")
# Individual differences in every parameter, plus level-one error:
# a late-inflecting outbreak-style curve, with delta = 3 placing the
# inflection at about 63% of total change, (1 + 3)^(-1/3).
set.seed(113)
d <- simulate_longitudinal_richards(
n = 30, target_times = 0:12,
fixed_parameters = c(alpha = 80, beta = 6, gamma = 0.9,
delta = 3, zeta = 10),
random_variances = c(alpha = 36, beta = 1, gamma = 0.01,
delta = 0.04, zeta = 9),
error_variance = 16
)
plot_trajectories(d, id = "id", time = "time", outcome = "y")
# delta = 1 reproduces the logistic exactly: with no randomness and
# no error, the two simulators return identical true scores.
d_r <- simulate_longitudinal_richards(
n = 1, target_times = 0:5,
fixed_parameters = c(alpha = 80, beta = 3, gamma = 1,
delta = 1, zeta = 10),
error_variance = 0)
d_l <- simulate_longitudinal_logistic(
n = 1, target_times = 0:5,
fixed_parameters = c(alpha = 80, beta = 3, gamma = 1, zeta = 10),
error_variance = 0)
all.equal(d_r$true_score, d_l$true_score)
Run the code above in your browser using DataLab