
Fit the cosinor GLMM model using the output from
update_formula_and_data()
and a new formula
Source: R/data_processor.R
fit_model_and_process.Rd
Fit the cosinor GLMM model using the output from
update_formula_and_data()
and a new formula
Arguments
- obj
Output from
update_formula_and_data()
.- formula
A (optionally) new formula to use when fitting the cosinor model (maybe with random effects) or other covariates found in the data.
- ...
Optional additional arguments passed to
glmmTMB::glmmTMB()
.
Examples
# Use vitamind data but add a "patient" identifier used as a random effect
vitamind2 <- vitamind
vitamind2$patient <- sample(
LETTERS[1:5],
size = nrow(vitamind2), replace = TRUE
)
# Use update_formula_and_data() to perform wrangling steps of cglmm()
# without yet fitting the model
data_and_formula <- update_formula_and_data(
data = vitamind2,
formula = vit_d ~ X + amp_acro(time,
group = "X",
period = 12
)
)
# print formula from above
data_and_formula$newformula
#> vit_d ~ X + X:main_rrr1 + X:main_sss1
#> <environment: 0x55f4b857c560>
# fit model while adding random effect to cosinor model formula.
mod <- fit_model_and_process(
obj = data_and_formula,
formula = update.formula(
data_and_formula$newformula, . ~ . + (1 | patient)
)
)
mod
#>
#> Conditional Model
#>
#> Raw formula:
#> vit_d ~ X + (1 | patient) + X:main_rrr1 + X:main_sss1
#>
#> Raw Coefficients:
#> Estimate
#> (Intercept) 29.68170
#> X1 1.92255
#> X0:main_rrr1 0.86482
#> X1:main_rrr1 6.47469
#> X0:main_sss1 6.17013
#> X1:main_sss1 4.76343
#>
#> Transformed Coefficients:
#> Estimate
#> (Intercept) 29.68170
#> [X=1] 1.92255
#> [X=0]:amp 6.23044
#> [X=1]:amp 8.03815
#> [X=0]:acr 1.43154
#> [X=1]:acr 0.63429
mod$fit # printing the `glmmTMB` model within shows Std.Dev. of random effect
#> Formula: vit_d ~ X + (1 | patient) + X:main_rrr1 + X:main_sss1
#> Data: newdata
#> AIC BIC logLik df.resid
#> 1247.7872 1274.1737 -615.8936 192
#> Random-effects (co)variances:
#>
#> Conditional model:
#> Groups Name Std.Dev.
#> patient (Intercept) 0.5016
#> Residual 5.2416
#>
#> Number of obs: 200 / Conditional model: patient, 5
#>
#> Dispersion estimate for gaussian family (sigma^2): 27.5
#>
#> Fixed Effects:
#>
#> Conditional model:
#> (Intercept) X1 X0:main_rrr1 X1:main_rrr1 X0:main_sss1
#> 29.6817 1.9225 0.8648 6.4747 6.1701
#> X1:main_sss1
#> 4.7634