Skip to contents

Derived slopes for different intervals based on a fitted cubic splines mixed-effects model from egg_model(). This function a specific version of compute_slopes designed to work specifically on egg_model().

Usage

egg_slopes(
  fit,
  period = c(0, 0.5, 1.5, 3.5, 6.5, 10, 12, 17),
  knots = c(1, 8, 12)
)

Arguments

fit

A model object from a statistical model such as from a call to egg_model().

period

The intervals knots on which slopes are to be computed.

knots

The knots as defined fit and according to method.

Value

A data.frame with slopes for each individuals/samples.

Examples

data("bmigrowth")
res <- egg_model(
  formula = log(bmi) ~ age,
  data = bmigrowth[bmigrowth[["sex"]] == 0, ],
  id_var = "ID",
  random_complexity = 1
)
#> Fitting model:
#>   nlme::lme(
#>     fixed = log(bmi) ~ gsp(age, knots = c(1, 8, 12), degree = rep(3, 4), smooth = rep(2, 3)),
#>     data = data,
#>     random = ~ gsp(age, knots = c(1, 8, 12), degree = rep(1, 4), smooth = rep(2, 3)) | ID,
#>     na.action = stats::na.omit,
#>     method = "ML",
#>     control = nlme::lmeControl(opt = "optim", niterEM = 25, maxIter = 500, msMaxIter = 500)
#>   )
head(
  egg_slopes(
    fit = res,
    period = c(0, 0.5, 1.5, 3.5, 6.5, 10, 12, 17),
    knots = c(1, 8, 12)
  )
)
#>    ID pred_period_0 pred_period_0.5 pred_period_1.5 pred_period_3.5
#> 1 082      2.747393        2.992282        2.992529        3.019458
#> 2 083      2.584858        2.832240        2.837474        2.874377
#> 3 080      2.599374        2.848047        2.855865        2.897935
#> 4 031      2.502765        2.745423        2.741210        2.759217
#> 5 007      2.617232        2.883761        2.927290        3.040782
#> 6 033      2.599044        2.838782        2.828728        2.835054
#>   pred_period_6.5 pred_period_10 pred_period_12 pred_period_17 slope_0--0.5
#> 1        3.214495       3.451351       3.572620       3.801536    0.4897771
#> 2        3.084375       3.338686       3.469928       3.723779    0.4947641
#> 3        3.115684       3.379037       3.515447       3.782216    0.4973477
#> 4        2.940873       3.162117       3.274465       3.481078    0.4853166
#> 5        3.365663       3.754004       3.961836       4.407158    0.5330585
#> 6        2.999186       3.199988       3.300654       3.478063    0.4794758
#>   slope_1.5--3.5 slope_6.5--10 slope_12--17
#> 1    0.013464430    0.06767327   0.04578315
#> 2    0.018451388    0.07266023   0.05077011
#> 3    0.021034975    0.07524382   0.05335370
#> 4    0.009003884    0.06321273   0.04132261
#> 5    0.056745807    0.11095465   0.08906453
#> 6    0.003163061    0.05737191   0.03548179