trapezoidarea: Approximate Area with Trapezoid Rule

View source: R/trap_MLestimates.R

trapezoidareaR Documentation

Approximate Area with Trapezoid Rule

Description

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

Usage

trapezoidarea(x, y)

Arguments

x, y

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

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.

Value

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

Comment

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

Examples

# 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


ROCit documentation built on May 29, 2024, 2:15 a.m.