Title: | Extended Tools for Cosinor Analysis of Rhythms |
Description: | Statistical procedures for calculating population–mean cosinor, non–stationary cosinor, estimation of best–fitting period, tests of population rhythm differences and more. See Cornélissen, G. (2014). <doi:10.1186/1742-4682-11-16>. |
Version: | 0.2.1 |
Author: | Augustin Mutak <mutak94@gmail.com> |
Maintainer: | Augustin Mutak <mutak94@gmail.com> |
Depends: | R (≥ 2.10), cosinor (≥ 1.1) |
Imports: | cowplot (≥ 0.9.3), scales (≥ 1.0.0), magrittr (≥ 1.5), stringr (≥ 1.3.1), purrr(≥ 0.2.5), ggplot2 (≥ 3.0.0), matrixStats (≥ 0.52.2), Hmisc (≥ 4.0-3) |
License: | GPL-3 |
Encoding: | UTF-8 |
RoxygenNote: | 6.1.0 |
LazyData: | True |
URL: | https://github.com/amutak/cosinor2 |
BugReports: | https://github.com/amutak/cosinor2/issues |
NeedsCompilation: | no |
Repository: | CRAN |
Date: | 2018-10-01 |
Suggests: | knitr, rmarkdown |
VignetteBuilder: | knitr |
Packaged: | 2018-10-15 15:36:37 UTC; Augustin |
Date/Publication: | 2018-10-15 16:10:03 UTC |
Self-reported mood
Description
A dataset containing the responses of 19 subjects on the shortened version of the PANAS questionnaire (Watson, Clark & Tellegen, 1988) in November 2015.
Usage
PANAS_november
Format
A data frame with 19 rows and 30 variables:
- X01, X02, X03, X04, X05, X06, X07, X08, X09, X10, X11, X12, X13, X14, X15, X16, X17, X18, X19, X20, X21, X22, X23, X24, X25, X26, X27, X28, X29, X30
Responses of subjects at 30 measurement points (days).
Details
Measurements were taken every day after 8 PM.
Note
The data contained in this dataset has been reduced compared to the original data that included more subjects. This dataset contains only the subjects that have responded to the PANAS questionnaire on more than 85% of the timepoints in both of the research cycles (July and November).
Source
Mutak, A. i Vukasović Hlupić, T. (2017). Exogeneity of the Circaseptan Mood Rhythm and Its Relation to the Working Week. Review of Psychology, 24 (1-2), 15-28.
References
Watson, D., Clark, L. A. & Tellegen, A. (1988). Development and Validation of Brief Measures of Positive and Negative Affect: The PANAS Scales. Journal of Personality and Social Psychology, 54(6), 1063-1070.
Measurement times of self-reported mood
Description
A dataset containing the measurement times (dates) of self reported mood contained in the data frame PANAS_november
Usage
PANAS_time
Format
A numeric vector of length 30.
Source
Mutak, A. i Vukasović Hlupić, T. (2017). Exogeneity of the Circaseptan Mood Rhythm and Its Relation to the Working Week. Review of Psychology, 24 (1-2), 15-28.
Self-reported positive affect of extraverts
Description
A dataset containing the responses of 24 subjects on the Positive Affect scale of the shortened version of the PANAS questionnaire (Watson, Clark & Tellegen, 1988) in January 2017.
Usage
PA_extraverts
Format
A data frame with 24 rows and 6 variables:
- X1, X2, X3, X4, X5, X6
Responses of subjects at 6 measurement points (hours).
Details
Measurements were taken at 10 AM, 12 PM, 2 PM, 4 PM, 6 PM and 8 PM \pm
30 minutes in the period of January 16 - 22, 2017. The data contained in this dataset has been averaged for each hour across 7 days of measurement.
Source
Mutak, A., Pavlović, M. & Zibar, K. (2017, May). Postoje li razlike između introverata i ekstraverata u cirkadijurnim ritmovima raspoloženja? [Are There Differences Between Introverts and Extraverts in Circadian Mood Rhythms?]. Study presented at the 3rd Regionalni susret studenata psihologije - SPIRI [Regional Meeting of Psychology Students - SPIRI] conference, Rijeka, Croatia.
References
Watson, D., Clark, L. A. & Tellegen, A. (1988). Development and Validation of Brief Measures of Positive and Negative Affect: The PANAS Scales. Journal of Personality and Social Psychology, 54(6), 1063-1070.
Self-reported positive affect of introverts
Description
A dataset containing the responses of 29 subjects on the Positive Affect scale of the shortened version of the PANAS questionnaire (Watson, Clark & Tellegen, 1988) in January 2017.
Usage
PA_introverts
Format
A data frame with 29 rows and 6 variables:
- X1, X2, X3, X4, X5, X6
Responses of subjects at 6 measurement points (hours).
Details
Measurements were taken at 10 AM, 12 PM, 2 PM, 4 PM, 6 PM and 8 PM \pm
30 minutes in the period of January 16 - 22, 2017. The data contained in this dataset has been averaged for each hour across 7 days of measurement.
Source
Mutak, A., Pavlović, M. & Zibar, K. (2017, May). Postoje li razlike između introverata i ekstraverata u cirkadijurnim ritmovima raspoloženja? [Are There Differences Between Introverts and Extraverts in Circadian Mood Rhythms?]. Study presented at the 3rd Regionalni susret studenata psihologije - SPIRI [Regional Meeting of Psychology Students - SPIRI] conference, Rijeka, Croatia.
References
Watson, D., Clark, L. A. & Tellegen, A. (1988). Development and Validation of Brief Measures of Positive and Negative Affect: The PANAS Scales. Journal of Personality and Social Psychology, 54(6), 1063-1070.
Measurement times of self-reported positive affect
Description
A dataset containing the measurement times (hours) of self reported positive affect contained in the data frames PA_extravers
and PA_introverts
.
Usage
PA_time
Format
A numeric vector of length 6.
Source
Mutak, A., Pavlović, M. & Zibar, K. (2017, May). Postoje li razlike između introverata i ekstraverata u cirkadijurnim ritmovima raspoloženja? [Are There Differences Between Introverts and Extraverts in Circadian Mood Rhythms?]. Study presented at the 3rd Regionalni susret studenata psihologije - SPIRI [Regional Meeting of Psychology Students - SPIRI] conference, Rijeka, Croatia.
Acrophase Correction
Description
Corrects the value of the acrophase parameter of the cosinor model, placing it in the appropriate quadrant.
Usage
correct.acrophase(x)
Arguments
x |
An object of the |
Details
The acrophase parameter of a cosinor model is found by solving an equation with inverse tangent of an expression which contains linearized cosinor parameters. However, multiple numeric entities may result in a same value of tangent and just calculating the inverse tangent may result with the wrong value of the acrophase. This function corrects the acrophase from the cosinor.lm
object according to the procedure from Bingham et al. (1982).
More specifically, the acrophase is calculated as:
K + g * arctan \vert\frac{\gamma}{\beta}\vert
where values of K
and g
depend on the signs of \beta
and \gamma
and can be derived from the following table:
sign \beta | sign \gamma | K | g |
+ | + | 0 | -1 |
+ | - | -2\pi | 1 |
- | + | -\pi | 1 |
- | - | -\pi | -1 |
References
Bingham, C., Arbogast, B., Guillaume Cornélissen, G., Lee, J.K. & Halberg, F. (1982). Inferential Statistical Methods for Estimating and Comparing Cosinor Parameters. Chronobiologia, 9(4), 397-439.
Examples
fit.temperature<-cosinor.lm(Temperature~time(Time), period = 24, data = temperature_zg)
correct.acrophase(fit.temperature)
Percent Rhythm
Description
Calculates Percent Rhythm, the measure of the relative strength of a rhythm.
Usage
cosinor.PR(x)
Arguments
x |
An object of the |
Details
Percent Rhythm is the coefficient of determination obtained by squaring the correlation between observed and estimated values.
Examples
fit.temperature<-cosinor.lm(Temperature~time(Time), period = 24, data = temperature_zg)
cosinor.PR(fit.temperature)
fit.november<-population.cosinor.lm(data = PANAS_november, time = PANAS_time,
period = 7)
cosinor.PR(fit.november)
Rhythm Detection Test
Description
Performs the rhythm detection test, a global test for the significance of the estimated model for single cosinor and population-mean cosinor.
Usage
cosinor.detect(x)
Arguments
x |
An object of the |
Details
The rhythm detection test, also called the zero-amplitude test, tests the overall significance of the cosinor model. The test is actually an F-ratio and is calculated as following (according to the procedure described in Cornélissen, 2014):
F = \frac{\frac{\sum(\widehat{Y}_i - \bar{Y})^2}{2}}{\frac{\sum(Y_i - \bar{Y})^2}{N - 3}}
with df_1 = 2
and df_2 = N - 3
, where \widehat{Y}_i
is the i
th estimated value, Y_i
is the i
th observed value, \bar{Y}
is the arithmetic mean of observed values and N
is the number of timepoints.
For the population-mean cosinor model, the test is calculated according to the procedure described in Bingham et al. (1982) as follows:
F = \frac{k(k-2)}{2(k-1)}\frac{1}{1-(\frac{\widehat{\sigma}_{\beta\gamma}}{\widehat{\sigma}_\beta \widehat{\sigma}_\gamma})^2}[\frac{\beta^2}{\widehat{\sigma}^2_\beta}-2\frac{\widehat{\sigma}_{\beta\gamma}}{\widehat{\sigma}_\beta \widehat{\sigma}_\gamma}\frac{\beta \gamma}{\widehat{\sigma}_\beta \widehat{\sigma}_\gamma}+\frac{\gamma^2}{\widehat{\sigma}^2_\gamma}]
with df_1 = 2
and df_2 = k - 2
, where k
is the number of subjects in the population, \widehat{\sigma}_\beta
and \widehat{\sigma}_\gamma
are standard deviations of population \beta
and \gamma
coefficients and \widehat{\sigma}_{\beta\gamma}
is the covariance of population \beta
and \gamma
coefficients.
References
Cornélissen, G. (2014). Cosinor-Based Rhythmometry. Theoretical Biology and Medical Modeling, 11, Article 16.
Bingham, C., Arbogast, B., Guillaume Cornélissen, G., Lee, J.K. & Halberg, F. (1982). Inferential Statistical Methods for Estimating and Comparing Cosinor Parameters. Chronobiologia, 9(4), 397-439.
Examples
fit.temperature<-cosinor.lm(Temperature~time(Time), period = 24, data = temperature_zg)
cosinor.detect(fit.temperature)
fit.november<-population.cosinor.lm(data = PANAS_november, time = PANAS_time,
period = 7)
cosinor.detect(fit.november)
Comparison of Cosinor Parameters of Two Populations
Description
Runs the tests that compare MESORs, amplitudes and acrophases of two different populations.
Usage
cosinor.poptests(pop1, pop2)
Arguments
pop1 |
An object of the |
pop2 |
An object of the |
Details
Bingham et al. (1982) describe tests for comparing population MESORs, amplitudes and acrophases. These tests are esentially F-ratios with df_1 = m - 1
and df_2 = K - m
, where m
is the number of populations and K
is the total number of subjects. The tests for MESOR, amplitude and acrophase differences respectively are calculated as follows:
F_M = \frac{\sum_{j = 1}^{m}k_j(\widehat{M}_j - \widehat{M})^2}{(m-1)\widehat{\sigma}_M^2}
F_\phi = \frac{\frac{\sum_{j = 1}^{m}k_j A_j^2 * sin^2(\widehat{\phi}_j - \tilde{\phi})}{m - 1}} {\widehat{\sigma}_\beta^2 sin^2\tilde{\phi} + 2\widehat{\sigma}_{\beta \gamma} cos\tilde{\phi}sin\tilde{\phi} + \widehat{\sigma}_\gamma^2 cos^2\tilde{\phi}}
F_A = \frac{\frac{\sum_{j = 1}^{m}(\widehat{A}_j - \widehat{A})^2}{m - 1}}{\widehat{\sigma}^2_\beta cos^2\widehat{\phi} - 2\widehat{\sigma}_{\beta \gamma}cos\widehat{\phi}sin\widehat{\phi} + \widehat{\sigma}^2_\gamma sin^2 \widehat{\phi}}
where \widehat{M}
, \widehat{A}
and \widehat{\phi}
are weighted averages of parameters across populations calculated as:
\widehat{M} = \frac{\sum_{j = 1}^{m}k_j\widehat{M}_j}{K}
\widehat{A} = \frac{\sum_{j = 1}^{m}k_j\widehat{A}_j}{K}
\widehat{\phi} = \frac{\sum_{j = 1}^{m}k_j\widehat{\phi}_j}{K}
\tilde{\phi}
is derived from the following expression:
tan 2\tilde{\phi} = \frac{\sum_{j = 1}^{m}k_j\widehat{A}^2_j sin 2\widehat{\phi}_j}{\sum_{j = 1}^{m}k_j\widehat{A}^2_j cos 2\widehat{\phi}_j}
where 2\tilde{\phi}
lies between -\frac{\pi}{2}
and \frac{\pi}{2}
if the denomanator is positive or between \frac{\pi}{2}
and \frac{3\pi}{2}
if the denominator is negative, k_j
is the number of subjects in the j
th population, \widehat{M}_j
, \widehat{A}_j
and \widehat{\phi}_j
are the cosinor parameters of the j
th population and \widehat{\sigma}_\beta
,\widehat{\sigma}_\gamma
and \widehat{\sigma}_{\beta \gamma}
are the estimates of pooled standard deviations (and covariance) calculated as following:
\widehat{\sigma}_\beta = \frac{\sum_{j = 1}^{m} (k_j - 1)\widehat{\sigma}_{\beta_j}}{K - m}
\widehat{\sigma}_\gamma = \frac{\sum_{j = 1}^{m} (k_j - 1)\widehat{\sigma}_{\gamma_j}}{K - m}
\widehat{\sigma}_{\beta \gamma} = \frac{\sum_{j = 1}^{m} (k_j - 1)\widehat{\sigma}_{{\beta_j} {\gamma_j}}}{K - m}
where \widehat{\sigma}_{\beta_j}
, \widehat{\sigma}_{\gamma_j}
and \widehat{\sigma}_{{\beta_j} {\gamma_j}}
are the standard devations and covariance of \beta
and \gamma
parameters in the j
th population.
Note
These tests should only be performed on independent samples. If the acrophases of two populations are significantly different, the results of the amplitude difference test are not reliable and should not be interpreted. While it's possible to perform tests which compare more than two populations, this function can only compare two populations.
References
Bingham, C., Arbogast, B., Guillaume Cornélissen, G., Lee, J.K. & Halberg, F. (1982). Inferential Statistical Methods for Estimating and Comparing Cosinor Parameters. Chronobiologia, 9(4), 397-439.
Examples
fit.extraverts<-population.cosinor.lm(data = PA_extraverts, time = PA_time,
period = 24)
fit.introverts<-population.cosinor.lm(data = PA_introverts, time = PA_time,
period = 24)
cosinor.poptests(pop1 = fit.extraverts, pop2 = fit.introverts)
Periodogram
Description
Estimates the best-fitting period using iterative cosinor procedure.
Usage
periodogram(data, time, periods = time, na.action = na.omit,
alpha = 0.05)
Arguments
data |
A data frame containing responses of subjects collected over time, with subjects in the rows and timepoints in the columns. |
time |
A vector containing the times at which the data was collected. If this vector includes midnight, it should be coded as 24 instead of 0. |
periods |
A vector containing periods that are to be included in the periodogram. Defaults to the same periods as provided in the vector |
na.action |
Action to be performed on missing values. Defaults to |
alpha |
Significance level for determining if a rhythm with a given period is significant or not. Defaults to .05. |
Details
Iterative cosinor procedure is performed as described in Klemfuss & Clopton (1993). Cosinor is performed iteratively with the period (\tau
) increased by 1 in each iteration. Percent Rhythm is calculated in each iteration, which allows for an estimation of the best fitting period. A periodogram can be plotted, which shows Percent Rhythm (coefficient of determination) for each period. On the plot, periods with significant rhythm are shown as a point and periods with insignificant rhythm are shown as a cross.
Note
The range of periods included in iterations starts from 3 (sinusoidality of the curve is not achieved for \tau
< 3) and ends with the number of timepoints in the data.
References
Klemfuss, H. & Clopton, P. L. (1993). Seeking Tau: A Comparison of Six Methods. Journal of Interdisciplinary Cycle Research, 24(1), 1-16.
See Also
Examples
periodogram(data = PANAS_november, time = PANAS_time)
periodogram(data = t(data.frame(temperature_zg$Temperature)), time = temperature_zg$Time)
Population-Mean Cosinor
Description
Calculates the population-mean cosinor.
Usage
population.cosinor.lm(data, time, period, na.action = na.omit,
alpha = 0.05, plot = T)
Arguments
data |
A data frame containing responses of subjects collected over time, with subjects in the rows and timepoints in the columns. |
time |
A vector containing the times at which the data was collected. |
period |
Duration of one cycle of rhythm. |
na.action |
Action to be performed on missing values. Defaults to |
alpha |
Significance level for calculating population cosinor parameters confidence intervals. Defaults to .05 (confidence intervals are 5% risk intervals). |
plot |
Logical, display plot after calculation? Defaults to |
Details
According to the procedure described in Cornélissen (2014), to calculate population-mean cosinor, single cosinors are first performed on each subject and linearized parameters are averaged, which allows for calculation of delinearized parameters. After such a procedure is completed, confidence intervals of population-mean cosinor parameters can be calculated as described in Bingham et al. (1982) using the following formulae:
\widehat{M} \pm \frac{t_{1-\frac{\alpha}{2}}\widehat{\sigma}_M}{\sqrt{k}}
\widehat{\phi}+arctan(\frac{c_{23} t_{1-\frac{\alpha}{2}}^2 \pm t_{1-\frac{\alpha}{2}}\sqrt{c_{33}} \sqrt{\widehat{A}^2-\frac{(c_{22}c_{33}-c_{23}^2)t_{1-\frac{\alpha}{2}}^2}{c_{33}}}}{\widehat{A}^2 - c_{22} t_{1-\frac{\alpha}{2}}^2})
\widehat{A} \pm t_{1-\frac{\alpha}{2}} \sqrt{c_{22}}
where c_{22}
, c_{23}
and c_{33}
are elements of the sampling scheme matrix, calculated as follows:
c_{22}=\frac{\widehat{\sigma}^2_{\beta}\widehat{\beta}^2+2\widehat{\sigma}_{\beta \gamma}\widehat{\beta}\widehat{\gamma}+\widehat{\sigma}^2_{\gamma}\widehat{\gamma}^2}{k\widehat{A}^2}
c_{23}=\frac{-(\widehat{\sigma}^2_{\beta}-\widehat{\sigma}^2_{\gamma})(\widehat{\beta}\widehat{\gamma})+\widehat{\sigma}_{\beta \gamma}(\widehat{\beta}^2-\widehat{\gamma}^2)}{k\widehat{A}^2}
c_{33}=\frac{\widehat{\sigma}^2_{\beta}\widehat{\gamma}^2-2\widehat{\sigma}_{\beta \gamma}\widehat{\beta}\widehat{\gamma}+\widehat{\sigma}^2_{\gamma}\widehat{\beta}^2}{k\widehat{A}^2}
where \widehat{M}
, \widehat{A}
, \widehat{\phi}
, \widehat{\beta}
and \widehat{\gamma}
are population-mean cosinor parameters, \widehat{\sigma}_M
, \widehat{\sigma}_{\beta}
and \widehat{\sigma}_{\gamma}
are the standard deviations of the single cosinor parameters, \widehat{\sigma}_{\beta \gamma}
is the covariance of the single cosinor \beta
and \gamma
coefficients, k
is the number of subjects in a population and t_{1-\frac{\alpha}{2}}
is the two-tailed inverse of the t-distribution with \alpha
level of significance and k - 1
degrees of freedom.
Value
Object of the population.cosinor.lm
class containing the following objects:
single.cos |
A list of objects containing all performed single cosinors. |
pop.mat |
A data frame containing the cosinor parameters of each subject in the population. |
coefficients |
Delinearized population-mean cosinor coefficients. |
emp.mean |
Empirical mean of the data across all timepoints. |
fitted.values |
Estimated values of the rhythm caclculated using the cosinor model. |
residuals |
The difference between empirical mean and the fitted values. |
conf.int |
Values of upper and lower limits of confidence intervals of delinearized cosinor parameters. |
Note
If the confidence interval of the population amplitude includes zero, confidence interval of the acrophase cannot be calculated reliably. If this case occurs while using this function, the user will be warned and acrophase confidence interval limits will be set to NA.
References
Cornélissen, G. (2014). Cosinor-Based Rhythmometry. Theoretical Biology and Medical Modeling, 11, Article 16.
Bingham, C., Arbogast, B., Guillaume Cornélissen, G., Lee, J.K. & Halberg, F. (1982). Inferential Statistical Methods for Estimating and Comparing Cosinor Parameters. Chronobiologia, 9(4), 397-439.
Examples
population.cosinor.lm(data = PANAS_november, time = PANAS_time,
period = 7, na.action = "na.exclude")
Serial Sections
Description
Performs serial section analysis of rhythmic data and fits non-stationary cosinor models.
Usage
ssections(data, time, period, interval, increment, na.action = na.omit,
alpha = 0.05)
Arguments
data |
A data frame containing responses of subjects collected over time, with subjects in the rows and timepoints in the columns. |
time |
A vector containing the times at which the data was collected. |
period |
Duration of one cycle of rhythm. |
interval |
Length of an interval (number of timepoints) on which cosinor analyses will be ran. |
increment |
A number indicating for how much timepoints should the interval be displaced throughout the data. Note that the value of the increment cannot be higher than the value of the interval. |
na.action |
Action to be performed on missing values. Defaults to |
alpha |
Significance level for calculating population cosinor parameters confidence intervals. Defaults to .05 (confidence intervals are 5% risk intervals). |
Details
Cornélissen (2014) describes procedures for rhythmometric analysis of non-stationary data. First, an interval of an user-specified length (I
) is chosen and usual cosinor analysis (i.e. single cosinor or population-mean cosinor) is performed on the interval. The interval is then displaced throughout the data by an user-specified increment (\Delta t
) and cosinor analysis is then performed on the new interval. Intervals can be overlapping (\Delta t
<I) or non-overlapping (\Delta t
=I). A rhythm detection test is also calculated in each interval. After values of cosinor parameters have been obtained for each interval, they and their confidence intervals can be plotted, along with the p-values from the rhythm detection test.
Value
Object of the Serial sections
class containing the following objects:
coefficients |
Cosinor coefficients in each of the intervals. |
emp.mean |
Empirical mean of the data across all timepoints. |
p-values |
p-values from the rhythm detection test in each interval. |
cosinors |
A list containing all cosinor objects calculated in each interval. |
plots |
Stacked plots showing the empirical data, cosinor parameters and their confidence intervals, p-values of the rhythm detection test and number of measurements across time. |
Note
The value of increment cannot be higher than the value of the interval.
References
Cornélissen, G. (2014). Cosinor-Based Rhythmometry. Theoretical Biology and Medical Modeling, 11, Article 16.
Examples
ssections(data = PANAS_november, time = PANAS_time, period = 7,
interval = 7, increment = 1)
Daily air temperature in Zagreb
Description
A dataset containing the air temperature in Zagreb on July 1, 2015.
Usage
temperature_zg
Format
A data frame with two variables:
- Temperature
Air temperature in Zagreb on July 1, 2015.
- Time
Time of the day when the temperature was measured.
Details
Measurements were taken every 30 minutes throughout the whole day.
Source
Croatian Meteorological and Hydrological Service, http://www.meteo.hr