# Simulate a Gompertz population with individual differences, then
# recover both the mean curve and the spread of its parameters.
set.seed(113)
d <- simulate_longitudinal_gompertz(
n = 40, target_times = 0:10,
fixed_parameters = c(alpha = 75, beta = 3, gamma = 0.55, zeta = 10),
random_variances = c(alpha = 25, beta = 0.4, gamma = 0.005, zeta = 4),
error_variance = 4
)
analysis_of_change(d, id = "id", time = "time", outcome = "y",
model = "gompertz")
# The same data as a straight-line (order 1) polynomial: the linear
# model has nothing to say about floors, ceilings, or timing.
analysis_of_change(d, id = "id", time = "time", outcome = "y",
model = "polynomial", order = 1)
# A single unit's trajectory: N = 1 is one fit, with asymptotic
# standard errors in place of between-unit spread.
one <- d[d$id == levels(d$id)[1], ]
analysis_of_change(one, id = NULL, time = "time", outcome = "y",
model = "gompertz")
# The proper mixed-effects model, fit simultaneously across units:
# nlme::nlme() for a nonlinear curve, lme4::lmer() for the polynomial
# (the latter requires lme4 to be installed).
analysis_of_change(d, id = "id", time = "time", outcome = "y",
model = "gompertz", method = "mixed")
analysis_of_change(d, id = "id", time = "time", outcome = "y",
model = "polynomial", order = 1,
method = "mixed")
Run the code above in your browser using DataLab