as_draws: Convert 'run_mcmc' output to 'draws_df' format

Description Usage Arguments Value Examples

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

1
2
3

Arguments

x

An object of class mcmc_output

Value

A draws_df object.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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)

bssm documentation built on Sept. 21, 2021, 5:09 p.m.