as_draws_df.mcmc_output {bssm}R Documentation

Convert run_mcmc output to draws_df format

Description

Converts MCMC output from run_mcmc call to a draws_df format of the posterior package. This enables the use of diagnostics and plotting methods of posterior and bayesplot packages. Note though that if run_mcmc used IS-MCMC method, the resulting weight column of the output is ignored by the aforementioned packages, i.e. the results correspond to approximate MCMC.

Usage

as_draws_df.mcmc_output(x)

as_draws.mcmc_output(x)

Arguments

x

An object of class mcmc_output

Value

A draws_df object.

Examples


model <- bsm_lg(Nile, 
  sd_y = tnormal(init = 100, mean = 100, sd = 100, min = 0),
  sd_level = tnormal(init = 50, mean = 50, sd = 100, min = 0),
  a1 = 1000, P1 = 500^2)

fit1 <- run_mcmc(model, iter = 2000)
library("posterior")
draws <- as_draws(fit1)
head(draws, 4)
ess_bulk(draws$sd_y)
summary(fit1, return_se = TRUE)

# More chains:
model$theta[] <- c(50, 150) # change initial value
fit2 <- run_mcmc(model, iter = 2000)
model$theta[] <- c(150, 50) # change initial value
fit3 <- run_mcmc(model, iter = 2000)

draws <- bind_draws(as_draws(fit1),
  as_draws(fit2), as_draws(fit3), along = "chain")
# it is actually enough to transform first mcmc_output to draws object, 
# rest are transformed automatically inside bind_draws
rhat(draws$sd_y)
ess_bulk(draws$sd_y)
ess_tail(draws$sd_y)


[Package bssm version 1.1.7-1 Index]