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).
slope(
x,
y,
outx = x,
allowZero = FALSE,
tol = 0.01,
full = FALSE,
decreasing = FALSE
)
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
).
numeric or integer: input x values, must be strictly increasing
numeric: input y values, must be monotone (can be non-strict) and in line with the direction specified by decreasing
numeric or integer: x values at which slopes are desired (default: same as input values)
logical: should zero be allowed in the output? Default FALSE
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.
logical: should a more detailed output be provided? Default FALSE
(see details under 'Value').
logical: is input supposed to be monotone decreasing rather than increasing? Default FALSE
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 NA
s.
deltaInverse
, which uses this function.