Personal note on identity-by-descent

Say there are two allels $A_1$ and $A_2$. There corresponding frequencies are $p$ and $q$. Let $F$ be the probability that two randomly selected alleles are identity-by-descent (IBD).

Calculating IBD probability was always confusing to me because of the difference of $p$ and $p^2$ (same for $q$) when the alleles are IBD and non-IBD. I was trying to think of an additional line that can help me go through it and finally got one.

The usual calculation goes \(\begin{aligned} P(A_1 A_1) &= P(A_1 A_1 \mid \mathrm{IBD}) P (\mathrm{IBD}) + P(A_1 A_1 \mid \mathrm{non-IBD}) P(\mathrm{non-IBD}) \\ &= pF + p^2 (1-F) \end{aligned}\) while I have put an additional line \(\begin{aligned} P(A_1 A_1) &= P(A_1 A_1 \mid \mathrm{IBD}) P (\mathrm{IBD}) + P(A_1 A_1 \mid \mathrm{non-IBD}) P(\mathrm{non-IBD}) \\ &= P(A_1 \mid \mathrm{IBD}, A_1)P(A_1 \mid \mathrm{IBD}) P(\mathrm{IBD}) + P(A_1 A_1 \mid \mathrm{non-IBD}) P(\mathrm{non-IBD}) \\ &= pF + p^2 (1-F) \end{aligned}\) using the Bayes formula ($P(A_1 A_1 \mid \mathrm{IBD}) = P(A_1 \mid \mathrm{IBD}, A_1)P(A_1 \mid \mathrm{IBD})$). To elaborate, once you know that the it is $A_1$ at one haplotype and the other is in IBD with it, the allele at the other takes $A_1$ with probability one and $A_2$ with probability zero.

I hope it might help other people who are struggling to understand it.