I am providing the full question as well my solution below. I'm looking for help with part (d), a simulation question.
Q - Suppose there are two species of Pandas, $T_1$ and $T_2$ which are indistinguishable and exist in equal proportions, but differ in how they lay children. Species $T_1$ gives birth to twins 10% of the time and otherwise lays a single cub. Species $T_2$ lays twins 20% of the time, and otherwise only lays a single cub.
There are two pandas, who are unrelated and of unknown species, Panda X and Panda Y.
a) Panda X has twins the first year. Find the conditional probability that the Panda is species $T_1$.
b) Find the conditional probability that Panda X will have twins again.
c) Suppose there exists a genetic test which correctly identifies pandas as species $T_1$ 80% of the time and correctly identifies species $T_2$ 60% of the time. This test is administered to Panda Y, and the results indicate that the panda is species $T_1$. Find the probability that the first birth from Panda Y results in twins.
d) Verify this through simulation in R.
Answers: (a) and (b) I do not have issues with. Providing part (c) for reference.
c) Follows Bayes laws again, but it is a new panda so we can forget parts a) and b). We use the Bayes rule to get the posterior probability they are type $S_1$ and then use the approach from part (b) to compute the probability the birth is twins. For the first part,
$$P(S_1\mid test) = \frac{P(test\mid S_1)\frac{1}{2}}{P(test\mid S_1)\frac{1}{2} + P(test\mid S_2)\frac{1}{2}} = \frac{\frac{8}{10}\frac{1}{2}}{\frac{8}{10}\frac{1}{2}+\frac{4}{10}\frac{1}{2}} = \frac{{\frac{2}{5}}}{\frac{3}{5}} = \frac{2}{3}$$
since the probability that it is right given it's a $T_1$ is $8/10$ and the probability the test is wrong given that it's a $T_2$ is $4/10.$
My question is, how do I go about part d? I'm aware that I'd have to sample in some way, but considering I don't know how the populations are distributed, I can't take any samples from pre-existing functions within R. Would be great if someone could show me how to solve part d. Many thanks in advance.
sample
or alternatively by generating a uniform byrunif
and comparing it to the probability. $\endgroup$