Type: | Package |
Title: | Tools for Estimating and Predicting the Cosinor Model |
Version: | 1.2.3 |
Date: | 2023-03-19 |
Author: | Michael Sachs <sachsmc@gmail.com> |
Maintainer: | Michael Sachs <sachsmc@gmail.com> |
Description: | A set of simple functions that transforms longitudinal data to estimate the cosinor linear model as described in Tong (1976). Methods are given to summarize the mean, amplitude and acrophase, to predict the mean annual outcome value, and to test the coefficients. |
URL: | https://github.com/sachsmc/cosinor |
Depends: | R (≥ 2.11.0) |
Imports: | ggplot2, shiny |
Suggests: | knitr |
License: | MIT + file LICENSE |
LazyData: | true |
VignetteBuilder: | knitr |
RoxygenNote: | 7.2.1 |
NeedsCompilation: | no |
Packaged: | 2023-03-21 07:55:13 UTC; sachsmc |
Repository: | CRAN |
Date/Publication: | 2023-03-21 08:20:02 UTC |
Fit cosinor model
Description
Given an outcome and time variable, fit the cosinor model with optional covariate effects.
Usage
cosinor.lm(formula, period = 12, data, na.action = na.omit)
Arguments
formula |
Formula specifying the model. Indicate the time variable with
|
period |
Length of time for a complete period of the sine curve. |
data |
Data frame where variable can be found |
na.action |
What to do with missing data |
Details
This defines special functions that are used in the formula to
indicate the time variable and which covariates effect the amplitude. To
indicate the time variable wrap the name of it in the function
time()
. To indicate a variable which affects the
acrophase/amplitude, wrap the name in amp.acro()
. This will then do
all the transformations for you. See examples for usage.
References
Tong, YL. Parameter Estimation in Studying Circadian Rhythms, Biometrics (1976). 32(1):85–94.
Examples
cosinor.lm(Y ~ time(time) + X + amp.acro(X), data = vitamind)
Fit cosinor model
Description
Given an outcome and time variable, fit the cosinor model with optional covariate effects.
Usage
cosinor.lm.default(formula, ...)
Arguments
formula |
Forumla specifying the model. Indicate the time variable with |
... |
other arguments |
Details
This defines special functions that are used in the formula to indicate the time variable
and which covariates effect the amplitude. To indicate the time variable wrap the name of it in the function
time()
. To indicate a variable which affects the acrophase/amplitude, wrap the name in
amp.acro()
. This will then do all the transformations for you. See examples for usage.
Examples
cosinor.lm(Y ~ time(time) + X + amp.acro(X), data = vitamind)
Shiny application to demonstrate cosinor fit
Description
Given a dataset, specify the outcome, time variable, and optional covariates. The app will then perform a cosinor analysis and plot the results.
Usage
cosinor_analyzer(data = NULL)
Arguments
data |
Data frame to analyze |
Examples
## Not run:
library(shiny)
cosinor_analyzer(vitamind)
## End(Not run)
Extract variable names from terms object, handling specials
Description
Extract variable names from terms object, handling specials
Usage
get_varnames(Terms)
Arguments
Terms |
a terms object |
Plot a cosinor model
Description
Given a cosinor.lm model fit, generate a plot of the data with the fitted values. Optionally allows for plotting by covariate levels 0 and 1.
Usage
ggplot_cosinor.lm(object, x_str = NULL)
Arguments
object |
An object of class |
x_str |
Character vector naming the covariate(s) to be plotted. May be NULL to plot overall curve |
Examples
fit <- cosinor.lm(Y ~ time(time) + X + amp.acro(X), data = vitamind)
ggplot_cosinor.lm(fit, "X")
Predict from a cosinor model
Description
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
Usage
## S3 method for class 'cosinor.lm'
predict(object, newdata, ...)
Arguments
object |
An object of class |
newdata |
Optional new data |
... |
other arguments |
Examples
fit <- cosinor.lm(Y ~ time(time) + X + amp.acro(X), data = vitamind)
predict(fit)
Print cosinor model
Description
Given an outcome and time variable, fit the cosinor model with optional covariate effects.
Usage
## S3 method for class 'cosinor.lm'
print(x, ...)
Arguments
x |
cosinor.lm object |
... |
passed to summary |
Print the summary of a cosinor model
Description
Print the summary of a cosinor model
Usage
## S3 method for class 'summary.cosinor.lm'
print(x, ...)
Arguments
x |
An object of class |
... |
Currently unused |
Examples
fit <- cosinor.lm(Y ~ time(time) + X + amp.acro(X), data = vitamind)
summary(fit)
Print test of model
Description
Print test of model
Usage
## S3 method for class 'test'
print(x)
Arguments
x |
test object |
Print results of test of cosinor model
Description
Print results of test of cosinor model
Usage
## S3 method for class 'test_cosinor'
print(x, ...)
Arguments
x |
test_cosinor object |
... |
Arguments passed to |
Simulate data from a cosinor model
Description
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.
Usage
simulate_cosinor(n, beta.mean = 2, beta.amp = 0, beta.acro = 0)
Arguments
n |
Sample size |
beta.mean |
Effect on the mean (intercept) |
beta.amp |
Effect on the amplitude |
beta.acro |
Effect on the acrophase |
Summarize a cosinor model
Description
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.
Usage
## S3 method for class 'cosinor.lm'
summary(object, ...)
Arguments
object |
An object of class |
... |
Currently unused |
Examples
fit <- cosinor.lm(Y ~ time(time) + X + amp.acro(X), data = vitamind)
summary(fit)
Test for differences in a cosinor model
Description
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.
Usage
test_cosinor(object, x_str, param = "amp")
Arguments
object |
An object of class |
x_str |
Character naming the covariate whose amplitude/acrophase will be tested |
param |
Character string naming the parameter to test, either "amp" for amplitude or "acr" for acrophase |
Examples
fit <- cosinor.lm(Y ~ time(time) + X + amp.acro(X), data = vitamind)
test_cosinor(fit, "X", "amp")
Replace covariate names with descriptive text
Description
Replace covariate names with descriptive text
Usage
update_covnames(names)
Arguments
names |
Coefficient names to update |
Vitamin D
Description
Simulated data set to illustrate the cosinor model. Y
is an outcome variable that varies of time time
according
to a cosine curve. The binary covariate X
is associated with the
mean and amplitude of the cosine curve.
Usage
vitamind
Format
A data frame with 3 variables: X
, Y
,
time
.