time_model: Fit one of three mixed model.

View source: R/time_model.R

time_modelR Documentation

Fit one of three mixed model.

Description

Fit a mixed model regression with "cubic slope", "linear splines" or "cubic splines" as fixed and random effects.

Usage

time_model(
  x,
  y,
  cov = NULL,
  data,
  method = c("cubic_slope", "linear_splines", "cubic_splines"),
  knots = list(cubic_slope = NULL, linear_splines = c(0.75, 5.5, 11), cubic_splines =
    c(1, 8, 12))[[method]],
  use_car1 = FALSE,
  id_var = "ID",
  quiet = FALSE
)

Arguments

x

A length one character vector with the main covariate name (i.e., right-hand side).

y

A length one character vector with the variable name to be explained (i.e., left-hand side).

cov

A vector of addtional/optional covariates names to included in the fixed effect part of the linear mixed-effects models.

data

A data.frame containing the variables named in x and y.

method

The type of model, i.e., one of "cubic_slope", "linear_splines" or "cubic_splines".

knots

The knots defining the splines for "linear_splines" and "cubic_splines" methods.

use_car1

A logical indicating whether to use continuous auto-correlation, i.e., CAR(1) as correlation structure.

id_var

A string indicating the name of the variable to be used as the individual identifier.

quiet

A logical indicating whether to suppress the output.

Value

An object of class "lme" representing the linear mixed-effects model fit.

Examples

data("bmigrowth")
ls_mod <- time_model(
  x = "age",
  y = "log(bmi)",
  cov = NULL,
  data = bmigrowth[bmigrowth[["sex"]] == 0, ],
  method = "linear_splines"
)
sres <- as.data.frame(summary(ls_mod)[["tTable"]])
rownames(sres) <- sub("gsp\\(.*\\)\\)", "gsp(...)", rownames(sres))
sres

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