Title: | Tools for Estimating and Predicting the Cosinor Model |
---|---|
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. |
Authors: | Michael Sachs <[email protected]> |
Maintainer: | Michael Sachs <[email protected]> |
License: | MIT + file LICENSE |
Version: | 1.2.3 |
Built: | 2024-11-21 06:40:39 UTC |
Source: | CRAN |
Given a dataset, specify the outcome, time variable, and optional covariates. The app will then perform a cosinor analysis and plot the results.
cosinor_analyzer(data = NULL)
cosinor_analyzer(data = NULL)
data |
Data frame to analyze |
## Not run: library(shiny) cosinor_analyzer(vitamind) ## End(Not run)
## Not run: library(shiny) cosinor_analyzer(vitamind) ## End(Not run)
Given an outcome and time variable, fit the cosinor model with optional covariate effects.
cosinor.lm(formula, period = 12, data, na.action = na.omit)
cosinor.lm(formula, period = 12, data, na.action = na.omit)
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 |
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.
Tong, YL. Parameter Estimation in Studying Circadian Rhythms, Biometrics (1976). 32(1):85–94.
cosinor.lm(Y ~ time(time) + X + amp.acro(X), data = vitamind)
cosinor.lm(Y ~ time(time) + X + amp.acro(X), data = vitamind)
Given an outcome and time variable, fit the cosinor model with optional covariate effects.
cosinor.lm.default(formula, ...)
cosinor.lm.default(formula, ...)
formula |
Forumla specifying the model. Indicate the time variable with |
... |
other arguments |
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.
cosinor.lm(Y ~ time(time) + X + amp.acro(X), data = vitamind)
cosinor.lm(Y ~ time(time) + X + amp.acro(X), data = vitamind)
Extract variable names from terms object, handling specials
get_varnames(Terms)
get_varnames(Terms)
Terms |
a terms object |
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.
ggplot_cosinor.lm(object, x_str = NULL)
ggplot_cosinor.lm(object, x_str = NULL)
object |
An object of class |
x_str |
Character vector naming the covariate(s) to be plotted. May be NULL to plot overall curve |
fit <- cosinor.lm(Y ~ time(time) + X + amp.acro(X), data = vitamind) ggplot_cosinor.lm(fit, "X")
fit <- cosinor.lm(Y ~ time(time) + X + amp.acro(X), data = vitamind) ggplot_cosinor.lm(fit, "X")
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 'cosinor.lm' predict(object, newdata, ...)
## S3 method for class 'cosinor.lm' predict(object, newdata, ...)
object |
An object of class |
newdata |
Optional new data |
... |
other arguments |
fit <- cosinor.lm(Y ~ time(time) + X + amp.acro(X), data = vitamind) predict(fit)
fit <- cosinor.lm(Y ~ time(time) + X + amp.acro(X), data = vitamind) predict(fit)
Given an outcome and time variable, fit the cosinor model with optional covariate effects.
## S3 method for class 'cosinor.lm' print(x, ...)
## S3 method for class 'cosinor.lm' print(x, ...)
x |
cosinor.lm object |
... |
passed to summary |
Print the summary of a cosinor model
## S3 method for class 'summary.cosinor.lm' print(x, ...)
## S3 method for class 'summary.cosinor.lm' print(x, ...)
x |
An object of class |
... |
Currently unused |
fit <- cosinor.lm(Y ~ time(time) + X + amp.acro(X), data = vitamind) summary(fit)
fit <- cosinor.lm(Y ~ time(time) + X + amp.acro(X), data = vitamind) summary(fit)
Print test of model
## S3 method for class 'test' print(x)
## S3 method for class 'test' print(x)
x |
test object |
Print results of test of cosinor model
## S3 method for class 'test_cosinor' print(x, ...)
## S3 method for class 'test_cosinor' print(x, ...)
x |
test_cosinor object |
... |
Arguments passed to |
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, beta.mean = 2, beta.amp = 0, beta.acro = 0)
simulate_cosinor(n, beta.mean = 2, beta.amp = 0, beta.acro = 0)
n |
Sample size |
beta.mean |
Effect on the mean (intercept) |
beta.amp |
Effect on the amplitude |
beta.acro |
Effect on the acrophase |
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 'cosinor.lm' summary(object, ...)
## S3 method for class 'cosinor.lm' summary(object, ...)
object |
An object of class |
... |
Currently unused |
fit <- cosinor.lm(Y ~ time(time) + X + amp.acro(X), data = vitamind) summary(fit)
fit <- cosinor.lm(Y ~ time(time) + X + amp.acro(X), 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(object, x_str, param = "amp")
test_cosinor(object, x_str, param = "amp")
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 |
fit <- cosinor.lm(Y ~ time(time) + X + amp.acro(X), data = vitamind) test_cosinor(fit, "X", "amp")
fit <- cosinor.lm(Y ~ time(time) + X + amp.acro(X), data = vitamind) test_cosinor(fit, "X", "amp")
Replace covariate names with descriptive text
update_covnames(names)
update_covnames(names)
names |
Coefficient names to update |
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.
vitamind
vitamind
A data frame with 3 variables: X
, Y
,
time
.