Predict average slopes for several intervals using a model fitted by time_model()
.
Source: R/compute_slopes.R
compute_slopes.Rd
Comoute average slopes for "clubic slope", "linear splines" and "cubic splines"
fitted using time_model()
.
Arguments
- fit
A model object from a statistical model such as from a call to
time_model()
.- method
The type of model provided in
fit
, i.e., one of"cubic_slope"
,"linear_splines"
or"cubic_splines"
.- period
The intervals knots on which slopes are to be computed.
- knots
The knots as defined
fit
and according tomethod
.
Examples
data("bmigrowth")
ls_mod <- time_model(
x = "age",
y = "log(bmi)",
cov = NULL,
data = bmigrowth[bmigrowth[["sex"]] == 0, ],
method = "linear_splines"
)
#> nlme::lme(
#> fixed = log(bmi) ~ gsp(age, knots = c(0.75, 5.5, 11), degree = rep(1, 4), smooth = rep(0, 3)),
#> data = data,
#> random = ~ gsp(age, knots = c(0.75, 5.5, 11), degree = rep(1, 4), smooth = rep(0, 3)) | ID,
#> na.action = stats::na.omit,
#> method = "ML",
#> control = nlme::lmeControl(opt = "optim", maxIter = 500, msMaxIter = 500)
#> )
head(compute_slopes(
fit = ls_mod,
method = "linear_splines",
period = c(0, 0.5, 1.5, 3.5, 6.5, 10, 12, 17)#,
# knots = list(
# "cubic_slope" = NULL,
# "linear_splines" = c(0.75, 5.5, 11),
# "cubic_splines" = c(1, 8, 12)
# )[[method]]
))
#> ID pred_period_0 pred_period_0.5 pred_period_1.5 pred_period_3.5
#> 1 001 2.723878 2.924006 3.052294 3.127556
#> 2 004 2.589648 2.776216 2.890202 2.945406
#> 3 005 2.664667 2.768827 2.846761 2.915703
#> 4 006 2.563305 2.687913 2.759908 2.785750
#> 5 007 2.482096 2.801064 3.013571 3.154967
#> 6 009 2.714582 2.790200 2.830887 2.838559
#> pred_period_6.5 pred_period_10 pred_period_12 pred_period_17 slope_0--0.5
#> 1 3.250941 3.419375 3.535776 3.877164 0.4002572
#> 2 3.069558 3.310879 3.424940 3.650504 0.3731377
#> 3 3.070117 3.369271 3.510101 3.786891 0.2083212
#> 4 2.902621 3.221219 3.342805 3.495594 0.2492165
#> 5 3.322661 3.414705 3.516817 3.895885 0.6379362
#> 6 2.944679 3.289247 3.420563 3.584907 0.1512362
#> slope_1.5--3.5 slope_6.5--10 slope_12--17
#> 1 0.037630884 0.04812388 0.06827756
#> 2 0.027601764 0.06894873 0.04511272
#> 3 0.034471055 0.08547234 0.05535803
#> 4 0.012921103 0.09102806 0.03055786
#> 5 0.070697987 0.02629820 0.07581357
#> 6 0.003836079 0.09844796 0.03286874