No BSD License  

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from
Cosinor Analysis

4.0 | 1 rating Rate this file 15 Downloads (last 30 days) File Size: 25.3 KB File ID: #20329 Version: 1.0
image thumbnail

Cosinor Analysis


cheart (view profile)


17 Jun 2008 (Updated )

Fits cosine curve to a time series using least squares

| Watch this File

File Information

  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.
  1979. Please consult reference.

  t - time series
  y - value of series at time t
  w - cycle length, defined by user based on prior knowledge of time
  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.

Required Products Statistics and Machine Learning Toolbox
MATLAB release MATLAB 7.4 (R2007a)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (9)
16 Jan 2016 luo2c1

luo2c1 (view profile)

10 Aug 2014 Stanislav

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. :)

Comment only
06 Aug 2014 Stanislav

UPD: 3) added by mistake

Comment only
06 Aug 2014 Stanislav

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.

Comment only
20 Dec 2011 David Bulger

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

Comment only
13 Mar 2009 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);

Comment only
26 Jun 2008 c heart

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

Comment only
20 Jun 2008 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.

Comment only
18 Jun 2008 a a

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

Comment only

Contact us