40 people arrives at a bus stop at a uniform continuous time between 8:00 and 8:15. The bus arrives at the stop at 8:10, 8:12, and 8:15 with probabilities 0.3, 0.5, and 0.2, respectively and takes everyone at the stop. Let X be the number of people taking the bus. What is the expectation and variance of X?
Intuitively, I am getting $E(X)=40*(0.3*10/15+0.5*12/15+0.2*15/15)=32$. But how can I get the pdf of X to calculate the expectation and variance?
Let $Y \in \{1, 2, 3\}$ represent the arrival time of the bus, with $Y = 1$ representing 8:10, and $Y = 2$ representing 8:12, and $Y = 3$ representing 8:15. Then $$\Pr[Y = 1] = 0.3 \\ \Pr[Y = 2] = 0.5 \\ \Pr[Y = 3] = 0.2.$$ We want to compute $\Pr[X = x]$, the unconditional PMF of the number of passengers the bus takes. To this end, we condition on $Y$. For instance, $\Pr[X = x \mid Y = 1]$ represents the probability that exactly $x$ people arrive at the stop by 8:10. Since the arrivals are uniformly distributed from 8:00 to 8:15, each person arriving has a $2/3$ probability of arriving within the first 10 minutes, and each person's arrival is independent of the arrivals of the other people. Thus, $$X \mid Y = 1 \sim \operatorname{Binomial}(n = 40, p_1 = 2/3)$$ with $$\Pr[X = x \mid Y = 1] = \binom{40}{x} (2/3)^x (1/3)^{40-x}.$$ Similarly, $$X \mid Y = 2 \sim \operatorname{Binomial}(n = 40, p_2 = 4/5).$$ In the final case, $X \mid Y = 3$ is not random: we have $\Pr[X = 40 \mid Y = 3] = 1$, since everyone is assured to arrive by 8:15. Then by the law of total probability, $$\begin{align} \Pr[X = x] &= \sum_{y=1}^3 \Pr[X = x \mid Y = y]\Pr[Y = y] \\ &= \binom{40}{x} \left( \frac{3}{10} (2/3)^x (1/3)^{40-x} + \frac{1}{2} (4/5)^x (1/5)^{40-x} + \frac{1}{5} \mathbb 1(x = 40) \right). \\ \end{align}$$
This PMF does not need to be calculated in order to compute the expectation and variance. To get the expectation, we apply the law of total expectation: $$\begin{align} \operatorname{E}[X] &= \sum_{y=1}^3 \operatorname{E}[X \mid Y = y]\Pr[Y = y] \\ &= n p_1 \Pr[Y = 1] + n p_2 \Pr[Y = 2] + n \Pr[Y = 3] \\ &= 40((2/3)(3/10) + (4/5)(1/2) + (1/5)) \\ &= 32. \end{align}$$ Then to compute the variance, we calculate $$\operatorname{E}[X^2] = \sum_{y=1}^3 \operatorname{E}[X^2 \mid Y = y]\Pr[Y = y]$$ in the same manner as above, noting that for a binomial random variable, $\operatorname{E}[X^2] = np(1-p) + n^2 p^2$. Then we finally use $$\operatorname{Var}[X] = \operatorname{E}[X^2] - \operatorname{E}[X]^2.$$
For the sake of curiosity, the PMF for $X$ is shown in the following table:
$$\begin{array}{c|c} x & \Pr[X = x] \\ \hline 0 & 2.467579 \times 10^{-20} \\ 1 & 1.974063 \times 10^{-18} \\ 2 & 7.698847 \times 10^{-17} \\ 3 & 1.950374 \times 10^{-15} \\ 4 & 3.608193 \times 10^{-14} \\ 5 & 5.195798 \times 10^{-13} \\ 6 & 6.061765 \times 10^{-12} \\ 7 & 5.888572 \times 10^{-11} \\ 8 & 4.858073 \times 10^{-10} \\ 9 & 3.454632 \times 10^{-9} \\ 10 & 2.141874 \times 10^{-8} \\ 11 & 1.168298 \times 10^{-7} \\ 12 & 5.646798 \times 10^{-7} \\ 13 & 2.432489 \times 10^{-6} \\ 14 & 9.382629 \times 10^{-6} \\ 15 & 0.0000325276 \\ 16 & 0.000101656 \\ 17 & 0.000287071 \\ 18 & 0.000733841 \\ 19 & 0.00170041 \\ 20 & 0.00357503 \\ 21 & 0.00682546 \\ 22 & 0.0118443 \\ 23 & 0.0187105 \\ 24 & 0.0269928 \\ 25 & 0.0357957 \\ 26 & 0.0441756 \\ 27 & 0.0517703 \\ 28 & 0.0591383 \\ 29 & 0.067258 \\ 30 & 0.076186 \\ 31 & 0.0838148 \\ 32 & 0.0861411 \\ 33 & 0.079579 \\ 34 & 0.0639085 \\ 35 & 0.0432651 \\ 36 & 0.0238812 \\ 37 & 0.0102935 \\ 38 & 0.00324528 \\ 39 & 0.000665157 \\ 40 & 0.200066 \\ \end{array}$$