# 21.1: A Simple Example (Section 20.3)


bayes_df = data.frame(prior=NA,
likelihood=NA,
marginal_likelihood=NA,
posterior=NA)

bayes_df$prior <- 1/1000000 nTests <- 3 nPositives <- 3 sensitivity <- 0.99 specificity <- 0.99 bayes_df$likelihood <- dbinom(nPositives, nTests, 0.99)

bayes_df$marginal_likelihood <- dbinom( x = nPositives, size = nTests, prob = sensitivity ) * bayes_df$prior +
dbinom(
x = nPositives,
size = nTests,
prob = 1 - specificity
) *
(1 - bayes_df$prior) bayes_df$posterior <-
(bayes_df$likelihood * bayes_df$prior) /
bayes_df\$marginal_likelihood

21.1: A Simple Example (Section 20.3) is shared under a not declared license and was authored, remixed, and/or curated by Russell A. Poldrack via source content that was edited to conform to the style and standards of the LibreTexts platform; a detailed edit history is available upon request.