predict_bmi: Predict BMI for a range of ages from a model fit.

View source: R/predict_bmi.R

predict_bmiR Documentation

Predict BMI for a range of ages from a model fit.

Description

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().

Usage

predict_bmi(fit, start = 0.25, end = 10, step = 0.01, filter = NULL)

Arguments

fit

A model object from a statistical model such as from a call nlme::lme(), time_model() or egg_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 through compute_apar() (see predict_bmi()). Default is NULL.

Value

A data.table object.

Examples

data("bmigrowth")
res <- egg_model(
  formula = log(bmi) ~ age,
  data = bmigrowth[bmigrowth[["sex"]] == 0, ],
  id_var = "ID",
  random_complexity = 1
)

predict_bmi(res)[]

## 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
)

predict_bmi(res)[order(egg_id, egg_ageyears)]

predict_bmi(res, filter = "source == 'A'")[order(egg_id, egg_ageyears)]

mcanouil/eggla documentation built on April 5, 2025, 3:06 a.m.