18/11/10 17:41:54.09 eRQ4an/O.net
確率密度関数の面積からのクォンタイルでの信頼区間の計算
mKoN2pCIq <- function(N=100 , K=4 , alpha=0.05){
pmf=Vectorize(function(p)seqNp(N,K,p)-seqNp(N,K+1,p))
mode=optimize(pmf,c(0,1),maximum=TRUE)$maximum
auc=integrate(pmf,0,1)$value
pdf=function(x) pmf(x)/auc
curve(pdf(x),bty='l')
mean=integrate(function(x)x*pdf(x),0,1)$value
cdf=function(x) MASS::area(pdf,0,x)
vcdf=Vectorize(cdf)
lwr=uniroot(function(x)vcdf(x)-alpha/2,c(0,mode))$root
upr=uniroot(function(x)vcdf(x)-(1-alpha/2),c(mode,1))$root
c(lower=lwr,mean=mean,mode=mode,upper=upr)
}
mKoN2pCIq(100,4)
> mKoN2pCIq(100,4)
lower mean mode upper
0.1748351 0.3692810 0.3728936 0.5605172
> seq2pCI(100,4)
lower mean mode upper
0.1662099 0.3692810 0.3728936 0.5685943