HPD {BayesTwin} | R Documentation |
Calculate highest posterior density interval
Description
This function calculates the Bayesian highest posterior density interval (HPD) based on a parameters' posterior sample.
Usage
HPD(sample, cred_int = 0.95)
Arguments
sample |
A vector representing draws from the target distribution of the paramter of interest, as produced by the main function |
cred_int |
The desired accuracy of the HPD. Default value is 0.95 for 95%. |
Details
The highest posterior density interval (HPD, see e.g. Box & Tia, 1992) contains the required mass such that all points within the interval have a higher probability density than points outside of the interval.
The function expects as input a vector representing draws from the target distribution of the paramter of interest, such as produced by the main function IRT_twin
of this package.
The result is a vector consisiting of two values, the first value representing the lower bound of the HPD and the second value representing the upper bound.
Value
A vector of length 2 with the lower (first value) and upper (second value) bound of the HPD.
Author(s)
Inga Schwabe
References
Box, G., & Tiao, G. (1992). Bayesian inference in statistical analysis. New York: John Wiley & Sons.
Examples
data(results)
#Obtain the 95% HPD for additive genetic variance
HPD(results$samples_var_a)
#Obtain the 90% HPD for all item difficulty parameters
apply(results$samples_item_b, 1, function (x) HPD(x, 0.90))