Learn R Programming

ExtremeRisks (version 0.0.5)

plotBayes: Plot empirical Bayes inference results for continuous and discrete generalized Pareto distribution

Description

Given a sample of posterior draws of the scale or shape parameter, return a histogram on the density scale for the posterior distribution along with a theoretical prior and posterior comparison curve based on the MLE, pointwise Wald-based normal 95% confidence intervals for the mean of the sample, and pointwise credible intervals (asymmetric by design).

Usage

plotBayes(
  x,
  mle,
  alpha = 0.05,
  param = c("scale", "shape"),
  cols = c("mediumseagreen", "goldenrod", "gold4"),
  ...
)

Value

NULL; used to create a plot

Arguments

x

a vector of posterior samples

mle

vector of length 2 containing the maximum likelihood estimator for the scale and shape parameters, respectively (only used if param="scale")

alpha

level for intervals. Default to 0.05 giving 95% confidence intervals

param

character string indicating the parameter. Default: c("scale", "shape")

cols

vector of length three containing colors for posterior mean, confidence intervals, and credible intervals. Default to c("mediumseagreen", "goldenrod", "gold4")

...

additional arguments for plotting function; only xlab is allowed

Examples

Run this code
if (FALSE) {
# generate data
set.seed(1234)
n <- 500
samp <- evd::rfrechet(n, 0, 3, 4)
# set effective sample size and threshold
k <- 50
threshold <- sort(samp, decreasing = TRUE)[k+1]
# preliminary mle estimates of scale and shape parameters
mlest <- evd::fpot(samp, threshold)
# empirical bayes procedure
proc <- estPOT(
 samp,
 k = k,
 pn = c(0.01, 0.005),
 type = "continuous",
 method = "bayesian",
 prior = "empirical",
 start = as.list(mlest$estimate),
 sig0 = 0.1)
plotBayes(
  proc$post_sample[,1],
  mlest$estimate,
  param = "scale")
plotBayes(
  proc$post_sample[,2],
  param = "shape")
}

Run the code above in your browser using DataLab