slope: Piecewise-linear local slopes given a (non-strictly) monotone...

View source: R/utilities.r

slopeR Documentation

Piecewise-linear local slopes given a (non-strictly) monotone x-y sequence

Description

Estimate monotone piecewise-linear slopes, with the default behavior forbidding zero slope. This behavior is due to the fact that the function is used to invert confidence intervals using the Delta method. The input interval has to be strictly increasing in x, and (non-strictly) monotone in y (increasing or decreasing).

Usage

slope(
  x,
  y,
  outx = x,
  allowZero = FALSE,
  tol = 0.01,
  full = FALSE,
  decreasing = FALSE
)

Arguments

x

numeric or integer: input x values, must be strictly increasing

y

numeric: input y values, must be monotone (can be non-strict) and in line with the direction specified by decreasing

outx

numeric or integer: x values at which slopes are desired (default: same as input values)

allowZero

logical: should zero be allowed in the output? Default FALSE

tol

tolerance level: when allowZero=FALSE, slope below that value is considered zero. Default 1e-2. Might need to change if you use unusual units for x or y.

full

logical: should a more detailed output be provided? Default FALSE (see details under 'Value').

decreasing

logical: is input supposed to be monotone decreasing rather than increasing? Default FALSE

Details

At design points (i.e., the input x values), the function takes the average between the left and right slopes (on the edges the inside slope is technically replicated to the outside). If allowZero=FALSE (default), the algorithm gradually expands the x range over which slope is observed (by increments of one average x spacing), until a positive slope results. If the input is completely flat in y and allowZero=FALSE, the function returns NAs.

Value

If full=FALSE, returns a vector of slopes at the points specified by outx.

If full=TRUE, returns a list with slopes at the design point (rawslopes), the initial guess at output slopes (initial), and the official final ones (final).

See Also

deltaInverse, which uses this function.


cir documentation built on April 27, 2023, 9:05 a.m.