# (Integrated) autocorrelation time

**URL:** https://discourse.julialang.org/t/integrated-autocorrelation-time/7403
**Category:** Statistics
**Tags:** question, proposal
**Created:** [November 30, 2017, 6:35am UTC](https://discourse.julialang.org/t/integrated-autocorrelation-time/7403 "2017-11-30T06:35:04Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![Sleort](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sleort/32/4875_2.png) [@Sleort](https://discourse.julialang.org/u/Sleort)
#### Post date: [November 30, 2017, 6:35am UTC](https://discourse.julialang.org/t/integrated-autocorrelation-time/7403/1 "2017-11-30T06:35:04Z")

</div>

I could not find any (integrated) autocorrelation time estimator in the basic statistics packages\*, so I made a crude [implementation](https://github.com/Sleort/FerrenbergSwendsenReweighting.jl/blob/master/src/AutocorrelationTime.jl) myself based on `StatsBase.autocor` and the tips given in [http://www.stat.unc.edu/faculty/cji/Sokal.pdf](http://www.stat.unc.edu/faculty/cji/Sokal.pdf). At the moment my implementation is just part of another package (under construction), but I realized that calculating autocorrelation times is of more general importance, so this functionality should maybe be moved somewhere else… (like to `StatsBase`?)

Of course, a more rigorous and less heuristic implementation/algorithm would be advantageous, if anyone is aware of that…

\*Except apparently somewhere in [this](https://github.com/brendano/MCMC.jl) package, which seems to have been abandoned.

---

<div class="post-metadata">

### Author: ![juliohm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juliohm/32/215266_2.png) [@juliohm](https://discourse.julialang.org/u/juliohm)
#### Post date: [November 30, 2017, 7:01am UTC](https://discourse.julialang.org/t/integrated-autocorrelation-time/7403/2 "2017-11-30T07:01:02Z")

</div>

Very nice @Sleort, thanks for putting a package together and for adopting the `evaluate` interface we discussed in [another thread](https://discourse.julialang.org/t/appending-to-names-of-callable-objects-functors-that-modify-their-argument/7343) 🙂

I would like to share with you something that has great overlap, which is the concept of variograms. A variogram is basically a constant (the sill) minus the autocorrelation, but it is more general in the sense that we can still use them to create models that aren’t necessarily stationary. There is also an efficient procedure to calculate variograms in more than one dimension, not only time series. I have implementations of variograms in [GeoStats.jl](https://github.com/juliohm/GeoStats.jl), this Jupyter notebook illustrates more or less the modeling: [http://nbviewer.jupyter.org/github/juliohm/GeoStats.jl/blob/master/examples/VariogramModeling.ipynb](http://nbviewer.jupyter.org/github/juliohm/GeoStats.jl/blob/master/examples/VariogramModeling.ipynb)

Feel free to play with them, compare results, and suggest improvements. Good to have more people involved with autocorrelation-related work. 👍

---

<div class="post-metadata">

### Author: ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)
#### Post date: [November 30, 2017, 7:19am UTC](https://discourse.julialang.org/t/integrated-autocorrelation-time/7403/3 "2017-11-30T07:19:35Z")

</div>

I have a (relatively well tested) effective sample size implementation in  
[https://github.com/tpapp/MCMCDiagnostics.jl](https://github.com/tpapp/MCMCDiagnostics.jl)

---

<div class="post-metadata">

### Author: ![Sleort](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sleort/32/4875_2.png) [@Sleort](https://discourse.julialang.org/u/Sleort)
#### Post date: [November 30, 2017, 9:24am UTC](https://discourse.julialang.org/t/integrated-autocorrelation-time/7403/4 "2017-11-30T09:24:27Z")

</div>

@juliohm You’re welcome. And thank you for useful feedback/opinions 🙂

The concept of variograms is new to me. I’m not sure it will be of use for me at the moment though, but I’ll keep it in mind!

@Tamas_Papp Great! That’s basically what I need! … but you haven’t registered it as a package (as far as I can see). Is there a reason for this? Is the intention that one should manually copy the file to ones own package?

---

<div class="post-metadata">

### Author: ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)
#### Post date: [November 30, 2017, 9:41am UTC](https://discourse.julialang.org/t/integrated-autocorrelation-time/7403/5 "2017-11-30T09:41:37Z")

</div>

You can just `Pkg.clone` it. I added a note to the [README](https://github.com/tpapp/MCMCDiagnostics.jl#installation).

It is not registered because I am still working on the API of my MCMC toolkit. In particular, see the documentation of [DynamicHMC.jl](https://github.com/tpapp/DynamicHMC.jl) which now has an example of how to use them together.

If you find it useful, open an issue and I will register it.

---

<div class="post-metadata">

### Author: ![Sleort](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sleort/32/4875_2.png) [@Sleort](https://discourse.julialang.org/u/Sleort)
#### Post date: [December 1, 2017, 2:47am UTC](https://discourse.julialang.org/t/integrated-autocorrelation-time/7403/6 "2017-12-01T02:47:32Z")

</div>

I think it would be useful to register `MCMCDiagnostics.jl`, as its content is quite general and important for any MCMC simulation (and beyond?)…

Also, it has to be registered in order for other packages to depend on it (added to REQUIRE)… (At least until `Pkg3.jl` is out, if my understanding is correct.)

I’ll open an issue…

---

<div class="post-metadata">

### Author: ![juliohm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juliohm/32/215266_2.png) [@juliohm](https://discourse.julialang.org/u/juliohm)
#### Post date: [December 1, 2017, 3:34am UTC](https://discourse.julialang.org/t/integrated-autocorrelation-time/7403/7 "2017-12-01T03:34:36Z")

</div>

@Sleort I want to clarity it further, and repeat that variogram and autocorrelation are basically the same thing (one is minus the other). You can compute variogram with time series exactly as you do with autocorrelation.

The main difference from a modeling perspective is that we have variograms for which there is no covariance, correlation, correlogram… counterpart. Other than that, they can be seen as equivalent.
