Search code examples
python-2.7statisticspymc3

PyMC3 autocorrplot() for any given array


The autocorrplot() function gives the autocorrelation plot for the sampled data from the trace. If I already have a sample of data in the form of an array or list, can I use autocorrplot() to do the same? Is there any alternative to generate autocorrelation plots given a sequence of data? Please help.


Solution

  • autocorrplot is a wrapper around matplotlib's acorr. To get a similar look to pymc3's version, you can use something like

    import numpy as np
    import matplotlib.pyplot as plt
    
    my_array = np.random.normal(size=1000)
    
    plt.acorr(my_array, detrend=plt.mlab.detrend_mean, maxlags=100)
    plt.xlim(0, 100)
    

    enter image description here

    Note the call to xlim at the end, since by default PyMC3 does not show negative correlations.