How do I extract ecdf values out of ecdfplot()

房东的猫 提交于 2019-12-05 23:08:45

I know you said you don't want to use ecdf, but in this case it is much easier to use it than to get the data out of the trellis object that ecdfplot returns. (After all, that's all that ecdfplot is doing- it's just doing it behind the scenes).

In the case of your example, the following will get you a matrix of the y values (where x is your entire input u, though you could choose a different one) for each ECDF:

ecdfs = lapply(split(u, mygroup), ecdf)
ys = sapply(ecdfs, function(e) e(u))
# output:
#       group1 group2
#  [1,]   0.52   0.72
#  [2,]   0.68   0.78
#  [3,]   0.62   0.78
#  [4,]   0.66   0.78
#  [5,]   0.72   0.80
#  [6,]   0.86   0.94
#  [7,]   0.10   0.26
#  [8,]   0.90   0.94
# ...

ETA: If you just want each column to correspond to the 50 x-values in that column, you could do:

ys = sapply(split(u, mygroup), function(g) ecdf(g)(g))

(Note that if the number of values in each group aren't identical, this will end up as a list rather than a matrix with columns).

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))
    
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!