Learn R Programming

smaa (version 0.3-3)

smaa.pvf: 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")

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.

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.

Author

Gert van Valkenhoef

Examples

Run this code
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)))

Run the code above in your browser using DataLab