Learn R Programming

ROCit (version 2.1.1)

trapezoidarea: Approximate Area with Trapezoid Rule

Description

trapezoidarea calculates the approximated area under curve, using trapezoidal rule.

Usage

trapezoidarea(x, y)

Value

Numeric value of the area under curve approximated with trapezoid rule.

Arguments

x, y

Numeric vectors of same length, representing the x and y coordinates of the points.

Comment

trapezoidarea is used internally in other function(s) of ROCit.

Details

The function approximates the area bounded by the following 4 curves: $$x = a, x = b, y = 0, y = f(x)$$

\(a\) and \(b\) are set at the min and max value of given x coordinates. \((x, y)\) are some points on the \(y = f(x)\) curve.

Examples

Run this code
# Area under rectangle -----------------
trapezoidarea(seq(0, 10), rep(1, 11))

# Area under triangle ------------------
trapezoidarea(seq(0, 10), seq(0, 10))

# Area under normal pdf ----------------
x_vals <- seq(-3, 3, 0.01); y_vals <- dnorm(x_vals)
trapezoidarea(x = x_vals, y = y_vals) # theoretically 1

Run the code above in your browser using DataLab