21.1: A Simple Example (Section 20.3)

Statistical Thinking for the 21st Century · LibreTexts

0%

Contents

    Text

    Size
    100%
    Theme
    Typeface
    Line length
    Spacing

    From LibreTexts, under CC BY-NC 4.0, as the source states it; its equations are written in TeX, which the PDF shows typeset. This page at LibreTexts.

    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

    This page titled 21.1: A Simple Example (Section 20.3) was last modified on Mon, 11 Jan 2021 05:14:05 GMT and is shared under a CC BY-NC 4.0 license and was authored, remixed, and/or curated by Russell A. Poldrack via source content that was edited to the style and standards of the LibreTexts platform.