Predict BMI values a cubic splines mixed model regression
with three splines parametrisation as random effect.
This function also works for any model obtained using time_model()
.
Arguments
- fit
A model object from a statistical model such as from a call
nlme::lme()
,time_model()
oregg_model()
.- start
The start of the time window to compute AP and AR.
- end
The end of the time window to compute AP and AR.
- step
The step to increment the sequence.
- filter
A string following
data.table
syntax for filtering on"i"
(i.e., row elements), e.g.,filter = "source == 'A'"
. Argument pass throughcompute_apar()
(seepredict_bmi()
). Default isNULL
.
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)
#> )
predict_bmi(res)[]
#> egg_id egg_ageyears egg_bmi
#> <char> <num> <num>
#> 1: 082 0.25 16.21582
#> 2: 082 0.26 16.29086
#> 3: 082 0.27 16.36399
#> 4: 082 0.28 16.43521
#> 5: 082 0.29 16.50453
#> ---
#> 48796: 068 9.96 30.83642
#> 48797: 068 9.97 30.85793
#> 48798: 068 9.98 30.87946
#> 48799: 068 9.99 30.90100
#> 48800: 068 10.00 30.92255
## For multiple sources of measures or multiple measures at one age
set.seed(1234)
dta <- bmigrowth[bmigrowth[["sex"]] == 0, ]
dta[["source"]] <- c("A", "B")[rbinom(n = nrow(dta), size = 1, prob = 0.65) + 1]
res <- egg_model(
formula = log(bmi) ~ age + source,
data = dta,
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)) + source,
#> 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)
#> )
predict_bmi(res)[order(egg_id, egg_ageyears)]
#> Warning: Multiple BMI measures (for the same age) have been detected and are aggregated using geometric mean!
#> Use "filter" (or "filter" in `run_eggla_lmm()`) parameter to apply some filtering, e.g., filter = "source == 'clinic'".
#> egg_id egg_ageyears egg_bmi
#> <char> <num> <num>
#> 1: 001 0.25 18.42096
#> 2: 001 0.26 18.50635
#> 3: 001 0.27 18.58958
#> 4: 001 0.28 18.67063
#> 5: 001 0.29 18.74953
#> ---
#> 48796: 099 9.96 33.73105
#> 48797: 099 9.97 33.75703
#> 48798: 099 9.98 33.78303
#> 48799: 099 9.99 33.80905
#> 48800: 099 10.00 33.83508
predict_bmi(res, filter = "source == 'A'")[order(egg_id, egg_ageyears)]
#> egg_id egg_source egg_ageyears egg_bmi
#> <char> <char> <num> <num>
#> 1: 001 A 0.25 18.39947
#> 2: 001 A 0.26 18.48476
#> 3: 001 A 0.27 18.56789
#> 4: 001 A 0.28 18.64885
#> 5: 001 A 0.29 18.72765
#> ---
#> 48796: 099 A 9.96 33.69170
#> 48797: 099 A 9.97 33.71765
#> 48798: 099 A 9.98 33.74362
#> 48799: 099 A 9.99 33.76960
#> 48800: 099 A 10.00 33.79560