I would like to calculate the area between the blue line and the gray diagonal line.
I can calculate the area under the blue line as:
library(zoo)
id <- order(x)
AUC <- sum(diff(x[id])*rollmean(y[id],2))
(thanks to Calculate the Area under a Curve in R)
Any ideas how to find the area between the blue and gray line?
Thanks in advance EC
The area between two curves is calculated by the formula: Area = ∫ba[f(x)−g(x)]dx ∫ a b [ f ( x ) − g ( x ) ] d x which is an absolute value of the area. It can never be negative.
The area between curves is the modulus(area(under blue line) - area(under gray line)) Area under blue line is 1/2(b-a)(f(b)-f(a)) where a and b are Xs of limits and f(a),f(b) are Ys of limits. Finding area under gray line can be done using simpson's rule. see this http://en.wikipedia.org/wiki/Simpson%27s_rule They have given rule as well as implementation + accuracy provided you have arrays of xs and ys.
I hope it helps, Saurabh
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With