Area under curve

· GNU-R
Authors

There are various ways in which you can get R to calculate area under a curve. Some of these are explained in various posts on this thread. Ravi Varadhan wrote up the following function that uses trapezoidal rule for calculating area between a 45 degrees line and a curve. I used it to get gini coefficients from a lorenz curve.

trap.rule-function(x,f) {sum(diff(x)*(f[-1]+f[-length(f)]))/2}

trap.rule(x,f=y-x)

(Area is negative if y(x) is below the 45 degrees line)

 

Technorati:

%d bloggers like this: