Functional overlap between two TPD distributions (Bhattacharyya coefficient).
overlapF <- function(x, y) {
if (!identical(x$eval.points, y$eval.points)) stop("Not identical eval points!")
TPDx <- x$estimate
if (class(x$eval.points) == "list") {
x$eval.points <- expand.grid(x$eval.points)
}
cellEdge <- numeric()
for (i in 1:ncol(x$eval.points)) {
cellEdge[i] <- unique(x$eval.points[, i])[2] - unique(x$eval.points[, i])[1]
}
cellSizex <- prod(cellEdge)
TPDx <- TPDx * cellSizex
TPDx <- TPDx / sum(TPDx)
TPDy <- y$estimate
TPDy <- TPDy * cellSizex
TPDy <- TPDy / sum(TPDy)
OL <- sum(pmin(TPDx, TPDy))
return(OL)
}