Skip to contents

Given an outcome and time variable, fit the cosinor model with optional covariate effects.

Usage

cglmm(
  formula,
  data,
  family = stats::gaussian(),
  quietly = TRUE,
  dispformula = ~1,
  ziformula = ~0,
  ...
)

Arguments

formula

A formula specifying the cosinor model to be fit. The cosinor portion of the formula is controlled by including amp_acro() on the right hand side of the formula. See amp_acro for more details.

data

A data.frame containing the variables used in the model.

family

A family function or a character string naming a family function. See ?family and ?glmmTMB::family_glmmTMB for options.

quietly

A logical. If TRUE, shows warning messages when wrangling data and fitting model. Defaults to TRUE.

dispformula

A one-sided (i.e., no response variable) formula for dispersion combining fixed and random effects, including cosinor components using amp_acro(). Defaults to ~1.

ziformula

A one-sided (i.e., no response variable) formula for zero-inflation combining fixed and random effects, including cosinor components using amp_acro(). Defaults to ~0.

...

Optional additional arguments passed to glmmTMB::glmmTMB().

Value

Returns a fitted cosinor model as a cglmm object.

References

Tong, YL. Parameter Estimation in Studying Circadian Rhythms, Biometrics (1976). 32(1):85--94.

Examples

# Single component cosinor model
cglmm(
  vit_d ~ amp_acro(time_col = time, group = "X", period = 12),
  data = vitamind
)
#> 
#>  Conditional Model 
#> 
#>  Raw formula: 
#> vit_d ~ X:main_rrr1 + X:main_sss1 
#> 
#>  Raw Coefficients: 
#>              Estimate
#> (Intercept)  30.32687
#> X0:main_rrr1  0.86520
#> X1:main_rrr1  6.47625
#> X0:main_sss1  6.24438
#> X1:main_sss1  4.66701
#> 
#>  Transformed Coefficients: 
#>             Estimate
#> (Intercept) 30.32687
#> [X=0]:amp    6.30404
#> [X=1]:amp    7.98266
#> [X=0]:acr    1.43312
#> [X=1]:acr    0.62444

# 2-component cosinor model with simulated data
sim_data <- simulate_cosinor(
  n = 500,
  mesor = 5,
  amp = c(2, 1),
  acro = c(1, 1.5),
  beta.mesor = 2,
  beta.amp = c(2, 1),
  beta.acro = c(1, 1.5),
  family = "gaussian",
  period = c(12, 6),
  n_components = 2,
  beta.group = TRUE,
)

cglmm(
  Y ~ group + amp_acro(times,
    n_components = 2,
    group = "group",
    period = c(12, 6)
  ),
  data = sim_data,
  family = gaussian
)
#> 
#>  Conditional Model 
#> 
#>  Raw formula: 
#> Y ~ group + group:main_rrr1 + group:main_sss1 + group:main_rrr2 +      group:main_sss2 
#> 
#>  Raw Coefficients: 
#>                  Estimate
#> (Intercept)       5.03185
#> group1           -3.00230
#> group0:main_rrr1  1.02654
#> group1:main_rrr1  1.00849
#> group0:main_sss1  1.71098
#> group1:main_sss1  1.65878
#> group0:main_rrr2 -0.00458
#> group1:main_rrr2  0.11368
#> group0:main_sss2  1.01718
#> group1:main_sss2  0.91571
#> 
#>  Transformed Coefficients: 
#>                Estimate
#> (Intercept)     5.03185
#> [group=1]      -3.00230
#> [group=0]:amp1  1.99531
#> [group=1]:amp1  1.94129
#> [group=0]:amp2  1.01719
#> [group=1]:amp2  0.92274
#> [group=0]:acr1  1.03040
#> [group=1]:acr1  1.02454
#> [group=0]:acr2  1.57530
#> [group=1]:acr2  1.44729