Fit a mixed model regression with "cubic slope", "linear splines" or "cubic splines" as fixed and random effects.
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
andy
.- 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.
Examples
data("bmigrowth")
ls_mod <- time_model(
x = "age",
y = "log(bmi)",
cov = NULL,
data = bmigrowth[bmigrowth[["sex"]] == 0, ],
method = "linear_splines"
)
#> nlme::lme(
#> fixed = log(bmi) ~ gsp(age, knots = c(0.75, 5.5, 11), degree = rep(1, 4), smooth = rep(0, 3)),
#> data = data,
#> random = ~ gsp(age, knots = c(0.75, 5.5, 11), degree = rep(1, 4), smooth = rep(0, 3)) | ID,
#> na.action = stats::na.omit,
#> method = "ML",
#> control = nlme::lmeControl(opt = "optim", maxIter = 500, msMaxIter = 500)
#> )
sres <- as.data.frame(summary(ls_mod)[["tTable"]])
rownames(sres) <- sub("gsp\\(.*\\)\\)", "gsp(...)", rownames(sres))
sres
#> Value Std.Error DF t-value p-value
#> (Intercept) 2.66826332 0.016046220 480 166.286095 0.000000e+00
#> gsp(...)D1(0) 0.27458917 0.024989904 480 10.988004 3.309661e-25
#> gsp(...)C(0.75).1 -0.25208766 0.025973809 480 -9.705456 1.873317e-20
#> gsp(...)C(5.5).1 0.05132095 0.007890419 480 6.504211 1.964795e-10
#> gsp(...)C(11).1 -0.02340424 0.011618719 480 -2.014356 4.452943e-02