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

Description Usage Arguments Details Value Author(s) See Also Examples

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

1
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.

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.

Value

The value of the area under the curve.

Author(s)

Claus Ekstrom ekstrom@life.ku.dk

See Also

approx

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
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)

Example output

[1] 4.5
[1] 4.5
[1] 4.5
[1] 4.75

kulife documentation built on May 2, 2019, 9:53 a.m.

Related to auc in kulife...