Skip to content
Advertisement

Finding areas of non-overlapping edges of two distributions

I am trying to find a way to calculate the overlapping (intersection) and non-overlapping areas of two distributions. Based on some posts (like this: FINDING AREA) I could figure out how to calculate the intersection of the two plots. But I had no luck finding the non-overlapping part.
Given this example distributions:

JavaScript

I wonder how I can calculate the areas between the two distributions at the edges?
I should mention that I have the data as well (if that is something that I could do with the data itself). enter image description here

Advertisement

Answer

Taking inspiration from the answer you linked, from data you should compute kde curves through scipy.stats.gaussian_kde:

JavaScript

Then you need to find intersection points between the kde curves:

JavaScript

where idx is the list of index of intersection points.
Finally, you can compute area through numpy.trapz, using index previously computed to slice x, kde1_x and kde2_x:

JavaScript

Complete Code

JavaScript

enter image description here

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement