pava {Iso} | R Documentation |
Linear order isotonic regression.
Description
The “pool adjacent violators algorithm” (PAVA) is applied to calculate the isotonic regression of a set of data, with respect to the usual increasing (or decreasing) linear ordering on the indices.
Usage
pava(y, w, decreasing=FALSE, long.out=FALSE, stepfun=FALSE)
pava.sa(y, w, decreasing=FALSE, long.out=FALSE, stepfun=FALSE)
Arguments
y |
Vector of data whose isotonic regression is to be calculated. |
w |
Optional vector of weights to be used for calculating a weighted isotonic regression; if w is not given, all weights are taken to equal 1. |
decreasing |
Logical scalar; should the isotonic regression be calculated with respect to decreasing (rather than increasing) order? |
long.out |
Logical argument controlling the nature of the value returned. |
stepfun |
Logical scalar; if |
Details
The function pava()
uses dynamically loading of a fortran
subroutine "pava" to effect the computations. The function pava.sa()
("sa" for "stand-alone") does all of the computations in raw R. Thus
pava.sa()
could be considerably slower for large data sets.
The x
values for the step function returned by these functions
(if stepfun
is TRUE
) are thought of as being 1, 2,
..., n=length(y)
. The knots of the step function are the
x
values (indices) following changes in the y
values (i.e. the starting indices of the level sets, except for the
first level set). The y
value corresponding to the first level
set is the “left hand” value of y
or yleft
.
The step function is formed using the default arguments of stepfun()
.
In particular it is right continuous.
Value
If long.out is TRUE then the result returned consists of a list whose components are:
y |
the fitted values |
w |
the final weights |
tr |
a set of indices made up of the smallest index in each level set, which thus "keeps track" of the level sets. |
h |
a step function which represents the results of the isotonic
regression. This component is present only if
|
If long.out
is FALSE
and stepfun
is TRUE
then only the step function is returned.
If long.out
and stepfun
are both FALSE
then only
the vector of fitted values is returned.
Author(s)
Rolf Turner rolfturner@posteo.net
References
Robertson, T., Wright, F. T. and Dykstra, R. L. (1988). Order Restricted Statistical Inference. Wiley, New York.
See Also
Examples
# Increasing order:
y <- (1:20) + rnorm(20)
ystar <- pava(y)
plot(y)
lines(ystar,type='s')
# Decreasing order:
z <- NULL
for(i in 4:8) {
z <- c(z,rep(8-i+1,i)+0.05*(0:(i-1)))
}
zstar <- pava(z,decreasing=TRUE)
plot(z)
lines(zstar,type='s')
# Using the stepfunction:
zstar <- pava(z,decreasing=TRUE,stepfun=TRUE)
plot(z)
plot(zstar,add=TRUE,verticals=FALSE,pch=20,col.points="red")