compute_slopes: Predict average slopes for several intervals using a model...

View source: R/compute_slopes.R

compute_slopesR Documentation

Predict average slopes for several intervals using a model fitted by time_model().

Description

Comoute average slopes for "clubic slope", "linear splines" and "cubic splines" fitted using time_model().

Usage

compute_slopes(
  fit,
  method,
  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]]
)

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 to method.

Value

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

Examples

data("bmigrowth")
ls_mod <- time_model(
  x = "age",
  y = "log(bmi)",
  cov = NULL,
  data = bmigrowth[bmigrowth[["sex"]] == 0, ],
  method = "linear_splines"
)
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]]
))

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