Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

as.data.frame.mcmc_output

Convert MCMC chain to data.frame


Description

Converts the MCMC chain output of run_mcmc to data.frame.

Usage

## S3 method for class 'mcmc_output'
as.data.frame(
  x,
  row.names,
  optional,
  variable = c("theta", "states"),
  times,
  states,
  expand = !(x$mcmc_type %in% paste0("is", 1:3)),
  ...
)

Arguments

x

Output from run_mcmc.

row.names

Ignored.

optional

Ignored.

variable

Return samples of "theta" (default) or "states"?

times

Vector of indices. In case of states, what time points to return? Default is all.

states

Vector of indices. In case of states, what states to return? Default is all.

expand

Should the jump-chain be expanded? Defaults to TRUE for non-IS-MCMC, and FALSE for IS-MCMC. For expand = FALSE and always for IS-MCMC, the resulting data.frame contains variable weight (= counts times IS-weights).

...

Ignored.

Examples

data("poisson_series")
model <- bsm_ng(y = poisson_series, 
sd_slope = halfnormal(0.1, 0.1), 
sd_level = halfnormal(0.1, 1),
  distribution = "poisson")
  
out <- run_mcmc(model, iter = 2000, particles = 10)
head(as.data.frame(out, variable = "theta"))
head(as.data.frame(out, variable = "state"))

# don't expand the jump chain:
head(as.data.frame(out, variable = "theta", expand = FALSE))

# IS-weighted version:
out_is <- run_mcmc(model, iter = 2000, particles = 10, mcmc_type  = "is2")
head(as.data.frame(out_is, variable = "theta"))

bssm

Bayesian Inference of Non-Linear and Non-Gaussian State Space Models

v1.1.4
GPL (>= 2)
Authors
Jouni Helske [aut, cre] (<https://orcid.org/0000-0001-7130-793X>), Matti Vihola [aut] (<https://orcid.org/0000-0002-8041-7222>)
Initial release
2021-04-13

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.