簡體   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