hpd function

get the highest posterior density (HPD) interval

get the highest posterior density (HPD) interval

hpd(object, parm, level = 0.95, HPD = TRUE)

Arguments

  • object: the output model from fitting a (network) meta analysis/regression model
  • parm: a specification of which parameters are to be given confidence intervals, either a vector of numbers or a vector of names. If missing, all parameters are considered.
  • level: the probability which the HPD interval will cover
  • HPD: a logical value indicating whether HPD or equal-tailed credible interval should be computed; by default, TRUE

Returns

dataframe containing HPD intervals for the parameters

Details

A 100(1α)100(1-\alpha)% HPD interval for θ\theta is given by

R(πα)=θ:π(θD)πα, R(\pi_\alpha) = {\theta: \pi(\theta| D) \ge \pi_\alpha},

where πα\pi_\alpha is the largest constant that satisfies P(θR(πα))1αP(\theta \in R(\pi_\alpha)) \ge 1-\alpha. hpd computes the HPD interval from an MCMC sample by letting θ(j)\theta_{(j)} be the jjth smallest of the MCMC sample, θi{\theta_i} and denoting

Rj(n)=(θ(j),θ(j+[(1α)n])), R_j(n) = (\theta_{(j)}, \theta_{(j+[(1-\alpha)n])}),

for j=1,2,,n[(1α)n]j=1,2,\ldots,n-[(1-\alpha)n]. Once θi\theta_i's are sorted, the appropriate jj is chosen so that

θ(j+[(1α)n])θ(j)=min1jn[(1α)n](θ(j+[(1α)n])θ(j)). \theta_{(j+[(1-\alpha)n])} - \theta_{(j)} = \min_{1\le j \leq n-[(1-\alpha)n]} (\theta_{(j+[(1-\alpha)n])} - \theta_{(j)}).

References

Chen, M. H., & Shao, Q. M. (1999). Monte Carlo estimation of Bayesian credible and HPD intervals. Journal of Computational and Graphical Statistics, 8(1) , 69-92.

  • Maintainer: Daeyoung Lim
  • License: GPL (>= 3)
  • Last published: 2024-01-24