繁体   English   中英

如何使用R获得函数的置信区间

[英]How to get the confidence interval for a function using R

我有一个这样的csv文件,第一列是一个值,第二列是该值出现的次数。 基本上,这是一个概率分布。 现在,我想使用R来计算置信区间。 假设95%置信水平的间隔是多少,90%,85%等的间隔如何?

我搜索了几个小时,找不到合适的方法。 对不起,我很愚蠢。

谢谢,J

听起来好像您需要加权分位数功能。 Hmisc软件包提供了一个:

install.packages("Hmisc")
# the first example from the help page for ?wtd.quantile
set.seed(1)
x <- runif(500)
wts <- sample(1:6, 500, TRUE)
std.dev <- sqrt(wtd.var(x, wts))
wtd.quantile(x, wts)
#-----------    
     0%         25%         50%         75%        100% 
0.001836858 0.262917845 0.482080115 0.747400865 0.996077372 
death <- sample(0:1, 500, TRUE)
plot(wtd.loess.noiter(x, death, wts, type='evaluate'))
describe(~x, weights=wts)
#-----------
x 

 2  Variables      500  Observations
 ---------------------------------------------------------------------------
x 
      n missing  unique    Info    Mean     .05     .10     .25     .50 
   1766       0     500       1   0.502 0.07068 0.11890 0.26292 0.48208 
    .75     .90     .95 
0.74740 0.91162 0.95515 

lowest : 0.001837 0.001933 0.011150 0.013078 0.013390
highest: 0.991839 0.991906 0.992684 0.993749 0.996077 
----------------------------------------------------------------------------
(weights) 
      n missing  unique    Info    Mean 
   1766       0       6    0.95   4.364 

           1   2   3   4   5   6
Frequency 87 138 282 296 465 498
%          5   8  16  17  26  28
----------------------------------------------------------------------------
# describe uses wtd.mean, wtd.quantile, wtd.table

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM