Title: | Fit a Cosinor Model Using a Generalised Mixed Modelling Framework |
---|---|
Description: | Allows users to fit a cosinor model using the 'glmmTMB' framework. This extends on existing cosinor modelling packages, including 'cosinor' and 'circacompare', by including a wide range of available link functions and the capability to fit mixed models. The cosinor model is described by Cornelissen (2014) <doi:10.1186/1742-4682-11-16>. |
Authors: | Rex Parsons [aut, cre] |
Maintainer: | Rex Parsons <[email protected]> |
License: | GPL (>= 3) |
Version: | 0.2.0.9000 |
Built: | 2024-08-19 06:38:20 UTC |
Source: | https://github.com/ropensci/GLMMcosinor |
Checks the validity of user inputs before creating an updated formula
and associated modifications to the data.frame
.
amp_acro(time_col, n_components = 1, group, period, ...)
amp_acro(time_col, n_components = 1, group, period, ...)
time_col |
A |
n_components |
The Number of cosinor components in the model. |
group |
A vector of the names for the group factors (column names
within the |
period |
A |
... |
Extra arguments for use within |
A data.frame
and formula
appropriate for use by
data_processor()
.
# Single component cosinor model cglmm( vit_d ~ amp_acro(time_col = time, group = "X", period = 12), data = vitamind ) # 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 )
# Single component cosinor model cglmm( vit_d ~ amp_acro(time_col = time, group = "X", period = 12), data = vitamind ) # 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 )
Given a cglmm model fit, generate a plot of the data with the fitted values. Optionally allows for plotting by covariates
## S3 method for class 'cglmm' autoplot( object, ci_level = 0.95, x_str, type = "response", xlims, pred.length.out, points_per_min_cycle_length = 20, superimpose.data = FALSE, data_opacity = 0.3, predict.ribbon = TRUE, ranef_plot = NULL, cov_list = NULL, quietly = TRUE, ... )
## S3 method for class 'cglmm' autoplot( object, ci_level = 0.95, x_str, type = "response", xlims, pred.length.out, points_per_min_cycle_length = 20, superimpose.data = FALSE, data_opacity = 0.3, predict.ribbon = TRUE, ranef_plot = NULL, cov_list = NULL, quietly = TRUE, ... )
object |
An |
ci_level |
The level for calculated confidence intervals. Defaults to
|
x_str |
A |
type |
A |
xlims |
A vector of length two containing the limits for the x-axis. |
pred.length.out |
An integer value that specifies the number of
predicted data points. The larger the value, the more smooth the fitted line
will appear. If missing, uses |
points_per_min_cycle_length |
Used to determine the number of samples
to create plot if |
superimpose.data |
A |
data_opacity |
A number between 0 and 1 inclusive that controls the
opacity of the superimposed data. (Used as the |
predict.ribbon |
A |
ranef_plot |
Specify the random effects variables that you wish to plot. If not specified, only the fixed effects will be visualised. |
cov_list |
Specify the levels of the covariates that you wish to plot as
a list. For example, if you have two covariates: var1, and var 2, you could
fix the level to be plotted as such |
quietly |
A |
... |
Additional, ignored arguments. |
Returns a ggplot
object.
# A simple model model <- cglmm( vit_d ~ X + amp_acro(time, group = "X", period = 12), data = vitamind ) autoplot(model, x_str = "X") # Plotting a model with various covariates test_data <- vitamind[vitamind$X == 1, ] test_data$var1 <- sample(c("a", "b", "c"), size = nrow(test_data), replace = TRUE) test_data$var2 <- rnorm(n = nrow(test_data)) object <- cglmm( vit_d ~ amp_acro(time, period = 12) + var1 + var2, data = test_data ) autoplot(object, cov_list = list( var1 = "a", var2 = 1 ), superimpose.data = TRUE )
# A simple model model <- cglmm( vit_d ~ X + amp_acro(time, group = "X", period = 12), data = vitamind ) autoplot(model, x_str = "X") # Plotting a model with various covariates test_data <- vitamind[vitamind$X == 1, ] test_data$var1 <- sample(c("a", "b", "c"), size = nrow(test_data), replace = TRUE) test_data$var2 <- rnorm(n = nrow(test_data)) object <- cglmm( vit_d ~ amp_acro(time, period = 12) + var1 + var2, data = test_data ) autoplot(object, cov_list = list( var1 = "a", var2 = 1 ), superimpose.data = TRUE )
{glmmTMB}
Given an outcome and time variable, fit the cosinor model with optional covariate effects.
cglmm( formula, data, family = stats::gaussian(), quietly = TRUE, dispformula = ~1, ziformula = ~0, ... )
cglmm( formula, data, family = stats::gaussian(), quietly = TRUE, dispformula = ~1, ziformula = ~0, ... )
formula |
A |
data |
A |
family |
A |
quietly |
A |
dispformula |
A one-sided (i.e., no response variable) |
ziformula |
A one-sided (i.e., no response variable) |
... |
Optional additional arguments passed to |
Returns a fitted cosinor model as a cglmm
object.
Tong, YL. Parameter Estimation in Studying Circadian Rhythms, Biometrics (1976). 32(1):85–94.
# Single component cosinor model cglmm( vit_d ~ amp_acro(time_col = time, group = "X", period = 12), data = vitamind ) # 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 )
# Single component cosinor model cglmm( vit_d ~ amp_acro(time_col = time, group = "X", period = 12), data = vitamind ) # 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 )
Simulated data set to illustrate a mixed cosinor model. The Y
column
contains a simulated outcome variable that varies over the time variable
(times
). The subject
column is a grouping variable that can be
used as a random effect. The rhythm has a period of 24 hours. Data was
simulated using simulate_cosinor
.
cosinor_mixed
cosinor_mixed
A data.frame
with 3 variables: Y
, times
, and
subject
.
update_formula_and_data()
and a new formulaFit the cosinor GLMM model using the output from
update_formula_and_data()
and a new formula
fit_model_and_process(obj, formula, ...)
fit_model_and_process(obj, formula, ...)
obj |
Output from |
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 |
Returns a fitted cosinor model as a cglmm
object.
# 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 # 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 mod$fit # printing the `glmmTMB` model within shows Std.Dev. of random effect
# 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 # 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 mod$fit # printing the `glmmTMB` model within shows Std.Dev. of random effect
Generates a polar plot with elliptical confidence intervals
polar_plot( x, ci_level = 0.95, n_breaks = 5, component_index = NULL, grid_angle_segments = 8, radial_units = c("radians", "degrees", "period"), clockwise = FALSE, text_size = 3, text_opacity = 0.5, fill_colours, ellipse_opacity = 0.3, circle_linetype = "dotted", start = c("right", "left", "top", "bottom"), view = c("full", "zoom", "zoom_origin"), overlay_parameter_info = FALSE, quietly = TRUE, show_component_labels = TRUE, xlims, ylims, ... )
polar_plot( x, ci_level = 0.95, n_breaks = 5, component_index = NULL, grid_angle_segments = 8, radial_units = c("radians", "degrees", "period"), clockwise = FALSE, text_size = 3, text_opacity = 0.5, fill_colours, ellipse_opacity = 0.3, circle_linetype = "dotted", start = c("right", "left", "top", "bottom"), view = c("full", "zoom", "zoom_origin"), overlay_parameter_info = FALSE, quietly = TRUE, show_component_labels = TRUE, xlims, ylims, ... )
x |
An object of class |
ci_level |
The level for calculated confidence ellipses. Defaults to 0.95. |
n_breaks |
The number of concentric circles that will be plotted using
the |
component_index |
A number that corresponds to a particular component
from the |
grid_angle_segments |
An |
radial_units |
A
|
clockwise |
A |
text_size |
A number controlling the font size of the text labels. Defaults to 3. |
text_opacity |
A |
fill_colours |
A |
ellipse_opacity |
A |
circle_linetype |
A |
start |
A |
view |
A
|
overlay_parameter_info |
A |
quietly |
Analogous to verbose, this |
show_component_labels |
Logical argument, TRUE by default. When TRUE, the polar plots have labels corresponding to their components. |
xlims |
A vector of length two containing the limits for the x-axis. |
ylims |
A vector of length two containing the limits for the y-axis. |
... |
Additional, ignored arguments. |
Returns a ggplot
object.
data(vitamind) model <- cglmm( vit_d ~ X + amp_acro(time, group = "X", period = 12), data = vitamind ) polar_plot(model, radial_units = "period")
data(vitamind) model <- cglmm( vit_d ~ X + amp_acro(time, group = "X", period = 12), data = vitamind ) polar_plot(model, radial_units = "period")
Generates a polar plot with elliptical confidence intervals
## S3 method for class 'cglmm' polar_plot( x, ci_level = 0.95, n_breaks = 5, component_index = NULL, grid_angle_segments = 8, radial_units = c("radians", "degrees", "period"), clockwise = FALSE, text_size = 3.5, text_opacity = 1, fill_colours, ellipse_opacity = 0.3, circle_linetype = "dotted", start = c("right", "left", "top", "bottom"), view = c("full", "zoom", "zoom_origin"), overlay_parameter_info = FALSE, quietly = TRUE, show_component_labels = TRUE, xlims, ylims, ... )
## S3 method for class 'cglmm' polar_plot( x, ci_level = 0.95, n_breaks = 5, component_index = NULL, grid_angle_segments = 8, radial_units = c("radians", "degrees", "period"), clockwise = FALSE, text_size = 3.5, text_opacity = 1, fill_colours, ellipse_opacity = 0.3, circle_linetype = "dotted", start = c("right", "left", "top", "bottom"), view = c("full", "zoom", "zoom_origin"), overlay_parameter_info = FALSE, quietly = TRUE, show_component_labels = TRUE, xlims, ylims, ... )
x |
An object of class |
ci_level |
The level for calculated confidence ellipses. Defaults to 0.95. |
n_breaks |
The number of concentric circles that will be plotted using
the |
component_index |
A number that corresponds to a particular component
from the |
grid_angle_segments |
An |
radial_units |
A
|
clockwise |
A |
text_size |
A number controlling the font size of the text labels. Defaults to 3. |
text_opacity |
A |
fill_colours |
A |
ellipse_opacity |
A |
circle_linetype |
A |
start |
A |
view |
A
|
overlay_parameter_info |
A |
quietly |
Analogous to verbose, this |
show_component_labels |
Logical argument, TRUE by default. When TRUE, the polar plots have labels corresponding to their components. |
xlims |
A vector of length two containing the limits for the x-axis. |
ylims |
A vector of length two containing the limits for the y-axis. |
... |
Additional, ignored arguments. |
Returns a ggplot
object.
model <- cglmm( vit_d ~ X + amp_acro(time, group = "X", period = 12), data = vitamind ) polar_plot(model, radial_units = "period")
model <- cglmm( vit_d ~ X + amp_acro(time, group = "X", period = 12), data = vitamind ) polar_plot(model, radial_units = "period")
Given a time variable and optional covariates, generate predicted values from a cosinor fit. Default prediction is the mean value, optionally can predict at a given month
## S3 method for class 'cglmm' predict(object, newdata, ...)
## S3 method for class 'cglmm' predict(object, newdata, ...)
object |
An object of class |
newdata |
Optional new data. |
... |
other arguments passed to |
Returns predicted values from the cosinor model.
fit <- cglmm(vit_d ~ X + amp_acro(time, group = "X", n_components = 1, period = 12 ), data = vitamind) predict(fit)
fit <- cglmm(vit_d ~ X + amp_acro(time, group = "X", n_components = 1, period = 12 ), data = vitamind) predict(fit)
cglmm
model.Print a brief summary of the cglmm
model.
## S3 method for class 'cglmm' print(x, digits = getOption("digits"), ...)
## S3 method for class 'cglmm' print(x, digits = getOption("digits"), ...)
x |
A |
digits |
Controls the number of digits displayed in the summary output. |
... |
Additional, ignored arguments. |
print(x)
returns x
invisibly.
# Single component cosinor model cglmm( vit_d ~ amp_acro(time_col = time, group = "X", period = 12), data = vitamind )
# Single component cosinor model cglmm( vit_d ~ amp_acro(time_col = time, group = "X", period = 12), data = vitamind )
Print test of model
## S3 method for class 'cglmmSubTest' print(x, ...)
## S3 method for class 'cglmmSubTest' print(x, ...)
x |
A |
... |
Additional, ignored arguments. |
print(x)
returns x
invisibly.
data_2_component <- simulate_cosinor( n = 10000, mesor = 5, amp = c(2, 5), acro = c(0, pi), beta.mesor = 4, beta.amp = c(3, 4), beta.acro = c(0, pi / 2), family = "gaussian", n_components = 2, period = c(10, 12), beta.group = TRUE ) mod_2_component <- cglmm( Y ~ group + amp_acro(times, n_components = 2, group = "group", period = c(10, 12) ), data = data_2_component ) test_output <- test_cosinor_levels( mod_2_component, param = "amp", x_str = "group" ) print(test_output$global.test)
data_2_component <- simulate_cosinor( n = 10000, mesor = 5, amp = c(2, 5), acro = c(0, pi), beta.mesor = 4, beta.amp = c(3, 4), beta.acro = c(0, pi / 2), family = "gaussian", n_components = 2, period = c(10, 12), beta.group = TRUE ) mod_2_component <- cglmm( Y ~ group + amp_acro(times, n_components = 2, group = "group", period = c(10, 12) ), data = data_2_component ) test_output <- test_cosinor_levels( mod_2_component, param = "amp", x_str = "group" ) print(test_output$global.test)
Print the summary of a cosinor model
## S3 method for class 'cglmmSummary' print(x, digits = getOption("digits"), ...)
## S3 method for class 'cglmmSummary' print(x, digits = getOption("digits"), ...)
x |
An object of class |
digits |
Controls the number of digits displayed in the summary output |
... |
Currently unused |
print
returns x
invisibly.
fit <- cglmm(vit_d ~ X + amp_acro(time, group = "X", n_components = 1, period = 12 ), data = vitamind) summary(fit)
fit <- cglmm(vit_d ~ X + amp_acro(time, group = "X", n_components = 1, period = 12 ), data = vitamind) summary(fit)
Print results of test of cosinor model
## S3 method for class 'cglmmTest' print(x, ...)
## S3 method for class 'cglmmTest' print(x, ...)
x |
A |
... |
Arguments passed to |
print(x)
returns x
invisibly.
data_2_component <- simulate_cosinor( n = 10000, mesor = 5, amp = c(2, 5), acro = c(0, pi), beta.mesor = 4, beta.amp = c(3, 4), beta.acro = c(0, pi / 2), family = "gaussian", n_components = 2, period = c(10, 12), beta.group = TRUE ) mod_2_component <- cglmm( Y ~ group + amp_acro(times, n_components = 2, group = "group", period = c(10, 12) ), data = data_2_component ) test_cosinor_levels( mod_2_component, param = "amp", x_str = "group" )
data_2_component <- simulate_cosinor( n = 10000, mesor = 5, amp = c(2, 5), acro = c(0, pi), beta.mesor = 4, beta.amp = c(3, 4), beta.acro = c(0, pi / 2), family = "gaussian", n_components = 2, period = c(10, 12), beta.group = TRUE ) mod_2_component <- cglmm( Y ~ group + amp_acro(times, n_components = 2, group = "group", period = c(10, 12) ), data = data_2_component ) test_cosinor_levels( mod_2_component, param = "amp", x_str = "group" )
see ?glmmTMB::sigma
for more details.
## S3 method for class 'cglmm' sigma(object, ...)
## S3 method for class 'cglmm' sigma(object, ...)
object |
An object of class |
... |
(ignored; for method compatibility) |
a numeric
.
testdata_poisson <- simulate_cosinor(100, n_period = 2, mesor = 7, amp = c(0.1, 0.5), acro = c(1, 1), beta.mesor = 4.4, beta.amp = c(0.1, 0.46), beta.acro = c(0.5, -1.5), family = "poisson", period = c(12, 6), n_components = 2, beta.group = TRUE ) mod <- cosinor_model <- cglmm( Y ~ group + amp_acro(times, period = c(12, 6), n_components = 2, group = "group" ), data = testdata_poisson, family = glmmTMB::nbinom1() ) sigma(mod)
testdata_poisson <- simulate_cosinor(100, n_period = 2, mesor = 7, amp = c(0.1, 0.5), acro = c(1, 1), beta.mesor = 4.4, beta.amp = c(0.1, 0.46), beta.acro = c(0.5, -1.5), family = "poisson", period = c(12, 6), n_components = 2, beta.group = TRUE ) mod <- cosinor_model <- cglmm( Y ~ group + amp_acro(times, period = c(12, 6), n_components = 2, group = "group" ), data = testdata_poisson, family = glmmTMB::nbinom1() ) sigma(mod)
This function simulates data from a cosinor model with a single covariate, where the time scale is month, and optionally allows for single covariate effects on the mean, amplitude, and acrophase.
simulate_cosinor( n, mesor, amp, acro, period = 24, n_components, beta.group = FALSE, beta.mesor, beta.amp, beta.acro, n_period = 1, family = c("gaussian", "poisson", "binomial", "gamma"), ... )
simulate_cosinor( n, mesor, amp, acro, period = 24, n_components, beta.group = FALSE, beta.mesor, beta.amp, beta.acro, n_period = 1, family = c("gaussian", "poisson", "binomial", "gamma"), ... )
n |
The sample size. An |
mesor |
A |
amp |
A |
acro |
A |
period |
The period of the rhythm data (for |
n_components |
The number of components in the model.
This must match the length of the inputs for |
beta.group |
A |
beta.mesor |
A |
beta.amp |
A |
beta.acro |
A |
n_period |
A |
family |
A |
... |
Extra arguments, including |
Returns simulated data in a data.frame
.
simulate_cosinor( n = 100, mesor = 1, amp = 1, acro = 1, period = 24, family = "gaussian" )
simulate_cosinor( n = 100, mesor = 1, amp = 1, acro = 1, period = 24, family = "gaussian" )
Summarize a cosinor model Given a time variable and optional covariates, generate inference a cosinor fit. Gives estimates, confidence intervals, and tests for the raw parameters, and for the mean, amplitude, and acrophase parameters. If the model includes covariates, the function returns the estimates of the mean, amplitude, and acrophase for the group with covariates equal to 1 and equal to 0. This may not be the desired result for continuous covariates.
## S3 method for class 'cglmm' summary(object, ci_level = 0.95, ...)
## S3 method for class 'cglmm' summary(object, ci_level = 0.95, ...)
object |
An object of class |
ci_level |
The level for calculated confidence intervals. Defaults to 0.95. |
... |
Currently unused |
Returns a summary of the cglmm
model as
a cglmmSummary
object.
fit <- cglmm(vit_d ~ X + amp_acro(time, group = "X", n_components = 1, period = 12 ), data = vitamind) summary(fit)
fit <- cglmm(vit_d ~ X + amp_acro(time, group = "X", n_components = 1, period = 12 ), data = vitamind) summary(fit)
Given a time variable and optional covariates, generate inference a cosinor fit. For the covariate named (or vector of covariates), this function performs a Wald test comparing the group with covariates equal to 1 to the group with covariates equal to 0. This may not be the desired result for continuous covariates.
test_cosinor_components( x, x_str = NULL, param = "amp", comparison_A = 1, comparison_B = 2, level_index = 0, ci_level = 0.95 )
test_cosinor_components( x, x_str = NULL, param = "amp", comparison_A = 1, comparison_B = 2, level_index = 0, ci_level = 0.95 )
x |
An |
x_str |
A |
param |
A |
comparison_A |
An |
comparison_B |
An |
level_index |
An |
ci_level |
The level for calculated confidence intervals. Defaults to
|
Returns a test_cosinor
object.
data_2_component <- simulate_cosinor( n = 10000, mesor = 5, amp = c(2, 5), acro = c(0, pi), beta.mesor = 4, beta.amp = c(3, 4), beta.acro = c(0, pi / 2), family = "gaussian", n_components = 2, period = c(10, 12), beta.group = TRUE ) mod_2_component <- cglmm( Y ~ group + amp_acro(times, n_components = 2, group = "group", period = c(10, 12) ), data = data_2_component ) test_cosinor_components(mod_2_component, param = "amp", x_str = "group")
data_2_component <- simulate_cosinor( n = 10000, mesor = 5, amp = c(2, 5), acro = c(0, pi), beta.mesor = 4, beta.amp = c(3, 4), beta.acro = c(0, pi / 2), family = "gaussian", n_components = 2, period = c(10, 12), beta.group = TRUE ) mod_2_component <- cglmm( Y ~ group + amp_acro(times, n_components = 2, group = "group", period = c(10, 12) ), data = data_2_component ) test_cosinor_components(mod_2_component, param = "amp", x_str = "group")
Given a time variable and optional covariates, generate inference a cosinor fit. For the covariate named (or vector of covariates), this function performs a Wald test comparing the group with covariates equal to 1 to the group with covariates equal to 0. This may not be the desired result for continuous covariates.
test_cosinor_levels( x, x_str, param = "amp", comparison_A, comparison_B, component_index = 1, ci_level = 0.95 )
test_cosinor_levels( x, x_str, param = "amp", comparison_A, comparison_B, component_index = 1, ci_level = 0.95 )
x |
An |
x_str |
A |
param |
A |
comparison_A |
An |
comparison_B |
An |
component_index |
An |
ci_level |
The level for calculated confidence intervals. Defaults to
|
Returns a test_cosinor
object.
data_2_component <- simulate_cosinor( n = 10000, mesor = 5, amp = c(2, 5), acro = c(0, pi), beta.mesor = 4, beta.amp = c(3, 4), beta.acro = c(0, pi / 2), family = "gaussian", n_components = 2, period = c(10, 12), beta.group = TRUE ) mod_2_component <- cglmm( Y ~ group + amp_acro(times, n_components = 2, group = "group", period = c(10, 12) ), data = data_2_component ) test_cosinor_levels(mod_2_component, param = "amp", x_str = "group")
data_2_component <- simulate_cosinor( n = 10000, mesor = 5, amp = c(2, 5), acro = c(0, pi), beta.mesor = 4, beta.amp = c(3, 4), beta.acro = c(0, pi / 2), family = "gaussian", n_components = 2, period = c(10, 12), beta.group = TRUE ) mod_2_component <- cglmm( Y ~ group + amp_acro(times, n_components = 2, group = "group", period = c(10, 12) ), data = data_2_component ) test_cosinor_levels(mod_2_component, param = "amp", x_str = "group")
Update data and formula for fitting cglmm model
update_formula_and_data( data, formula, family = "gaussian", quietly = TRUE, dispformula = ~1, ziformula = ~0 )
update_formula_and_data( data, formula, family = "gaussian", quietly = TRUE, dispformula = ~1, ziformula = ~0 )
data |
input data for fitting cglmm model. |
formula |
model formula, specified by user including |
family |
the model family. |
quietly |
controls whether messages from amp_acro are displayed. TRUE by default |
dispformula |
The formula specifying the dispersion model |
ziformula |
The formula specifying the zero-inflation model |
Returns a list
.
# 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 # 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 mod$fit # printing the `glmmTMB` model within shows Std.Dev. of random effect
# 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 # 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 mod$fit # printing the `glmmTMB` model within shows Std.Dev. of random effect
Simulated data set to illustrate the cosinor model. The vit_d
column
contains the blood vitamin D levels which vary over time (time
).
The rhythm of the vitamind D fluctuations follows a cosine function and can
be modelled with a cosinor model. The X
column is a binary covariate
representing two groups of patients and is associated with the
characteristics of the rhythm. The rhythm has a period of about 12 hours.
vitamind
vitamind
A data.frame
with 3 variables: vit_d
, time
, and
X
.