- Definition:
- A framework for drawing statistical conclusions based on the ideas of Bayesian probability is known as Bayesian statistics.
2024-03-22
illustrates in mathematical terms how previous convictions or odds are revised in light of fresh information.
Formula: \[ P(A|B) = \frac{P(B|A) \times P(A)}{P(B)} \]
library(plotly)
## Warning: package 'plotly' was built under R version 4.3.3
## Loading required package: ggplot2
## ## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2': ## ## last_plot
## The following object is masked from 'package:stats': ## ## filter
## The following object is masked from 'package:graphics': ## ## layout
prior_probs <- seq(0.01, 0.1, length.out = 20)
test_accuracies <- seq(0.8, 1, length.out = 20)
grid <- expand.grid(P_D = prior_probs, P_T_given_D = test_accuracies)
posterior_probs <- (grid$P_T_given_D * grid$P_D) / (grid$P_T_given_D * grid$P_D + 0.05 * (1 - grid$P_D))
plot <- plot_ly(grid, x = ~P_D, y = ~P_T_given_D, z = ~posterior_probs, type = "scatter3d", mode = "markers",
marker = list(size = 5))
plot <- plot %>% layout(scene = list(xaxis = list(title = "Prior Probability of Having Disease"),
yaxis = list(title = "Test Accuracy"),
zaxis = list(title = "Posterior Probability of Having Disease")))
plot
ggplot(data.frame(prior_prob = prior_probs, posterior_prob = posterior_probs), aes(x = prior_prob, y = posterior_prob)) +geom_line() +labs(title = "Posterior Probability vs Prior Probability",x = "Prior Probability of Having Disease", y = "Posterior Probability of Having Disease Given Positive Test Result")
ggplot(data.frame(test_accuracy = test_accuracies, posterior_prob = posterior_probs), aes(x = test_accuracy, y = posterior_prob)) + geom_line() + labs(title = "Posterior Probability vs Test Accuracy", x = "Test Accuracy", y = "Posterior Probability of Having Disease Given Positive Test Result")