R,Python或八度音阶:具有置信区间的经验分位数(反CDF)? [英] R, python or octave: empirical quantile (inverse cdf) with confidence intervals?
问题描述
我正在寻找一个内置函数,该函数可在除MATLAB之外的其他方式中返回样本分位数和估计的置信区间(MATLAB的ecdf
会执行此操作).
I'm looking for a built-in function that returns the sample quantile and an estimated confidence interval in something other than MATLAB (MATLAB's ecdf
does this).
我想R内置了这个功能,但我还没有找到它.
I'm guessing R has this built-in and I just haven't found it yet.
如果您有任何独立的代码可以执行此操作,虽然我希望找到包含在更大的开放代码库中的内容,但是您也可以在这里指向它.
If you have any standalone code to do this, you could also point to it here, though I hope to find something that is included as part of a larger open code base.
-试图摆脱MATLAB.
-Trying to get away from MATLAB.
推荐答案
survfit
函数可用于获取具有置信区间的 survival 函数.由于它只是1-ecdf,因此分位数之间存在直接关系.要使用此功能,您必须创建一个变量,说明您的每个观察结果都是完整的(未经审查):
The survfit
function can be used to get the survival function with confidence intervals. Since it is just 1-ecdf, there is a direct relationship between the quantiles. To use this you have to create a variable that says that each of your observations is complete (not censored):
library(survival)
x <- rexp(10)
ev <- rep(1, length(x))
sf <- survfit(Surv(x,ev)~1)
有输出:
>summary(sf)
Call: survfit(formula = Surv(x, ev) ~ 1)
time n.risk n.event survival std.err lower 95% CI upper 95% CI
-1.4143 10 1 0.9 0.0949 0.7320 1.000
-1.1229 9 1 0.8 0.1265 0.5868 1.000
-0.9396 8 1 0.7 0.1449 0.4665 1.000
-0.4413 7 1 0.6 0.1549 0.3617 0.995
-0.2408 6 1 0.5 0.1581 0.2690 0.929
-0.1698 5 1 0.4 0.1549 0.1872 0.855
0.0613 4 1 0.3 0.1449 0.1164 0.773
0.1983 3 1 0.2 0.1265 0.0579 0.691
0.5199 2 1 0.1 0.0949 0.0156 0.642
0.8067 1 1 0.0 NaN NA NA
实际上,survfit
确实计算了中位数及其置信区间,但没有计算其他分位数:
In fact, survfit
does calculate the median and its confidence interval, but not the other quantiles:
>sf
Call: survfit(formula = Surv(x, ev) ~ 1)
records n.max n.start events median 0.95LCL 0.95UCL
10.000 10.000 10.000 10.000 -0.205 -0.940 NA
survival:::survmean
函数很好地隐藏了计算中位数置信区间的实际工作,您可以使用它来推广到其他分位数.
The actual work for of the calculation of the confidence interval of the median is well hidden in the survival:::survmean
function, which you could probably use to generalize to other quantiles.
这篇关于R,Python或八度音阶:具有置信区间的经验分位数(反CDF)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!