Estimation of effectve size in stan code

Hi all,

I would like to estimate the correlation length (or effective size) of the a model’s residuals within the transformed_parameters block.

Any idea how to do this efficiently without [rewriting] an autocorrelation function in stan ?



Unfortunately we don’t have a built-in autocorrelation function in Stan so you would have to write the code. My hunch is that this has probably come up before though, so you may be able to search for an example where someone has already efficiently coded it up in a Stan program. It’s something we should probably consider adding to the language though.

Thanks Jonah ! I’ll sneak around…

I +1 to your suggestion of adding it to Stan ;-)

I recommend opening an issue on GitHub with a feature request!


There’s already a PR, and
associated discussion here
Analysis API

1 Like

Do you need the result as part of the log density? If not, then it’s much more efficient to do these kinds of transforms in the generated quantities block.

That’s for analysis code on the outside. The question is about calculating the autocorrelation of residuals within the model itself.

1 Like

Yes, I would like to use it in a regularization prior.

We’ve been talking for a long time about adding the FFT code with derivatives to make it possible to do efficient autocorrelations, but we’re still hung up on how to represent imaginary numbers. If we only exposed an autorcorrelation function, that problem would go away.