ecdf函数_如何从ecdfplot()中提取ecdf值

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

mygroup

ecdfplot(~u, groups=mygroup)

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

解决方案

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).

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值