# How to find the probability of getting heads of an unknown coin when having the number of heads and trials?

As a new learner of the statistics I have a basic question. Suppose we have a coin without knowing whether it is biased or not and accordingly we don't know the probability of getting a head in a single flip. We have replicated a 1000 coin-flip over 5000 times. The mean observed number of heads is calculated as follows

$$\frac{1}{5000} \sum_{i=1}^{5000} a_i$$

where each $$a_i$$ is the number of heads observed in each 1000 flips. What is a robust way of calculating the accurate probability of getting a head in a single coin flip?

Thanks.

• What is a 1000 coin-flip over 5000 times? In what way is this different from "the whole observe number of heads". Are you saying you have recorded 5 million individual flips ... or the result of 5000 summaries of 1000 flips. How many points in the dataset? And what is the distribution of results? Dec 23, 2019 at 20:54
• @wolfies Thank you for your comment. It is now edited. Dec 23, 2019 at 22:44
• Can you please provide the code you use? Do you use a distinct seed for each of $5000$ sequences of $1000$ coin flips? Dec 24, 2019 at 12:14

Let's call a binary experiment one with only two possible outcomes: success and failure.

The binomial distribution $$Bin(n,p)$$ with parameters $$n \in \mathbb{N}_0$$ and $$p \in (0,1)$$ is the probability distribution of the number of successes in a sequence of $$n$$ independent binary experiments, where the probability of success for each individual experiment equals $$p$$. Coin flips are your experiments and heads are your successes.

If $$X \sim Bin(n,p)$$, then $$P(X=k)= {n\choose k}p^k(1-p)^{n-k}$$ for $$k \in \{0,...,n\}$$.

The likelihood function of the binomial model is just the probability function viewed as a function of the parameters of the model given the data, i.e. the result of the experiments, $$\mathcal{L}(p|n,x) = {n\choose x}p^x(1-p)^{n-x},$$ where $$x$$ is the number of successes and $$n$$ the number of experiments.

Its natural logarithm is given by $$\log{n\choose x} + x \log{p} + (n-x) \log(1-p).$$

To maximise $$\log{\mathcal{L}(p|n,x)}$$ as a function of $$p$$ is to maximise $$x \log{p} + (n-x) \log(1-p).$$

By differentiation, one finds that the maximum (log-)likelihood is achieved by $$\hat{p}=\frac{x}{n}$$.

So, the maximum likelihood estimator of the probability of a success in a single experiment is the proportion of successes over all independent experiments. This estimator is known to be unbiased. See https://en.wikipedia.org/wiki/Binomial_distribution for helpful documentation.

• That might be one way to look at the problem. But another way might be to ask what is the a priori distribution of biased coins compared to unbiased ones. Do the coins come straight out the mint? Have you come across other biased coins? Or is this an unbiased coin with a sampling distribution just like any random variable? Unless the data suggested clearly otherwise, my natural predilection would be to assume the coin is in fact unbiased, or to weight the calculation by the distribution of biased/unbiased coins. Dec 23, 2019 at 17:04
• Out of habit, I do not take a Bayesian approach unless one has explicit prior knowledge and a relatively small sample size. Dec 23, 2019 at 17:18
• You may also wish to check how the coins were flipped, and whether the sampler is inducing bias in his/her flipping. Never trust a flipper. Dec 23, 2019 at 17:21
• Within the context of this website, I think it is reasonable to assume proper experimental procedure for such a problem. Dec 23, 2019 at 17:55
• The OP says they have "replicated a 1000 coin-flip over 5000 times". How does that match the model you have suggested above? Dec 23, 2019 at 20:55