# Regime-switching Model in Turing.jl

**URL:** <https://discourse.julialang.org/t/regime-switching-model-in-turing-jl/68614>\
**Category:** Probabilistic Programming\
**Tags:** turing\
**Created:** [September 23, 2021, 5:03am UTC](https://discourse.julialang.org/t/regime-switching-model-in-turing-jl/68614 "2021-09-23T05:03:32Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ohmsweetohm1](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ohmsweetohm1/32/49126_2.png) [@ohmsweetohm1](https://discourse.julialang.org/u/ohmsweetohm1)\
**Post date:** [September 23, 2021, 5:03am UTC](https://discourse.julialang.org/t/regime-switching-model-in-turing-jl/68614/1 "2021-09-23T05:03:32Z")

</div>

Is it possible to replicate this Stan model in Turing.jl?

[https://khakieconomics.github.io/2018/02/24/Regime-switching-models.html](https://khakieconomics.github.io/2018/02/24/Regime-switching-models.html)

---

<div class="post-metadata">

**Author:** ![spragud2](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/spragud2/32/29409_2.png) [@spragud2](https://discourse.julialang.org/u/spragud2)\
**Post date:** [September 23, 2021, 5:07pm UTC](https://discourse.julialang.org/t/regime-switching-model-in-turing-jl/68614/2 "2021-09-23T17:07:46Z")

</div>

That article seems to be describing a relatively straightforward hidden Markov model.

In turing:  
[https://turing.ml/dev/tutorials/04-hidden-markov-model/](https://turing.ml/dev/tutorials/04-hidden-markov-model/)

Changes in state are the regime changes described in that article. You can either sample the state path as in that tutorial, or use the Viterbi algorithm to calculate it for you. You can use the forward-backward algorithm to calculate the odds of being in a given regime at a given time.

For the emission distributions, one will be an autoregressive gaussian (conditioned on the prior value), whereas the other one is simply a gaussian.
