This function calculates the highest density interval (HDI) for a given set of samples. The HDI is the interval that contains a specified proportion (default 95%) of the highest density values from the distribution.
Details
The function first sorts the input data and computes the necessary quantiles using inear interpolation. It then identifies the interval that contains the highest density, ensuring that the HDI encompasses the specified probability mass. Note that this function does not support the case where two or more separate HDIs exist.