MathGroup Archive 2000

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Re: Correlation function and data

  • To: mathgroup at smc.vnet.net
  • Subject: [mg24792] Re: [mg24748] Re: Correlation function and data
  • From: Ian Brooks <ianb at wolfram.com>
  • Date: Thu, 10 Aug 2000 00:32:58 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

A better function to use here is ListCorrelate.  Try:

corrs[data_List] := Module[{adjdata},
     adjdata = data - (Tr[data]/Length[data]);
     Flatten[
       Map[ListCorrelate[adjdata, PadRight[Drop[adjdata, #], Length[adjdata]]]/
             Variance[data] &, Range[Length[data] - 1]]]]

In quick testing the time for 300 datapoints is about 0.4 s, compared to 
~53 s for the Sum approach.

Ian

>Hello,
>  I am trying to construct an autocorrelation function that can be
>applied to a data set as follows;
>
>n=Length[data];
>c[y_]:= Sum[(data[[i]] - Mean[data] )* ( data[[i+y]] - Mean[data])/
>                 Variance[data], {i,1,n - y}];
>corrfunction = Array[c, {n - 1}];
>
>ListPlot[corrfunction, PlotJoined->True]
>
>Problem is , this routine works well for data sets up to a length of
>300 points, but gets unusually long for larger data sets , say
>around 1000-3000 points in length. I've tried  "Map" (using
>anonymous function rules), Table-Evaluate, etc..
>
>Anyone got any ideas? I would much appreciate them!
>
>Regards,
>Deb L.



  • Prev by Date: 3D plot of discontinuous function
  • Next by Date: Re: postscript
  • Previous by thread: Re: Re: Correlation function and data
  • Next by thread: Re: Correlation function and data