P_B_A <- 0.904
P_A <- 1 / 18000
P_B_notA <- 0.065
P_notA <- 1 - P_A

Solution

P_B <- (P_B_A * P_A) + (P_B_notA * P_notA)
P_B
## [1] 0.06504661
P_A_B <- (P_B_A * P_A) / P_B
P_A_B
## [1] 0.0007720959
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) \] \[ P(PONFL|Alert) = \frac{P(Alert|PONFL) \cdot P(PONFL)}{P(Alert)} \]

\[ \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} \]