Learn R Programming

bssm (version 2.0.2)

as.data.frame.mcmc_output: Convert MCMC Output to data.frame

Description

Converts the MCMC output of run_mcmc to data.frame.

Usage

# S3 method for mcmc_output
as.data.frame(
  x,
  row.names,
  optional,
  variable = c("theta", "states"),
  times,
  states,
  expand = TRUE,
  use_times = TRUE,
  ...
)

Arguments

x

Object of class mcmc_output from run_mcmc.

row.names

Ignored.

optional

Ignored.

variable

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

times

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

states

A 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 expand = FALSE and always for IS-MCMC, the resulting data.frame contains variable weight (= counts * IS-weights).

use_times

If TRUE (default), transforms the values of the time variable to match the ts attribute of the input to define. If FALSE, time is based on the indexing starting from 1.

...

Ignored.

See Also

as_draws which converts the output for as_draws object.

Examples

Run this code
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"))

Run the code above in your browser using DataLab