问题
I need to calculate the area between two curves. I have lots of data, so I'd like to do it programmatically.
Basically, I always have 2 normal distributions, calculated from a mean value and standard deviation. I would then like to calculate how much they intersect. Here is an example of what I mean, and also some code in R (that I don't know).
Is there already a function in matplotlib
or scipy
or some other module that does it for me?
In case I have to implement it myself, I think that I should do:
- find the intersections (there will be max 2)
- see which function is lower before, [between], and after the intersection
- calculate the integral of the lower function and add them all together
Is that right? How can I do the single steps? Are there functions, modules, etc that can help?
回答1:
I don't know R either, but the answer seems to be in the link you provided: just integrate the minimum of your distributions.
You don't need to find intersections, just feed min(f(x), g(x))
to scipy.integrate.quad
.
来源:https://stackoverflow.com/questions/15361125/calculate-area-between-two-curves-that-are-normal-distributions