No BSD License  

Highlights from
Cosinor Analysis

Be the first to rate this file! 18 Downloads (last 30 days) File Size: 25.3 KB File ID: #20329
image thumbnail

Cosinor Analysis

by

 

17 Jun 2008 (Updated )

Fits cosine curve to a time series using least squares

| Watch this File

File Information
Description

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

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.

Required Products Statistics 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 (8)
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. :)

06 Aug 2014 Stanislav

UPD: 3) added by mistake

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.

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?

13 Mar 2009 David

Undefined function or variable "phi".

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

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.

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.

18 Jun 2008 a a

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

Contact us