View source: R/expand_sample.R

expand_sample | R Documentation |

The MCMC algorithms of `bssm`

use a jump chain representation where we
store the accepted values and the number of times we stayed in the current
value. Although this saves bit memory and is especially convenient for
IS-corrected MCMC, sometimes we want to have the usual sample paths
(for example for drawing traceplots).
Function `expand_sample`

returns the expanded sample based on the
counts (in form of `coda::mcmc`

object. Note that for
the IS-MCMC the expanded sample corresponds to the approximate posterior,
i.e., the weights are ignored.

expand_sample(x, variable = "theta", times, states, by_states = TRUE)

`x` |
Output from |

`variable` |
Expand parameters |

`times` |
A vector of indices. In case of states, what time points to expand? Default is all. |

`states` |
A vector of indices. In case of states, what states to expand? Default is all. |

`by_states` |
If |

This functions is mostly for backwards compatibility, methods
`as.data.frame`

and `as_draws`

produce likely more convenient
output.

An object of class `"mcmc"`

of the `coda`

package.

`as.data.frame.mcmc_output`

and `as_draws.mcmc_output`

.

set.seed(1) n <- 50 x <- cumsum(rnorm(n)) y <- rnorm(n, x) model <- bsm_lg(y, sd_y = gamma_prior(1, 2, 2), sd_level = gamma_prior(1, 2, 2)) fit <- run_mcmc(model, iter = 1e4) # Traceplots for theta plot.ts(expand_sample(fit, variable = "theta")) # Traceplot for x_5 plot.ts(expand_sample(fit, variable = "states", times = 5, states = 1)$level)

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.