Skip to contents

Fit a cubic splines mixed model regression with three splines parametrisation as random effect. This function is a specific version of time_model().

Usage

egg_model(
  formula,
  data,
  id_var,
  random_complexity = "auto",
  use_car1 = FALSE,
  knots = c(1, 8, 12),
  quiet = FALSE
)

Arguments

formula

An object of class "formula": a symbolic description of the model to be fitted with, time component as the first term in the right-hand side.

data

A data.frame containing the variables defined in formula.

id_var

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

random_complexity

A numeric (1-3) indicating the complexity of the random effect term. Default, "auto" will try from the more complex to the less complex if no success.

use_car1

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

knots

The knots defining the splines.

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")
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)
#>   )
sres <- as.data.frame(summary(res)[["tTable"]])
rownames(sres) <- sub("gsp\\(.*\\)\\)", "gsp(...)", rownames(sres))
sres
#>                       Value   Std.Error  DF    t-value      p-value
#> (Intercept)      2.61835319 0.015188424 478 172.391363 0.000000e+00
#> gsp(...)D1(0)    0.87980825 0.048919995 478  17.984635 1.302819e-55
#> gsp(...)D2(0)   -1.88100109 0.111960768 478 -16.800538 4.066470e-50
#> gsp(...)D3(0)    1.92287447 0.115451509 478  16.655256 1.893624e-49
#> gsp(...)C(1).3  -1.93037596 0.116238566 478 -16.607018 3.153465e-49
#> gsp(...)C(8).3   0.01240328 0.004270085 478   2.904692 3.846477e-03
#> gsp(...)C(12).3 -0.01521666 0.011250160 478  -1.352573 1.768316e-01