[R] Monotonic regression in R??
Timothy R. Johnson
trjohns at pullman.com
Sun Mar 4 21:37:03 CET 2001
I wrote an isotonic regression function for S-PLUS (kindly revised by Bill
Venables). It allows for weights and three different approaches to resolving
ties. It uses a non-negative least squares solution rather than the "pool
adjacent violators" algorithm.
It looks like it should work in R EXCEPT that the nnls.fit() function
(non-negative least squares) does not exist in R. Since non-negative least
squares is a quadratic programming problem, one could easily modify this
function to work in R using the quadprog library available at CRAN.
Best regards,
Tim Johnson
--
Assistant Professor of Statistics
University of Idaho
http://www.uidaho.edu/~trjohns
isoreg <- function(x, y, weights = rep(1, length(x)),
untie = c("optimal", "random", "none"),
subset = weights > 0, ...) {
# Purpose: isotonic regression of y on x. Returns fitted values.
# Arguments: x is the predictor and y is the response.
# Weights are optional. Methods of dealing with ties in x
# are 'optimal', 'random', and 'none' (i.e., preserve ties).
# Author: Tim R. Johnson (trjohns at uidaho.edu)
# Revised 24/2/1999
#
# Revised 26/2/2000 by Bill Venables.
#
x.tmp <- x[subset]
y.tmp <- y[subset]
w.tmp <- weights[subset]
n <- length(x.tmp)
untie <- match.arg(untie)
x.tmp <- switch(untie,
optimal = rank(rank(x.tmp) +
sort(runif(n))[rank(rank(y.tmp) + runif(n))]),
random = rank(rank(x.tmp) + runif(n)),
none = rank(x.tmp))
X <- cbind(-1, outer(x.tmp,
if(untie == "none") sort(unique(x.tmp)) else 1:n,
">="))
b <- nnls.fit(X, y.tmp, weights = w.tmp, ...)$coefficients # modify here
for R
y[subset] <- as.vector(X %*% b)
y
}
----- Original Message -----
From: "M. Edward (Ed) Borasky" <znmeb at aracnet.com>
To: <r-help at stat.math.ethz.ch>
Sent: Saturday, March 03, 2001 12.44 PM
Subject: [R] Monotonic regression in R??
> Is there R code somewhere for monotonic regression? I have some functions
> (computer response time curves) that are guaranteed by theory to be
monotonic,
> and some experimental data where they are not. What I'd like to do is plot
a
> smooth monotonic curve through the experimental points. There is no closed
form
> expression for the curve, although there is a recursive difference
equation
> formulation in some simple cases, so ordinary nonlinear regression is not
the
> answer. I have Hardle's book (the title of which escapes me at the moment)
> which gives the algorithm, so I can code it if it doesn't exist already,
but I
> was hoping it was already done.
> --
> znmeb at aracnet.com (M. Edward Borasky) http://www.aracnet.com/~znmeb
>
> If God had meant carrots to be eaten cooked, He would have given rabbits
> fire.
>
> -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.
-.-.-
> r-help mailing list -- Read
http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
> Send "info", "help", or "[un]subscribe"
> (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
>
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._.
_._
>
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list