# Binomial distribution with random number of experiments

I am modelling a process where I repeatedly draw $n$ i.i.d. binary variables $x_i$. The probability of drawing a positive $x_i$ is $P(x_i = 1) = \rho$. Therefore, the probability of drawing $k$ positive $x_i$ out of $n$ trials follows a Binomial distribution, $P(k) = B(k|\rho,n)$. To add complexity, $n$ is also a random variable that follows a Poisson distribution $P(n) = \frac{1}{n!}\lambda^n \text{e}^{-\lambda}$.

Overall, the probability of drawing $k$ positive samples computes as: $$P(k) = \frac{1}{n!}\lambda^n \text{e}^{-\lambda} \begin{pmatrix}n\\k\end{pmatrix} (1-\rho)^{n-k} \rho^k$$.

However, I am interested in the fraction of positive samples, i.e., in $m = \frac{k}{n}$. By simulation the expectation comes out as $\text{E}\{m\} = \rho = \frac{\rho\lambda}{\lambda}$ and that variance is $\text{Var}\{m\} = \frac{\rho(1-\rho)}{\lambda} = \frac{\rho(1-\rho)\lambda}{\lambda^2}$.

The nominator of both $\text{E}\{m\}$ and $\text{Var}\{m\}$ is the same as one would expect from the Binomial distribution, where $n$ is swapped with $\text{E}\{n\} = \lambda$. But why? And why is the denominator $\lambda$ or $\lambda^2$?

First you need to condition on $N > 0$ for this process to be well-defined.
For the variance the formula you have is not correct. If you condition on $N$ and apply the law of total variance then you should get
Regarding your observation about the mean (whose formula is correct), if you're only interested in intuition then consider for a moment the case of $K / n$ where $n$ is fixed and $K \sim$ binomial$(n, p)$. We already know that $\text{E}(K / n) = p$ and this is true independent of the value of n, so the distribution of $n$ should be irrelevant (aside from being positive and integer-valued) if $n$ happens to be random.