HPD: Calculate highest posterior density interval

Description Usage Arguments Details Value Author(s) References Examples

View source: R/ouput.R

Description

This function calculates the Bayesian highest posterior density interval (HPD) based on a parameters' posterior sample.

Usage

1
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 IRT_twin of this package.

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

1
2
3
4
5
6
7
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))

Example output

Loading required package: foreign
Loading required package: coda
Loading required package: matrixStats
Loading required package: rjags
Linked to JAGS 4.2.0
Loaded modules: basemod,bugs
[1] 0.09020 0.19399
         [,1]     [,2]    [,3]
[1,] -0.11234 -0.54743 0.40879
[2,] -0.03832 -0.47062 0.48190

BayesTwin documentation built on May 2, 2019, 8:05 a.m.