Area under the Curve (AUC)Source:
Based on the DescTools
AUC function. It can calculate the area under the curve with a naive algorithm or a more elaborated spline approach. The curve must be given by vectors of xy-coordinates. This function can handle unsorted x values (by sorting x) and ties for the x values (by ignoring duplicates).
Vector of x values.
Vector of y values.
Method to compute the Area Under the Curve (AUC). Can be
"spline". If "trapezoid", the curve is formed by connecting all points by a direct line (composite trapezoid rule). If "step" is chosen then a stepwise connection of two points is used. For calculating the area under a spline interpolation the splinefun function is used in combination with integrate.
Arguments passed to or from other methods.
library(bayestestR) posterior <- distribution_normal(1000) dens <- estimate_density(posterior) dens <- dens[dens$x > 0, ] x <- dens$x y <- dens$y area_under_curve(x, y, method = "trapezoid") #>  0.498307 area_under_curve(x, y, method = "step") #>  0.499534 area_under_curve(x, y, method = "spline") #>  0.498307