Reputation: 6409
I would like to calculate the cumulative probability of a binomial series:
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)
Is there any way to do this with a single command?
Upvotes: 5
Views: 9472
Reputation: 66864
For cumulative probability use pbinom
:
pbinom(0:5,5,0.5)
[1] 0.03125 0.18750 0.50000 0.81250 0.96875 1.00000
For individual values, dbinom
:
dbinom(0:5,5,0.5)
[1] 0.03125 0.15625 0.31250 0.31250 0.15625 0.03125
And for summing cumulatively use cumsum
:
cumsum(dbinom(0:5,5,0.5))
[1] 0.03125 0.18750 0.50000 0.81250 0.96875 1.00000
Upvotes: 8