Re: Correlation function and data
- To: mathgroup at smc.vnet.net
- Subject: [mg24766] Re: Correlation function and data
- From: Jens-Peer Kuska <kuska at informatik.uni-leipzig.de>
- Date: Thu, 10 Aug 2000 00:31:49 -0400 (EDT)
- Organization: Universitaet Leipzig
- References: <8mr0id$1is@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Hi,
in *every* term of your summation you calculate the two times
the mean value and one time the variance *and* you are wondering
why it take so long ? Strange ..
n=Length[data];
aved=Mean[data];
vard=Variance[data];
centerd=(#-aved) & /@ data
c[y_]:=Sum[centerd[[i]]*centerd[[i+y]], {i,1,n - y}]/vard
may help and
c[y_]:=(Dot @@ (Take[#,n-y] & /@ {centerd,RotateLeft[centerd,y]}))/vard
may be a bit faster
Regards
Jens
Deborah Leddon wrote:
>
> 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.