> ## Documentation Index
> Fetch the complete documentation index at: https://v1-learn.neoartd.my.id/llms.txt
> Use this file to discover all available pages before exploring further.

# Bayes' Theorem

### Example

<Card>
  $1.$ We have two boxes.\
  $~~~~~$a) The first contains two green balls and seven red balls\
  $~~~~~$b) The second contains four green balls and three red balls.\
  $2.$ Bob selects a ball by first choosing one of the two boxes at random.\
  $3.$ He then selects one of the balls in this box at random.\
  $4.$ If Bob has selected a red ball, what is the probability that he selected a ball from the first box?

  <br />

  Solution:

  $1.$ Let\
  $~~~~~$a) $E$ be the event that Bob has chosen a red ball\
  $~~~~~$b) $\overline{E}$ be the event that Bob has chosen a green ball\
  $~~~~~$c) $F$ be the event that Bob has chosen a ball from the first box\
  $~~~~~$d) $\overline{F}$ be the event that Bob has chosen a ball from the second box.

  $2.$ We want to find $p(F|E)$, the probability that the ball Bob selected came from the first box, given it is red

  $~~~~~ p(F|E) = \dfrac{p(F \cap E)}{p(E)}$

  <br />

  ![gambar1](https://i.ibb.co/h7tdjWF/Screenshot-2024-05-05-075627.png)
  ![gambar1](https://i.ibb.co/YXz1SmS/Screenshot-2024-05-05-075637.png)
</Card>

## Bayes' Theorem

Suppose that $E$ and $F$ are events from a sample space $S$ such that $p(E) \neq 0$ and $p(F) \neq 0$. Then

$~~~~~ p(F|E) = \dfrac{p(E|F) \cdot p(F)}{p(E|F) \cdot p(F) + p(E|\overline{F}) \cdot p(\overline{F})}$

### Example

<Card>
  Suppose that one person in 100,000 has a particular rare disease for
  which there is a fairly accurate diagnostic test. This test is correct 99.0%
  of the time when given to a person selected at random who has the
  disease; it is correct 99.5% of the time when given to a person selected
  at random who does not have the disease. Given this information can
  we find

  $~~~~~$a) the probability that a person who tests positive for the disease has the disease?

  $~~~~~$b) the probability that a person who tests negative for the disease does not have the disease?

  Should a person who tests positive be very concerned that he or she
  has the disease?

  <br />

  Solution:

  Let

  $~~~~~$a) $F$ be the event that a person selected at random has the disease

  $~~~~~$b) $E$ be the event that a person selected at random tests positive for the disease.

  We want to compute $p(F|E)$. To use Bayes' theorem to compute $p(F|E)$, we need to find $p(E|F)$, $p(E|\overline{F})$, $p(F)$, and $p(\overline{F})$.

  <CardGroup cols={1}>
    <Card icon="a">
      We know that one person in 100,000 has this disease, so $p(F) = \dfrac{1}{100000} = 0.00001$ and $p(\overline{F}) = 1 - p(F) = 0.99999$.

      <br />

      Because a person who has the disease tests positive 99% of the time, we know that $p(E|F) = 0.99$.

      <br />

      This is the probability of a true positive, that a person with the disease tests positive. It follows that $p(\overline{E}|F) = 1 - p(E|F) = 1 - 0.99 = 0.01$; this is the probability of a false negative, that a person with the disease tests negative.

      <br />

      Furthermore, because a person who does not have the disease tests negative 99.5% of the time, we know that $p(\overline{E}|\overline{F}) = 0.995$. This is the probability of a true negative, that a person without the disease tests negative.

      <br />

      Finally, we see that $p(E|\overline{F}) = 1 - p(\overline{E}|\overline{F}) = 1 - 0.995 = 0.005$. This is the probability of a false positive, that a person without the disease tests positive.

      <br />

      The probability that a person who tests positive for the disease actually has the disease is $p(F|E)$. By Bayes' theorem, we have

      <br />

      $~~~~~ p(F|E) = \dfrac{p(E|F) \cdot p(F)}{p(E|F) \cdot p(F) + p(E|\overline{F}) \cdot p(\overline{F})}$

      <br />

      $~~~~~ p(F|E) = \dfrac{0.99 \cdot 0.00001}{0.99 \cdot 0.00001 + 0.005 \cdot 0.99999} \approx 0.002$
    </Card>

    <Card icon="b">
      The probability that someone who tests negative for the disease does not have the disease is $p(F|E)$. By Bayes' theorem, we know that

      <br />

      $~~~~~ p(\overline{F}|\overline{E}) = \dfrac{p(\overline{E}|\overline{F}) \cdot p(\overline{F})}{p(\overline{E}|\overline{F}) \cdot p(\overline{F}) + p(\overline{E}|F) \cdot p(F)}$

      <br />

      $~~~~~ p(\overline{F}|\overline{E}) = \dfrac{0.995 \cdot 0.99999}{0.995 \cdot 0.99999 + 0.01 \cdot 0.00001} \approx 0.99998$

      <br />

      Consequently, 99.99999% of the people who test negative really do not have the disease.
    </Card>
  </CardGroup>

  In part (a) we showed that only 0.2% of people who test
  positive for the disease actually have the disease. People
  who test positive for the diseases should not be overly
  concerned that they actually have the disease
</Card>
