Title: | Extract Circadian Rhythms Metrics from Actigraphy Data |
---|---|
Description: | Circadian rhythms are rhythms that oscillate about every 24 h, which has been observed in multiple physiological processes including core body temperature, hormone secretion, heart rate, blood pressure, and many others. Measuring circadian rhythm with wearables is based on a principle that there is increased movement during wake periods and reduced movement during sleep periods, and has been shown to be reliable and valid. This package can be used to extract nonparametric circadian metrics like intradaily variability (IV), interdaily stability (IS), and relative amplitude (RA); and parametric cosinor model and extended cosinor model coefficient. Details can be found in Junrui Di et al (2019) <doi:10.1007/s12561-019-09236-4>. |
Authors: | Junrui Di [aut, cre], Vadim zipunnikov [aut], Vincent van Hees [ctb] |
Maintainer: | Junrui Di <[email protected]> |
License: | GPL-3 |
Version: | 0.3.0 |
Built: | 2025-02-02 03:25:23 UTC |
Source: | https://github.com/junruidi/actcr |
A parametric approach to study circadian rhythmicity assuming cosinor shape.
ActCosinor(x, window = 1, export_ts = FALSE)
ActCosinor(x, window = 1, export_ts = FALSE)
x |
|
window |
The calculation needs the window size of the data. E.g window = 1 means each epoch is in one-minute window. |
export_ts |
A Boolean to indicate whether time series should be exported |
A list with elements
mes |
MESOR which is short for midline statistics of rhythm, which is a rhythm adjusted mean. This represents mean activity level. |
amp |
amplitude, a measure of half the extend of predictable variation within a cycle. This represents the highest activity one can achieve. |
acro |
acrophase, a meaure of the time of the overall high values recurring in each cycle. Here it has a unit of radian. This represents time to reach the peak. |
acrotime |
acrophase in the unit of the time (hours) |
ndays |
Number of days modeled |
cosinor_ts |
Exported data frame with time, time over days, original time series, fitted time series using cosinor model |
Cornelissen, G. Cosinor-based rhythmometry. Theor Biol Med Model 11, 16 (2014). https://doi.org/10.1186/1742-4682-11-16
count1 = c(t(example_activity_data$count[c(1:2),-c(1,2)])) cos_coeff = ActCosinor(x = count1, window = 1, export_ts = TRUE)
count1 = c(t(example_activity_data$count[c(1:2),-c(1,2)])) cos_coeff = ActCosinor(x = count1, window = 1, export_ts = TRUE)
A parametric approach to study circadian rhythmicity assuming cosinor shape.This function is a whole dataset
wrapper for ActCosinor
.
ActCosinor_long(count.data, window = 1, export_ts = FALSE)
ActCosinor_long(count.data, window = 1, export_ts = FALSE)
count.data |
|
window |
The calculation needs the window size of the data. E.g window = 1 means each epoch is in one-minute window. |
export_ts |
A Boolean to indicate whether time series should be exported (notice: it takes time and storage space to export time series data for all subject-days. Use this with caution. Suggest to only export time series for selected subjects) |
A data.frame
with the following 5 columns
ID |
ID |
ndays |
number of days |
mes |
MESRO, which is short for midline statistics of rhythm, which is a rhythm adjusted mean. This represents mean activity level. |
amp |
amplitude, a measure of half the extend of predictable variation within a cycle. This represents the highest activity one can achieve. |
acro |
acrophase, a meaure of the time of the overall high values recurring in each cycle. Here it has a unit of radian. This represents time to reach the peak. |
acrotime |
acrophase in the unit of the time (hours) |
ndays |
Number of days modeled |
and
cosinor_ts |
Exported data frame with time, time over days, original time series, fitted time series using cosinor model |
counts_1 = example_activity_data$count[c(1:12),] cos_all_1 = ActCosinor_long(count.data = counts_1, window = 1,export_ts = TRUE) counts_10 = cbind(counts_1[,1:2], as.data.frame(t(apply(counts_1[,-c(1:2)], 1, FUN = bin_data, window = 10, method = "average")))) cos_all_10 = ActCosinor_long(count.data = counts_10, window = 10)
counts_1 = example_activity_data$count[c(1:12),] cos_all_1 = ActCosinor_long(count.data = counts_1, window = 1,export_ts = TRUE) counts_10 = cbind(counts_1[,1:2], as.data.frame(t(apply(counts_1[,-c(1:2)], 1, FUN = bin_data, window = 10, method = "average")))) cos_all_10 = ActCosinor_long(count.data = counts_10, window = 10)
Extended cosinor model based on sigmoidally transformed cosine curve using anti-logistic transformation
ActExtendCosinor( x, window = 1, lower = c(0, 0, -1, 0, -3), upper = c(Inf, Inf, 1, Inf, 27), export_ts = FALSE )
ActExtendCosinor( x, window = 1, lower = c(0, 0, -1, 0, -3), upper = c(Inf, Inf, 1, Inf, 27), export_ts = FALSE )
x |
|
window |
The calculation needs the window size of the data. E.g window = 1 means each epoch is in one-minute window. |
lower |
A numeric vector of lower bounds on each of the five parameters (in the order of minimum, amplitude, alpha, beta, acrophase) for the NLS. If not given, the default lower bound for each parameter is set to |
upper |
A numeric vector of upper bounds on each of the five parameters (in the order of minimum, amplitude, alpha, beta, acrophase) for the NLS. If not given, the default lower bound for each parameter is set to |
export_ts |
A Boolean to indicate whether time series should be exported |
A list with elements
minimum |
Minimum value of the of the function. |
amp |
amplitude, a measure of half the extend of predictable variation within a cycle. This represents the highest activity one can achieve. |
alpha |
It determines whether the peaks of the curve are wider than the troughs: when alpha is small, the troughs are narrow and the peaks are wide; when alpha is large, the troughs are wide and the peaks are narrow. |
beta |
It dertermines whether the transformed function rises and falls more steeply than the cosine curve: large values of beta produce curves that are nearly square waves. |
acrotime |
acrophase is the time of day of the peak in the unit of the time (hours) |
F_pseudo |
Measure the improvement of the fit obtained by the non-linear estimation of the transformed cosine model |
UpMesor |
Time of day of switch from low to high activity. Represents the timing of the rest- activity rhythm. Lower (earlier) values indicate increase in activity earlier in the day and suggest a more advanced circadian phase. |
DownMesor |
Time of day of switch from high to low activity. Represents the timing of the rest-activity rhythm. Lower (earlier) values indicate decline in activity earlier in the day, suggesting a more advanced circadian phase. |
MESOR |
A measure analogous to the MESOR of the cosine model (or half the deflection of the curve) can be obtained from mes=min+amp/2. However, it goes through the middle of the peak, and is therefore not equal to the MESOR of the cosine model, which is the mean of the data. |
ndays |
Number of days modeled. |
cosinor_ts |
Exported data frame with time, time over days, original time series, fitted time series using cosinor model from step 1, and fitted extended cosinor model from step 2 |
Marler MR, Gehrman P, Martin JL, Ancoli-Israel S. The sigmoidally transformed cosine curve: a mathematical model for circadian rhythms with symmetric non-sinusoidal shapes. Stat Med.
count1 = c(t(example_activity_data$count[c(1:2),-c(1,2)])) cos_coeff = ActExtendCosinor(x = count1, window = 1,export_ts = TRUE)
count1 = c(t(example_activity_data$count[c(1:2),-c(1,2)])) cos_coeff = ActExtendCosinor(x = count1, window = 1,export_ts = TRUE)
Extended cosinor model based on sigmoidally transformed cosine curve using anti-logistic transformation.This function is a whole dataset
wrapper for ActExtendCosinor
.
ActExtendCosinor_long( count.data, window = 1, lower = c(0, 0, -1, 0, -3), upper = c(Inf, Inf, 1, Inf, 27), export_ts = FALSE )
ActExtendCosinor_long( count.data, window = 1, lower = c(0, 0, -1, 0, -3), upper = c(Inf, Inf, 1, Inf, 27), export_ts = FALSE )
count.data |
|
window |
The calculation needs the window size of the data. E.g window = 1 means each epoch is in one-minute window. window size as an argument. |
lower |
A numeric vector of lower bounds on each of the five parameters (in the order of minimum, amplitude, alpha, beta, acrophase) for the NLS. If not given, the default lower bound for each parameter is set to |
upper |
A numeric vector of upper bounds on each of the five parameters (in the order of minimum, amplitude, alpha, beta, acrophase) for the NLS. If not given, the default lower bound for each parameter is set to |
export_ts |
A Boolean to indicate whether time series should be exported (notice: it takes time and storage space to export time series data for all subject-days. Use this with caution. Suggest to only export time series for selected subjects) |
A data.frame
with the following 11 columns
ID |
ID |
ndays |
number of days |
minimum |
Minimum value of the of the function. |
amp |
amplitude, a measure of half the extend of predictable variation within a cycle. This represents the highest activity one can achieve. |
alpha |
It determines whether the peaks of the curve are wider than the troughs: when alpha is small, the troughs are narrow and the peaks are wide; when alpha is large, the troughs are wide and the peaks are narrow. |
beta |
It dertermines whether the transformed function rises and falls more steeply than the cosine curve: large values of beta produce curves that are nearly square waves. |
acrotime |
acrophase is the time of day of the peak in the unit of the time (hours) |
F_pseudo |
Measure the improvement of the fit obtained by the non-linear estimation of the transformed cosine model |
UpMesor |
Time of day of switch from low to high activity. Represents the timing of the rest- activity rhythm. Lower (earlier) values indicate increase in activity earlier in the day and suggest a more advanced circadian phase. |
DownMesor |
Time of day of switch from high to low activity. Represents the timing of the rest-activity rhythm. Lower (earlier) values indicate decline in activity earlier in the day, suggesting a more advanced circadian phase. |
MESOR |
A measure analogous to the MESOR of the cosine model (or half the deflection of the curve) can be obtained from mes=min+amp/2. However, it goes through the middle of the peak, and is therefore not equal to the MESOR of the cosine model, which is the mean of the data. |
cosinor_ts |
Exported data frame with time, time over days, original time series, fitted time series using cosinor model from step 1, and fitted extended cosinor model from step 2 |
counts_1 = example_activity_data$count[c(1:12),] cos_all_1 = ActExtendCosinor_long(count.data = counts_1, window = 1, export_ts = TRUE) counts_10 = cbind(counts_1[,1:2], as.data.frame(t(apply(counts_1[,-c(1:2)], 1, FUN = bin_data, window = 10, method = "average")))) cos_all_10 = ActExtendCosinor_long(count.data = counts_10, window = 10, export_ts = FALSE)
counts_1 = example_activity_data$count[c(1:12),] cos_all_1 = ActExtendCosinor_long(count.data = counts_1, window = 1, export_ts = TRUE) counts_10 = cbind(counts_1[,1:2], as.data.frame(t(apply(counts_1[,-c(1:2)], 1, FUN = bin_data, window = 10, method = "average")))) cos_all_10 = ActExtendCosinor_long(count.data = counts_10, window = 10, export_ts = FALSE)
Bin minute level data into different time resolutions
bin_data(x = x, window = 1, method = c("average", "sum"))
bin_data(x = x, window = 1, method = c("average", "sum"))
x |
|
window |
window size used to bin the original 1440 dimensional data into. Window size should be an integer factor of 1440 |
method |
|
a vector of binned data
data(example_activity_data) count1 = c(t(example_activity_data$count[1,-c(1,2)])) xbin = bin_data(x = count1, window = 10, method = "average")
data(example_activity_data) count1 = c(t(example_activity_data$count[1,-c(1,2)])) xbin = bin_data(x = count1, window = 10, method = "average")
A list of two data.frames
containing the counts and the weartime
for 50 NHANES subjects
example_activity_data
example_activity_data
A list of two data.frame
s with 1442 columns, which are in the following order:
identifier of the person.
numeric
sequence 1,2,.. indicating the order of days within a subject.
counts of activity of that specific minute.
This function calcualte interdaily stability, a nonparametric metric of circadian rhtymicity
IS(x)
IS(x)
x |
|
Junrui Di et al. Joint and individual representation of domains of physical activity, sleep, and circadian rhythmicity. Statistics in Biosciences.
data(example_activity_data) count1 = example_activity_data$count[c(1,2,3),-c(1,2)] is = IS(x = count1)
data(example_activity_data) count1 = example_activity_data$count[c(1,2,3),-c(1,2)] is = IS(x = count1)
This function calcualte interdaily stability, a nonparametric metric
of circadian rhtymicity. This function is a whole dataset
wrapper for IS
IS_long(count.data, window = 1, method = c("average", "sum"))
IS_long(count.data, window = 1, method = c("average", "sum"))
count.data |
|
window |
an |
method |
|
A data.frame
with the following 2 columns
ID |
ID |
IS |
IS |
Junrui Di et al. Joint and individual representation of domains of physical activity, sleep, and circadian rhythmicity. Statistics in Biosciences.
data(example_activity_data) count1 = example_activity_data$count is_subj = IS_long(count.data = count1, window = 10, method = "average")
data(example_activity_data) count1 = example_activity_data$count is_subj = IS_long(count.data = count1, window = 10, method = "average")
This function calcualte intradaily variability, a nonparametric metric reprsenting fragmentation of circadian rhtymicity
IV(x)
IV(x)
x |
|
IV
Junrui Di et al. Joint and individual representation of domains of physical activity, sleep, and circadian rhythmicity. Statistics in Biosciences.
data(example_activity_data) count1 = c(t(example_activity_data$count[1,-c(1,2)])) iv = IV(x = count1)
data(example_activity_data) count1 = c(t(example_activity_data$count[1,-c(1,2)])) iv = IV(x = count1)
This function calcualte intradaily variability, a nonparametric metric
reprsenting fragmentation of circadian rhtymicity. This function is a whole dataset
wrapper for IV
.
IV_long(count.data, window = 1, method = c("average", "sum"))
IV_long(count.data, window = 1, method = c("average", "sum"))
count.data |
|
window |
an |
method |
|
A data.frame
with the following 5 columns
ID |
ID |
Day |
Day |
IV |
IV |
Junrui Di et al. Joint and individual representation of domains of physical activity, sleep, and circadian rhythmicity. Statistics in Biosciences.
data(example_activity_data) count1 = example_activity_data$count iv_subj = IV_long(count.data = count1, window = 10, method = "average")
data(example_activity_data) count1 = example_activity_data$count iv_subj = IV_long(count.data = count1, window = 10, method = "average")
This function calcualte relative amplitude, a nonparametric metric reprsenting fragmentation of circadian rhtymicity
RA(x, window = 1, method = c("average", "sum"))
RA(x, window = 1, method = c("average", "sum"))
x |
|
window |
since the caculation of M10 and L5 depends on the dimension of data, we need to include window size as an argument. |
method |
|
A list with elements
M10 |
Maximum 10 hour activity |
L5 |
Minimum 5 hour activity |
RA |
Relative amplitude |
Junrui Di et al. Joint and individual representation of domains of physical activity, sleep, and circadian rhythmicity. Statistics in Biosciences.
data(example_activity_data) count1 = c(t(example_activity_data$count[1,-c(1,2)])) ra = RA(x = count1, window = 10, method = "average")
data(example_activity_data) count1 = c(t(example_activity_data$count[1,-c(1,2)])) ra = RA(x = count1, window = 10, method = "average")
This function calcualte relative amplitude, a nonparametric metric
of circadian rhtymicity. This function is a whole dataset
wrapper for RA
.
RA_long(count.data, window = 1, method = c("average", "sum"))
RA_long(count.data, window = 1, method = c("average", "sum"))
count.data |
|
window |
since the caculation of M10 and L5 depends on the dimension of data, we need to include
window size as an argument. This function is a whole dataset
wrapper for |
method |
|
A data.frame
with the following 3 columns
ID |
ID |
Day |
Day |
RA |
RA |
data(example_activity_data) count1 = example_activity_data$count[1:12,] ra_all = RA_long(count.data = count1, window = 10, method = "average")
data(example_activity_data) count1 = example_activity_data$count[1:12,] ra_all = RA_long(count.data = count1, window = 10, method = "average")