Question

I am trying to plot reverse ecdf (what="1-F" equivalent of Ecdf function in Hmisc) using ggplot.

Here is the data:

dat = data.frame(ID = rep(c(1001:1015),each=3),
             Month = rep(c("April", "July", "October")),
             Value = runif(45,2.0,14.6))

I could plot the ecdf for each Month using ggplot2:

ggplot(dat, aes(Value, colour = Month)) + stat_ecdf()

However, I need to plot the reverse ecdf for each month. I tried several ways but couldn't work it out. Any help appreciated!

Best,

db

Was it helpful?

Solution

Better if you can share the data, but try:

series <- rnorm(1000, 200, 50)
n<-ceiling(max(series))
qplot(1:n,1-(ecdf(series)(1:n)))+geom_step()

OTHER TIPS

Two more ways to do this as I was recently working on this for vaccine clinical trials:

  1. Use Hmisc Ecdf. This is straight forward and plots it out though bit difficult to figure out details on changing different elements of the graph.

  2. Calculate cumulative distribution and then 1-cumulative is reverse cumulative. Plot the reverse using ggplot2 using geom_step if you like a step function in the graph. The function below would use ecdf from base r to give you cumulative distribution and then 1-cumulative:

    rcdf <- function (x) {
    cdf <- ecdf(x)
    y <- cdf(x)
    xrcdf <- 1-y
    }
    

in the above rcdf is a user-defined function defined using ecdf.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top