Learn R Programming

cir (version 2.1.1)

slope: 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, 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

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

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).

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.

See Also

deltaInverse, which uses this function.