P_Alert_PONFL <- 0.904
P_Alert_NonPONFL <- 0.065
P_PONFL <- 1 / 18000
P_NonPONFL <- 1 - P_PONFL

#total probability of an alert
P_Alert <- (P_Alert_PONFL * P_PONFL) + (P_Alert_NonPONFL * P_NonPONFL)

# posterior probability of being a PONFL with alert
P_PONFL_Alert <- (P_Alert_PONFL * P_PONFL) / P_Alert

#  result
P_PONFL_Alert
## [1] 0.0007720959

Calculate the total probability of an alert

\[ \begin{equation} \label{eq:bayes} P(A) = P(A|P')P(P') + P(A|P)P(P) \end{equation} \]

Calculate the posterior probability of being a PONFL given an alert

\[ P(Alert) = P(Alert|PONFL) \cdot P(PONFL) + P(Alert|NonPONFL) \cdot P(NonPONFL) \]

Now we can apply Bayes’ Theorem to find the posterior probability

\[ P(PONFL|Alert) = \frac{P(Alert|PONFL) \cdot P(PONFL)}{P(Alert)} \]

The probability that a person is actually on the no-fly list given that the alarm has gone off is

\[ \begin{equation} \label{eq:bayesfullplugged} P(PONFL|Alert) = \frac{(P_Alert_PONFL)(P_PONFL)}{(P_Alert_NonPONFL)(P_NonPONFL)+(P_Alert_PONFL)(P_PONFL)} = 7.72096\times 10^{-4} \end{equation} \]