如何从Ecdf()返回值中提取Ecdf值? [英] How to extract Ecdf value from the Ecdf() return?

查看:75
本文介绍了如何从Ecdf()返回值中提取Ecdf值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此问题的答案在这里建议应用 ecdf 的一种方法.

The answer for This question here suggest a way by applying ecdf.

但是我使用软件包 Hmisc 中的 Ecdf(),因为它提供了一种方便的方法来制作ccdf(互补累积分布函数)图.(通过将 what 选项设置为"1-F")

However I am using Ecdf() from package Hmisc for it provides a convenient way to do a ccdf(Complementary Cumulative Distribution Function) plot. (by setting the what option to '1-F')

默认情况下, Ecdf()进行绘图并返回包含 x y 的嵌套列表.

By default, Ecdf() does the plot and return a nested list containing x and y.

如何提取某个 x 值的 y 值?然后将其绘制在原始图上?

How can I extract the y value of a certain x value? and then plot it on the original plot?

仅供参考:

 > str(Ecdf(rnorm(20), lwd = 2))
    List of 2
     $ x: num [1:21] -1.46 -1.46 -1.18 -1.17 -1.16 ...
     $ y: num [1:21] 0 0.05 0.1 0.15 0.2 0.25 0.3 0.35 0.4 0.45 ...
     - attr(*, "N")=List of 2
      ..$ n: num 20
      ..$ m: num 0

首先,我正在考虑使用 R列表中建议的方法将此列表转换为data.frame到数据框,但是我的数据很大,并且 rbind 看起来真的很慢.

At first i am considering convert this list to a data.frame using methods suggested from R List to Data Frame, but my data is huge and the rbind seems really slow.

推荐答案

Ecdf 返回一个列表,而 ecdf 返回一个函数.使用R-stats函数 ecdf 比使用受折磨的东西要容易得多: Ecdf(.)$ y [min(which(Ecdf(.)$ x> val))] .如果要从 Ecdf-object 中获取ecdf(x = 0)的值,则应该可以使用:

Ecdf returns a list whereas ecdf returns a function. It's a lot easier to use the R-stats function ecdf than it is to use something tortured like: Ecdf(.)$y[ min(which(Ecdf(.)$x>val))]. If you want the value of ecdf(x=0) from an Ecdf-object then this should work:

 ecdf( Ecdf(rnorm(20), lwd = 2)$x ) (v=0)
[1] 0.5238095

(事实证明,由 ecdf 返回的函数的形式参数为"v".)但是,如果您要使用不太雅致的方法,并且已经将结果分配给名为'的对象,oneEcdf':

(It turns out that the formal parameter for the function returned by ecdf is "v".) But if you want the less elegant method and you already have assigned the result to an object named 'oneEcdf':

oneEcdf <- Ecdf(rnorm(20), lwd = 2)
oneEcdf$y[ min( which(oneEcdf$x > 0 ))]
[1] 0.6

这篇关于如何从Ecdf()返回值中提取Ecdf值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆