[R] Empirical Complementary CDF
Shiazy Fuzzy
shiazy at gmail.com
Wed May 30 20:44:33 CEST 2007
Hi all,
I'd like to plot an empirical LLCD (log-log-CCDF, where CCDF == 1-CDF).
It seems ecdf() and plot(ecdf()) can't do it. I'd like to reuse some
graphics features of ECDF plot.
The fastest way I've found is to copy&paste the ecdf code and writing
this function:
--- [R-code] ---
eccdf <- function(x)
{
x <- sort(x)
n <- length(x)
if (n < 1)
stop("'x' must have 1 or more non-missing values")
vals <- sort(unique(x))
rval <- approxfun(vals, 1-cumsum(tabulate(match(x, vals)))/n, #[CHANGED]
method = "constant", yleft = 1, yright = 0, f = 0, ties = "ordered")
class(rval) <- c("eccdf", "stepfun", class(rval)) #[CHANGED]
attr(rval, "call") <- sys.call()
rval
}
--- [/R-code] ---
and the rewriting the plot.ecdf function:
--- [R code] ---
plot.eccdf <- function (x, ..., ylab = "1-Fn(x)", verticals = FALSE,
col.01line = "gray70") #CHANGED
{
plot.stepfun(x, ..., ylab = ylab, verticals = verticals)
abline(h = c(0, 1), col = col.01line, lty = 2)
}
--- [/R-code] ---
So, is there a even faster way to get it?
Thank you so much!!
-- Marco
More information about the R-help
mailing list