im struggleing with a potential easy to solve Problem. I have a dataset with 100k series of coin throws with varying k (throws). For each series I want to compute the the probability for each discrete n-state of getting head (sic!). E.g. 4 throws with the probabilities of c(.25,.5,.25,.75) to throw head. No I would like to calculate of how probable it is to get 0,1,2,3,4 -times head. I assume it is a different variant of a classical multinominal distribution. Is there a easy R command that I could apply or a formula ?
Greetings and Thanks! David
So far I just tried to create a function that hard calcualtes each case, like 3 throws with
prob = c(0.3,0.2,.5)
#only 1 no_sites = (1-.3)(1-.2)(1-.5)
#3 one_site = ((.3)(1-.2)(1-.5)) + ((1-.3)(.2)(1-.5)) + ((1-.3)(1-.2)(.5))
#3
two_sites = ((.3)(.2)(1-.5)) + ((1-.3)(.2)(.5)) + ((.3)(1-.2)(.5))
#1 three_sites = (.3)(.2)(.5)
sum(no_sites, one_site, two_sites, three_sites) = 1
Yet there should be a formula that is able to do so, without annoying hardcoded caclulations.
The sum of Bernouilli distributions is a Poisson Binomial Distribution. There's the package poisbinom
that you can use to calculate those probabilities.
With the vector of probabilities you gave:
install.packages("poisbinom")
library(poisbinom)
pp <- c(.25,.5,.25,.75)
dpoisbinom(4, pp)