cosinor

knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

The function cosinor() is built off of literature supporting the analysis of circadian rhythms. There are two other packages on CRAN that provide cosinor analyses that are very good, cosinor and cosinor2. This package was built for 1) learning about regression and model development, and 2) the raw material generated to allow for more expansive and experimental analysis of cosinor functions and circadian rhythms.

library(card)

# Using the provide dataset
data("twins")
head(twins)

The twins dataset contains clinical covariates and continuous time measures, such as heart rate variability at each hour of the day. These continuous measures follow a circadian pattern.

library(ggplot2)
ggplot(twins, aes(x = hour, y = rDYX)) +
  geom_smooth(method = "gam")

Cosinor analysis can be used to generate model statistics. Confidence intervals of the amplitude and acrophase can be generated. It is based of the hardhat package.

The model can return information about an individual cosinor. The model statistics can be extracted, as well as visualized.

# Model
m <- cosinor(rDYX ~ hour, data = twins, tau = 24)

# Summary
summary(m)

# Plot
ggcosinor(m, labels = TRUE)

More complex models can also be made using multiple components, which is represented by additional, user-defined periods.

# Model
m <- cosinor(rDYX ~ hour, data = twins, tau = c(24, 12))

# Summary
summary(m)

# Plot
ggcosinor(m, labels = TRUE)

And, these models can be repeated for an entire population if warranted.

# Model
m <- cosinor(rDYX ~ hour, data = twins, tau = c(24), population = "patid")

# Summary
summary(m)


Try the card package in your browser

Any scripts or data that you put into this service are public.

card documentation built on Sept. 3, 2020, 9:07 a.m.