How do I extract ecdf values out of ecdfplot()

Druss2k picture Druss2k · Aug 29, 2012 · Viewed 9.4k times · Source

If I use the ecdfplot() function of the latticeExtra package how do I get the actual values calculated i.e. the y-values which correspond to the ~x|g input?

I've been looking at ?ecdfplot but there's not discription to it. For the usual highlevel function ecdf() it works with the command plot=FALSE but this does not work for ecdfplot().

The reason I want to use ecdfplot() rather than ecdf() is that I need to calculate the ecdf() values for a grouping variable. I know I could do this handish too but I'm quite convinced that there is a highroad too.

Here a small expample

u <- rnorm(100,0,1)
mygroup <- c(rep("group1",50),rep("group2",50))
ecdfplot(~u, groups=mygroup)

enter image description here

I would like to extract the y-values given each group for the corresponding x-values.

Answer

Joel S picture Joel S · Feb 17, 2015

If you stick with the ecdf() function in the base package, you can simply do as follows:

  1. Create ecdf function with your data:

    fun.ecdf <- ecdf(x) # x is a vector of your data
    
  2. Now use this "ecdf function" to generate the cumulative probabilities of any vector you feed it, including your original, sorted data:

    my.ecdf <- fun.ecdf(sort(x))