Hi Ken,

Many thanks for the solution to plotting the log-log scale cumulative distribution function Pr(X>=x). With a minor tweak (adding scales argument) and renaming to fit your example, it worked.

x <- c(0.23, 0.09, 0.05, 0.02, 0.38, 1, 0.04, 0.01, 0.17, 0.04, 0.01, 0.17, 0.5)
F <- c(rep(1, 5), rep(2, 4), rep(3, 4))
ecdflt <- function(x) {
        cdf <- as.vector(
        sapply(sort(x, decreasing = TRUE),
              function(y) sum(x >= y)/length(x))
        )
        cbind(sort(x, decreasing = TRUE), cdf)
        }
        
panel.ecdflt <- function(x, logY = TRUE, ...) {
        xy <- ecdflt(x)
        if (logY) xy[, 2] <- log10(xy[, 2])
        panel.xyplot(xy[, 1], xy[, 2], ...)
        }

xyplot(x ~ x | F, scales = list(y = list(log = TRUE), x = list(log = TRUE)),
        panel = function(x, y = NULL, ...){
        panel.ecdflt(x, ...)
        })

Cheers,
Jeff


Ken Knoblauch wrote:
Jeff Stevens <stev0175 <at> googlemail.com> writes:
I have two questions regarding the ecdfplot function in the
latticeExtra package.
1. How can I plot the fraction of values >= x rather than <=x, like
the what = "1-F" argument in the Ecdf function in the Hmisc package?

2. When I try to log-transform the y-axis, I get a warning that it
can't have log Y-scale, and it fails to scale properly:
How can I log-transform the y-axis in ecdfplot?  Here is a test
example of my analysis in R version 2.10.1 in Ubuntu 9.10:
resp <- c(0.23, 0.09, 0.05, 0.02, 0.38, 1, 0.04, 0.01, 0.17, 0.04, 0.01,
0.17, 0.5)
id <- c(rep(1, 5), rep(2, 4), rep(3, 4))
testdata <- data.frame(id, resp)
ecdfplot(~resp | id, data = testdata, scales = list(x = list(relation =
"free",
 log = TRUE),y = list(log =
TRUE)), type = "p")
Warning message:
In densityplot.formula(x = ~resp | id, data = list(id = c(1, 1,  :
  Can't have log Y-scale

If I understand what you are trying to do, I put this together
a while back (which was not optimal but it worked at the
time), but I haven't tested it since.

ecdflt <- function(x) {
        cdf <- as.vector(
sapply(sort(x, decreasing = TRUE), function(y) sum(x >= y)/length(x))
        )
        cbind(sort(x, decreasing = TRUE), cdf)
        }
        
panel.ecdflt <- function(x, logY = TRUE, ...) {
        xy <- ecdflt(x)
        if (logY) xy[, 2] <- log10(xy[, 2])
        panel.xyplot(xy[, 1], xy[, 2], ...)
        }

xyplot(X ~ X | F, panel = function(x, y = NULL, ...){
        panel.ecdflt(x, ...)
        })

Many thanks,
Jeff

--
Jeff Stevens
Research Scientist
Center for Adaptive Behavior and Cognition
Max Planck Institute for Human Development
Lentzealle 94
14195 Berlin, Germany


Jeff Stevens
Center for Adaptive Behavior and Cognition
Max Planck Institute for Human Development
Lentzealle 94
14195 Berlin, Germany

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to