[SciPy-User] autocorrelation

josef.pktd at gmail.com josef.pktd at gmail.com
Tue Jun 19 12:29:19 EDT 2012


On Tue, Jun 19, 2012 at 12:18 PM, Skipper Seabold <jsseabold at gmail.com> wrote:
> On Tue, Jun 19, 2012 at 12:03 PM, Jaidev Deshpande
> <deshpande.jaidev at gmail.com> wrote:
>>
>> On Tue, Jun 19, 2012 at 9:21 PM, Bala subramanian
>> <bala.biophysics at gmail.com> wrote:
>> > Friends,
>> > I need to calculate the autocorrelation of my data. How can i do the
>> > same in
>> > scipy.
>> >
>> > I want to make a plot similar to that shown in the following link.
>> > autocorrelation of the data for a user input time lag.
>> >
>> > http://www.itl.nist.gov/div898/handbook/eda/section3/autocopl.htm
>> >
>> > --
>> > C. Balasubramanian
>> >
>> >
>> > _______________________________________________
>> > SciPy-User mailing list
>> > SciPy-User at scipy.org
>> > http://mail.scipy.org/mailman/listinfo/scipy-user
>> >
>>
>> Hi,
>>
>> You can use the numpy.corrcoef function. Please refer to this
>>
>> http://docs.scipy.org/doc/numpy/reference/generated/numpy.corrcoef.html#numpy.corrcoef
>>
>> The plotting can be easily done with matplotlib. If you want the
>> figure exactly as in the link you provided, you can use the xlabel and
>> ylabel functions for labeling the axes, and the axis command to set
>> the range of the X and Y axes.
>
>
> You could also use statsmodels. I don't think we have a convenience function
> yet for plotting ACF (pull requests welcome), but you can do something like
> (using the FLICKER.DAT from NIST in that example)

We have it somewhere but I cannot find it in the docs.
Pandas also has it or will get it as part of GSOC.

Josef


>
> import statsmodels.api as sm
> import matplotlib.pyplot as plt
>
> plt.interactive(False)
> fig = plt.figure()
> ax = fig.add_subplot(111)
>
> acf = sm.tsa.acf(y, nlags=250)
>
> ax.bar(np.arange(251), acf)
> plt.show()
>
>
> _______________________________________________
> SciPy-User mailing list
> SciPy-User at scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user
>



More information about the SciPy-User mailing list