Skip to content

Commit 61370bc

Browse files
committed
Updates to clarify difference in hmm_latent_rng and hmm_hidden_state_prob and generating totally new trajectories of the HMM
1 parent cf40154 commit 61370bc

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

knitr/hmm-example/hmm-example.Rmd

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: "HMM Example"
33
author: "Ben Bales"
4-
date: 9-26-2020
4+
date: 10-2-2020
55
output:
66
html_document: default
77
pdf_document: default
@@ -45,13 +45,16 @@ There are three functions
4545

4646
- `hmm_marginal` - The likelihood of an HMM with the hidden discrete states
4747
integrated out
48-
- `hmm_latent_rng` - A function to generate draws of the hidden state from the posterior
49-
- `hmm_hidden_state_prob` - A function to compute the distribution of hidden states
50-
states at each measurement time
48+
- `hmm_latent_rng` - A function to generate draws of the hidden state that are
49+
implicitly integrated out of the model when using `hmm_marginal` (this is
50+
different than sampling more states with a posterior draw of a transition matrix
51+
and initial state)
52+
- `hmm_hidden_state_prob` - A function to compute the distributions of the
53+
integrated out hidden states
5154

5255
This guide will demonstrate how to simulate HMM realizations in R, fit the data
53-
with `hmm_marginal`, produce estimates of the hidden states using
54-
`hmm_hidden_state_prob`, and generate draws of the hidden state from the
56+
with `hmm_marginal`, produce estimates of the distributions of the hidden states
57+
using `hmm_hidden_state_prob`, and generate draws of the hidden state from the
5558
posterior with `hmm_latent_rng`.
5659

5760
### Generating HMM realizations
@@ -221,7 +224,7 @@ fit$summary("t3")
221224

222225
### State Probabilities
223226

224-
Even though the hidden states are not sampled directly, the distribution
227+
Even though the hidden states are integrated out, the distribution
225228
of hidden states at each time point can be computed with the function
226229
`hmm_hidden_state_prob`:
227230

@@ -258,14 +261,20 @@ hidden_probs_df %>%
258261
xlab("Time (n)")
259262
```
260263

261-
New simulations from the fitted HMM can be generated with `hmm_latent_rng`:
264+
If it is more convenient to work with draws of the hidden states at each time
265+
point (instead of the probabilities provided by `hmm_hidden_state_prob`), these
266+
can be generated with `hmm_latent_rng`:
262267

263268
```{stan, output.var = "", eval = FALSE}
264269
generated quantities {
265270
int[N] y_sim = hmm_latent_rng(log_omega, Gamma, rho)
266271
}
267272
```
268273

274+
Note, these are the probabilities and draws of the hidden state that was
275+
integrated out. This is different than sampling new HMM realizations using
276+
posterior draws of the initial condition and the transition matrix.
277+
269278
These can be plotted as well:
270279

271280
```{r}

0 commit comments

Comments
 (0)