# Formula for producing probability that binomial distribution was created with different odds of producing heads?

Given a binomial distribution of, say, unfair coin flips:

1 1 0 1 0 0 1 1 0


I'm trying to determine: given an x% probability of flipping heads, what are the odds of producing this result?

What formula can I use? So the input would be the number of heads, total flips, and heads probability. And the output would be the odds of producing that result given those parameters.

I would be interested in both a discrete formula (finding the odds at a given % probability for heads) and for ALL probabilities of heads 0 to 1 as a normal distribution type thing. Either or both would be much appreciated!

I also intend to use this in a Python project, so I if anyone knows a corresponding function I would love to be alerted to it.

• If you want the probability of this exact sequence, it is $x^5*(1-x)^4$, since you have 5 events and 4 non-events. Commented Jul 6, 2022 at 7:00

You are looking for the probability mass function (PMF) of the binomial distribution. Feed in the number of successes (typically denoted $$k$$, here you have $$k=5$$ ones), the total number of draws (typically denoted $$n$$, here $$n=9$$) and the hypothesized success probability $$p$$.

In Python, you can use scipy.stats.binom.pmf():

from scipy.stats import binom
binom.pmf(5,9,0.5)
# 0.24609374999999992
binom.pmf(5,9,5/9)
# 0.2601824190046903
binom.pmf(5,9,0.6)
# 0.2508226559999999


Unsurprisingly, the probability for $$p=\frac{k}{n}=\frac{5}{9}$$ is largest - that is the maximum likelihood estimate of $$p$$, after all.

You can also evaluate the PMF directly:

from scipy.special import comb
comb(9,5)*0.6**5*(1-0.6)**(9-5)
# 0.25082265600000003

• Thank you so much! I got it working great. Commented Jul 6, 2022 at 9:02