File Exchange

## Cosinor Analysis

version 1.0 (25.3 KB) by

Fits cosine curve to a time series using least squares

Updated

Description:
Cosinor analysis uses the least squares method to fit a sine wave to a
time series. Cosinor analysis is often used in the analysis
of biologic time series that demonstrate predictible rhythms. This
method can be used with an unequally spaced time series.

Follows cosinor analysis of a time series as outlined by
Nelson et al. "Methods for Cosinor-Rhythmometry" Chronobiologica.

Input:
t - time series
y - value of series at time t
w - cycle length, defined by user based on prior knowledge of time
series
alpha - type I error used for cofidence interval calculations. Usually
set to be 0.05 which corresponds with 95% cofidence intervals

Note: Statistics toolbox is necessary only to caculate t and F distributions for the number of samples at the specified alpha. These values could be obtained from a table and manually inserted in the code, thus negating the use of the statistics toolbox.

I'm getting the following message:

"Confidence region overlaps the pole. Confidence limits for Amplitude and Acrophase cannot be determined"

Why the confidence region overlaps the pole? Why cannot the confidence limits for amplitude and acrophase be determined? What can I do to solve this?

luo2c1

Stanislav

### Stanislav (view profile)

It seems that unequal sampling problem can be resolved by addition ~isnan(y) to every value in NE matrix. Thus 2) is not an issue. :)

Stanislav

Stanislav

### Stanislav (view profile)

I am by no means a specialist in Matlab, but there are several comments:
1) In section "Confidence interval for the mesor" is written 'sigma^2', whereas according to Nelson et al, 1979 and Bingham et al., 1982 it should be 'sigma'.
This leads to inflated estimation of mesor CI.
2) This code is can not be used for data sets with missing values - only equally spaced and full time series thus simplified estimation of M, beta and gamma can be applied as shown in Nelson et al.,1979.
3) According to Nelson et al., 1979 t should be computed for two-tailed distribution, thus 1-alpha/2 should be used.

David Bulger

### David Bulger (view profile)

Wouldn't the p-value for the zero-amplitude test have to come from the F-distribution's CDF, rather than its PDF?

David

### David (view profile)

Undefined function or variable "phi".

Error in ==> cosinor at 94
fprintf(1,'Mesor = %g \nAmplitude = %g \nAcrophase = %g \n\n',M,Amp,phi);

c heart

The published example should run to completion. The statistics toolbox is necessary. Please post if there are any additional problems.

Peter Giles

The published example does not run to completion. The error message is:

??? Undefined function or method 'tinv' for input arguments of type 'double'.

Error in ==> cosinor at 121
CI_M = tinv(1-alpha/2,n-3)*sigma^2*sqrt(((sum(x.^2))*(sum(z.^2)) - (sum(x.*z))^2)/(n^3*(X*Z - T^2))); %#ok<NASGU>

Either this m-file depends on a toolbox not identified here, or something has been left out of the submission.

a a

There is a bug in the published M-file!!!

##### MATLAB Release
MATLAB 7.4 (R2007a)