Let $X,Y,Z$ be three discrete random variables which I can numerically sample. I need to numerically estimate the probability that $X=Y$ and the probability that $X=Z$. I would like to know whether the algorithm that I describe below is suited to this goal. In particular, I would like to know whether it is acceptable to use the same samples from $X$ to estimate both quantities.


My current algorithm generates $n$ independent samples of each random variable. That is, I generate three vectors:
$$(x\_1,\ldots,x\_n)\\
 (y\_1,\ldots,y\_n)\\
(z\_1,\ldots,z\_n)$$
Associated to these vectors, I define two counting variables as follows,
$$c\_{XY}:=\sum\_{i=1}^n\displaystyle\delta\_{x\_iy\_i}\qquad c\_{XZ}:=\sum\_{i=1}^n\delta\_{x\_iz\_i} $$
where $\delta\_{ij}$ is the [Kronecker delta](https://en.wikipedia.org/wiki/Kronecker_delta).
Finally, I estimate my probabilities in the following way:
$$P(X=Y)\approx \frac{c\_{XY}}{n}\qquad P(X=Z)\approx \frac{c\_{XZ}}{n}$$.


I would greatly appreciate any feedback.



Using common samples to numerically estimate pairwise equality of three random variables
Your two estimators $c\_{XY}/n$ and $c\_{XZ}/n$ are unbiased estimators of $P(X=Y)$ and $P(X=Z)$ respectively. They are not independent, however. Whether that is "acceptable" might depend on what you're using them for.


