smaa.pvf: Compute piece-wise linear partial value functions

View source: R/smaa.R

smaa.pvfR Documentation

Compute piece-wise linear partial value functions

Description

Given a set of reference levels and their values, compute a linearly interpolated (piece-wise linear) partial value function.

Usage

smaa.pvf(x, cutoffs, values, outOfBounds="error")

Arguments

x

Values to compute the PVF for, a numeric vector

cutoffs

Reference levels (ascending order)

values

Values of the reference levels

outOfBounds

What to do when some of the x are outside the range of the given cutoffs. When "error", throws an error. When "clip", clips to the value of the first or last cutoff. When "interpolate", interpolates according to the closest interval.

Value

A numeric vector the same length as x.

The values are computed by linear interpolation between the values of the two closest reference levels. This has been implemented in C for a dramatic performance improvement.

Author(s)

Gert van Valkenhoef

Examples

x <- c(50, 90, 100, 10, 40, 101, 120)
values <- smaa.pvf(x,
  cutoffs=c(50, 75, 90, 100),
  values=c(1, 0.8, 0.5, 0),
  outOfBounds="clip")
stopifnot(all.equal(values, c(1.0, 0.5, 0.0, 1.0, 1.0, 0.0, 0.0)))

smaa documentation built on April 28, 2023, 5:07 p.m.