View source: R/check_diagnostics.R

check_diagnostics | R Documentation |

`run_mcmc`

OutputPrints out the acceptance rate, smallest effective sample sizes (ESS) and
largest Rhat values for a quick first check that the sampling worked. For
further checks, see e.g. `bayesplot`

and `coda`

packages.

check_diagnostics(x)

`x` |
Results object of class |

For methods other than IS-MCMC, the estimates are based on the improved
diagnostics from the `posterior`

package.For IS-MCMC, these Rhat,
bulk-ESS, and tail-ESS estimates are based on the approximate posterior
which should look reasonable, otherwise the IS-correction does not make much
sense. For IS-MCMC, ESS estimates based on a weighted posterior are also
computed.

set.seed(1) n <- 30 phi <- 2 rho <- 0.9 sigma <- 0.1 beta <- 0.5 u <- rexp(n, 0.1) x <- rnorm(n) z <- y <- numeric(n) z[1] <- rnorm(1, 0, sigma / sqrt(1 - rho^2)) y[1] <- rnbinom(1, mu = u * exp(beta * x[1] + z[1]), size = phi) for(i in 2:n) { z[i] <- rnorm(1, rho * z[i - 1], sigma) y[i] <- rnbinom(1, mu = u * exp(beta * x[i] + z[i]), size = phi) } model <- ar1_ng(y, rho = uniform_prior(0.9, 0, 1), sigma = gamma_prior(0.1, 2, 10), mu = 0., phi = gamma_prior(2, 2, 1), distribution = "negative binomial", xreg = x, beta = normal_prior(0.5, 0, 1), u = u) out <- run_mcmc(model, iter = 1000, particles = 10) check_diagnostics(out)

bssm documentation built on May 4, 2022, 1:06 a.m.

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.