Package 'cosinor2'

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>.
Authors: Augustin Mutak <[email protected]>
Maintainer: Augustin Mutak <[email protected]>
License: GPL-3
Version: 0.2.0
Built: 2025-02-11 04:27:34 UTC
Source: https://github.com/amutak/cosinor2

Help Index


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 cosinor.lm class.

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+garctanγβK + g * arctan \vert\frac{\gamma}{\beta}\vert

where values of KK and gg 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)

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 cosinor.lm or population.cosinor.lm class.

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=(Y^iYˉ)22(YiYˉ)2N3F = \frac{\frac{\sum(\widehat{Y}_i - \bar{Y})^2}{2}}{\frac{\sum(Y_i - \bar{Y})^2}{N - 3}}

with df1=2df_1 = 2 and df2=N3df_2 = N - 3 , where Y^i\widehat{Y}_i is the iith estimated value, YiY_i is the iith observed value, Yˉ\bar{Y} is the arithmetic mean of observed values and NN 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=k(k2)2(k1)11(σ^βγσ^βσ^γ)2[β2σ^β22σ^βγσ^βσ^γβγσ^βσ^γ+γ2σ^γ2]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 df1=2df_1 = 2 and df2=k2df_2 = k - 2 , where kk 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 population.cosinor.lm class calculated on the first population.

pop2

An object of the population.cosinor.lm class calculated on the second population.

Details

Bingham et al. (1982) describe tests for comparing population MESORs, amplitudes and acrophases. These tests are esentially F-ratios with df1=m1df_1 = m - 1 and df2=Kmdf_2 = K - m, where mm is the number of populations and KK is the total number of subjects. The tests for MESOR, amplitude and acrophase differences respectively are calculated as follows:

FM=j=1mkj(M^jM^)2(m1)σ^M2F_M = \frac{\sum_{j = 1}^{m}k_j(\widehat{M}_j - \widehat{M})^2}{(m-1)\widehat{\sigma}_M^2}

Fϕ=j=1mkjAj2sin2(ϕ^jϕ~)m1σ^β2sin2ϕ~+2σ^βγcosϕ~sinϕ~+σ^γ2cos2ϕ~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}}

FA=j=1m(A^jA^)2m1σ^β2cos2ϕ^2σ^βγcosϕ^sinϕ^+σ^γ2sin2ϕ^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 M^\widehat{M}, A^\widehat{A} and ϕ^\widehat{\phi} are weighted averages of parameters across populations calculated as:

M^=j=1mkjM^jK\widehat{M} = \frac{\sum_{j = 1}^{m}k_j\widehat{M}_j}{K}

A^=j=1mkjA^jK\widehat{A} = \frac{\sum_{j = 1}^{m}k_j\widehat{A}_j}{K}

ϕ^=j=1mkjϕ^jK\widehat{\phi} = \frac{\sum_{j = 1}^{m}k_j\widehat{\phi}_j}{K}

ϕ~\tilde{\phi} is derived from the following expression:

tan2ϕ~=j=1mkjA^j2sin2ϕ^jj=1mkjA^j2cos2ϕ^jtan 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ϕ~2\tilde{\phi} lies between π2-\frac{\pi}{2} and π2\frac{\pi}{2} if the denomanator is positive or between π2\frac{\pi}{2} and 3π2\frac{3\pi}{2} if the denominator is negative, kjk_j is the number of subjects in the jjth population, M^j\widehat{M}_j, A^j\widehat{A}_j and ϕ^j\widehat{\phi}_j are the cosinor parameters of the jjth 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:

σ^β=j=1m(kj1)σ^βjKm\widehat{\sigma}_\beta = \frac{\sum_{j = 1}^{m} (k_j - 1)\widehat{\sigma}_{\beta_j}}{K - m}

σ^γ=j=1m(kj1)σ^γjKm\widehat{\sigma}_\gamma = \frac{\sum_{j = 1}^{m} (k_j - 1)\widehat{\sigma}_{\gamma_j}}{K - m}

σ^βγ=j=1m(kj1)σ^βjγjKm\widehat{\sigma}_{\beta \gamma} = \frac{\sum_{j = 1}^{m} (k_j - 1)\widehat{\sigma}_{{\beta_j} {\gamma_j}}}{K - m}

where σ^βj\widehat{\sigma}_{\beta_j}, σ^γj\widehat{\sigma}_{\gamma_j} and σ^βjγj\widehat{\sigma}_{{\beta_j} {\gamma_j}} are the standard devations and covariance of β\beta and γ\gamma parameters in the jjth 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)

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 cosinor.lm or population.cosinor.lm class.

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)

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.


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.


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 time.

na.action

Action to be performed on missing values. Defaults to na.omit.

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

cosinor.PR

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 na.omit.

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 TRUE.

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:

M^±t1α2σ^Mk\widehat{M} \pm \frac{t_{1-\frac{\alpha}{2}}\widehat{\sigma}_M}{\sqrt{k}}

ϕ^+arctan(c23t1α22±t1α2c33A^2(c22c33c232)t1α22c33A^2c22t1α22)\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})

A^±t1α2c22\widehat{A} \pm t_{1-\frac{\alpha}{2}} \sqrt{c_{22}}

where c22c_{22}, c23c_{23} and c33c_{33} are elements of the sampling scheme matrix, calculated as follows:

c22=σ^β2β^2+2σ^βγβ^γ^+σ^γ2γ^2kA^2c_{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}

c23=(σ^β2σ^γ2)(β^γ^)+σ^βγ(β^2γ^2)kA^2c_{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}

c33=σ^β2γ^22σ^βγβ^γ^+σ^γ2β^2kA^2c_{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 M^\widehat{M}, A^\widehat{A}, ϕ^\widehat{\phi}, β^\widehat{\beta} and γ^\widehat{\gamma} are population-mean cosinor parameters, σ^M\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, kk is the number of subjects in a population and t1α2t_{1-\frac{\alpha}{2}} is the two-tailed inverse of the t-distribution with α\alpha level of significance and k1k - 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 na.omit.

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 (II) 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 (Δt\Delta t) and cosinor analysis is then performed on the new interval. Intervals can be overlapping (Δt\Delta t<I) or non-overlapping (Δt\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