Learn R Programming

flux (version 0.2-0)

auc: Calculate the area under a line(curve).

Description

Calculates the area under a curve (integral) following the trapezoid rule.

Usage

auc(x, y, thresh = NULL, dens = 100)

Arguments

x
Numerical vector giving the x cordinates of the points of the line (curve).
y
Numerical vector giving the x cordinates of the points of the line (curve). One can calculate the integral of a fitted line through giving a vector to x that spans xlim with small intervalls and predicting the y coordinates with
thresh
Threshold below which area is not calculated. When below threshold data represent proper data you'll want to substract the areas below the zero line from the area above the zero line to integrate the area under the curve. When data below thresh
dens
By default the scatter points are densified with factor 100. This makes sense when a threshold is set, to increase accuracy.

Value

  • Returns a numeric value that expresses the area under the curve. The unit depends from the input.

encoding

UTF-8

See Also

trapz, integrate

Examples

Run this code
## Construct a data set (Imagine 2-hourly ghg emission data
## (methane) measured during a day).
## The emission vector (data in mg CH4 / m2*h) as a time series.
ghg <- ts(c(12.3, 14.7, 17.3, 13.2, 8.5, 7.7, 6.4, 3.2, 19.8, 
22.3, 24.7, 15.6, 17.4), start=0, end=24, frequency=0.5)
## Have a look at the emission development.
plot(ghg)
## Calculate what has been emitted that day
## Assuming that emissions develop linearly between
## measurements
auc(time(ghg), ghg)

## The effect of below.zero:
## Shift data, so that we have negative emissions (immissions)
ghg <- ghg-10
## See the difference
plot(ghg)
abline(h=0)
## With thresh = NULL the negative emissions are subtracted
## from the positive emissions
auc(time(ghg), ghg)
## With thresh = 0 the negative emissions are set to 0
## and only the emissions >= 0 are counted.
auc(time(ghg), ghg, thresh = 0)

Run the code above in your browser using DataLab