Overlap calculation in R© Karobben

Overlap calculation in R

overlap

overlap: The overlap package provides functions to calculate and visualize the overlap of two or more density distributions. The overlapEst function can be used to calculate the overlap of two density distributions, while the overlapPlot function can be used to visualize the overlap.

library(overlap)
library(ggplot2)

# Generate two random lists of numbers
set.seed(123)
list1 <- rnorm(100, mean = 5, sd = 1)
list2 <- rnorm(100, mean = 8, sd = 1)

# Calculate overlap density
overlapEst(list1, list2)

ggplot() + geom_density(aes(list1, fill = "list1"), alpha = .5) +
geom_density(aes(list2, fill = "list2"), alpha = .5) + theme_bw()

    Dhat1     Dhat4     Dhat5 
0.2460298        NA        NA 

Density overlapping estimate 1

overlapping

library(overlapping)

# Generate two random lists of numbers
set.seed(123)
list1 <- rnorm(100, mean = 5, sd = 1)
list2 <- rnorm(100, mean = 8, sd = 1)

# Calculate overlap density
overlap(list(list1, list2))
$OV
[1] 0.1431085

I personally believe that this result is more reliable.

Author

Karobben

Posted on

2023-02-14

Updated on

2024-01-11

Licensed under

Comments