diagplots: Diagnostic plots for 'hmclearn'

Description Usage Arguments Value Examples

View source: R/utils.R

Description

Plots histograms of the posterior estimates. Optionally, displays the 'actual' values given a simulated dataset.

Usage

1
2
3
4
5
6
7
8
diagplots(
  object,
  burnin = NULL,
  plotfun = 2,
  comparison.theta = NULL,
  cols = NULL,
  ...
)

Arguments

object

an object of class hmclearn, usually a result of a call to mh or hmc

burnin

optional numeric parameter for the number of initial MCMC samples to omit from the summary

plotfun

integer 1 or 2 indicating which plots to display. 1 shows trace plots. 2 shows a histogram

comparison.theta

optional numeric vector of true parameter values

cols

optional integer index indicating which parameters to display

...

currently unused

Value

Returns a customized ggplot object

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
# Linear regression example
set.seed(522)
X <- cbind(1, matrix(rnorm(300), ncol=3))
betavals <- c(0.5, -1, 2, -3)
y <- X%*%betavals + rnorm(100, sd=.2)

f <- hmc(N = 1000,
          theta.init = c(rep(0, 4), 1),
          epsilon = 0.01,
          L = 10,
          logPOSTERIOR = linear_posterior,
          glogPOSTERIOR = g_linear_posterior,
          varnames = c(paste0("beta", 0:3), "log_sigma_sq"),
          param=list(y=y, X=X), parallel=FALSE, chains=1)

diagplots(f, burnin=300, comparison.theta=c(betavals, 2*log(.2)))

hmclearn documentation built on Oct. 23, 2020, 8:04 p.m.