Learn R Programming

kulife (version 0.1-14)

auc: Compute the area under the curve for two vectors.

Description

Compute the area under the curve using linear interpolation for two vectors where one corresponds to the x values and the other corresponds to the y values.

Usage

auc(x, y, from = min(x), to = max(x), ...)

Arguments

x
a numeric vector of x values.
y
a numeric vector of y values of the same length as x.
from
The value from where to start calculating the area under the curve. Defaults to the smallest x value.
to
The value from where to end the calculation of the area under the curve. Defaults to the smallest y value.
...
additional arguments passed on to approxfun. In particular rule can be set to determine how values outside the range of x is handled.

Value

Details

auc is implemented using the approx function together with the composite trapezoid rule. approx creates a function that performs the linear interpolation between points and the trapezoid rule calculates the numerical integral, and by combining these we can handle unsorted time values, missing observations, ties for the time values, and integrating over part of the area or even outside the area.

See Also

approx

Examples

Run this code
x <- 1:4
y <- c(0, 1, 1, 5)
auc(x, y)

# AUC from 0 to max(x) where we allow for extrapolation
auc(x, y, from=0, rule=2)    

# Use value 0 to the left
auc(x, y, from=0, rule=2, yleft=0)

# Use 1/2 to the left
auc(x, y, from=0, rule=2, yleft=.5)

Run the code above in your browser using DataLab