计算R中的累积二项式概率

时间:2013-03-01 14:37:54

标签: r

我想计算二项式系列的累积概率:

a=choose(5,0)*0.5^0*0.5^5
b=choose(5,1)*0.5^1*0.5^4
c=choose(5,2)*0.5^2*0.5^3
d=choose(5,3)*0.5^3*0.5^2
e=choose(5,4)*0.5^4*0.5^1
f=choose(5,5)*0.5^5*0.5^0

cumulative=sum(a,b,c,d,e,f)

有没有办法用一个命令做到这一点?

1 个答案:

答案 0 :(得分:3)

累积概率使用pbinom

pbinom(0:5,5,0.5)
[1] 0.03125 0.18750 0.50000 0.81250 0.96875 1.00000

对于个别值,dbinom

dbinom(0:5,5,0.5)
[1] 0.03125 0.15625 0.31250 0.31250 0.15625 0.03125

总结累计使用cumsum

cumsum(dbinom(0:5,5,0.5))
[1] 0.03125 0.18750 0.50000 0.81250 0.96875 1.00000