# Probability of heads given p is less than some value

Say I have a coin with a chance $$p$$ of landing heads where $$p$$ is drawn from the uniform distribution from 0 to 1. Now let's say I have some fixed number $$x \in (0,1)$$. My question is what is the probability that the coin lands on heads, given that $$p \leq x$$? In other words, what is $$\Pr(H | p \leq x)$$?

I first attempted to use Baye's rule $$\Pr(H | p \leq x) = \frac{\Pr(p \leq x | H)\Pr(H)}{\Pr(p \leq x)}$$ but I couldn't deduce the value of $$\Pr(p \leq x | H)$$ or the value of $$\Pr(H)$$.

I then tried using an integral to solve this. My idea was that the possible values of $$p$$ range from 0 to $$x$$ and for each, they have a probability $$p$$ of landing on heads. Hence: $$\int_0^x p \text{ }dp = \frac{x^2}{2}$$ However, my friend tells me the answer is $$\frac{x}{2}$$ because I need to divide the integral by $$x$$ since I need to "average" it. I'm afraid I don't understand what he means.

An explanation of who is right and why would be much appreciated. Also, if one could explain how to find the values of $$\Pr(p \leq x | H)$$ and $$\Pr(H)$$ that would be much appreciated as well.

• Your friend is right :-(. Hope you did not bet on something unaffordable... Do you want step by step guidance, or just the answer?
– Ute
Commented Jul 19, 2023 at 0:24
• @Ute Thank you for the response my friend. Step by step guidance would be very appreciated because I have thought a great deal about his comments but have not been able to figure out why it is true. Commented Jul 19, 2023 at 0:26
• You could set the self-study tag then :-). But let's see if we can do this in a few minutes: There are two random mechanisms in the whole thing, right? Can you tell me what these are?
– Ute
Commented Jul 19, 2023 at 0:27
• First the selection of $p$ and then the event the coin lands on heads given the selected $p$ Commented Jul 19, 2023 at 0:31
• Yeah! (I am taking a bit long, because I did not know where is best to start)  I think your integral approach is easier to start with. How do you usually calculate the mean of a random variable $X$ when you know the density function $f(x)$?
– Ute
Commented Jul 19, 2023 at 0:46

You can continue here if you like.

You said that you need to random variables to generate the outcome, the probability, and then the head-or-tail outcome.

To model this mathematically, we introduce a bit notation.

You have a random variable that gives you the head probability for the coin. Let's call it $$P$$.

Then you have a random variable that gives head or tail. Let's encode this by a r.v. $$Z$$ with values in $$0, 1$$ (tail head). $$Z$$ has a Binomial distribution with size $$1$$ and probability $$P$$. The mean of $$Z$$ is the probability to get head, because $$Z$$ counts successes $$Pr(H) = \mathbb{E} Z.$$

#### Bayes formula

This approach would become quite complicated. You would need to look at the joint distribution of $$P$$ and $$Z$$.

but I couldn't deduce the value of $$Pr(p\leq x|H)$$ or the value of $$Pr(H)$$.

To be able to calculate $$Pr(p \leq x \mid H)$$, which is in terms of the new variables $$Pr(P \leq x\mid Z=1)$$, you would actually need to calculate $$\mathbb{E} Z$$ - you don't win anything with the Bayes formula here. But it looks correct :-)

#### integral approach

As I can see, you have applied the correct formula $$\mathbb{E} Z = \mathbb{E}(\mathbb{E}(Z \mid P))$$ and used used that $$\mathbb{E}(Z \mid P) = P \implies \mathbb{E} Z = \mathbb{E}(\mathbb{E}(Z \mid P)) = \mathbb{E}P.$$ Here, in calculating $$\mathbb{E}P$$, seems to lie the problem,

1. How do you usually calculate the mean of a random variable X when you know the density function f(x)?

$$E(X) = \int xf(x) d x$$

1. You know that has a uniform distribution on $$[0,x]$$. What is its density function $$f$$?

the density is a zero outside the interval $$[0,x]$$ and a constant inside $$[0,x]$$. The constant must be $$1/x$$, so that the density integrates to 1. Thus we have $$f(p) = \frac{1}{x}$$ for $$p\in[0,x]$$ and $$f(p) = 0$$ if $$p$$ is not in the interval.

1. can you now calculate the mean of $$P$$ with the integral form?

$$\mathbb{E}P = \int p\cdot f(p) d p =\int_0^x p\cdot \frac{1}{x} d p = \frac{1}{x}\int_0^x p d p = \frac{1}{x}\cdot \frac{1}{2}x^2 = \frac{x}{2}$$