mdogucu / stats115-wi20-website

Website for Stats 115 course at UCI
0 stars 1 forks source link

A function that might be useful for Bayesian Hypothesis Testing #1

Closed TaneishaArora closed 4 years ago

TaneishaArora commented 4 years ago
Code to compute the prior odds, posterior odds, and Baye's Factor

#Code author: Taneisha Arora

bayes_hypothesis <- function(prior_alpha, prior_beta, n, x, h_pi){

  posterior_alpha <- prior_alpha+x
  posterior_beta <- prior_beta+n-x

  prior_odds <- 
    pbeta(h_pi, prior_alpha, prior_beta, lower.tail = FALSE)/
    (1-pbeta(h_pi, prior_alpha, prior_beta, lower.tail = FALSE))

  posterior_odds <- 
    pbeta(h_pi, posterior_alpha, posterior_beta, lower.tail = FALSE)/
    (1-pbeta(h_pi, posterior_alpha, posterior_beta, lower.tail = FALSE))

  bayes_factor <- posterior_odds/prior_odds

  c("prior odds" = prior_odds, "posterior odds" = posterior_odds, "bayes factor" = bayes_factor)
} 
mdogucu commented 4 years ago

Thank you Taneisha, I will incorporate this with few changes.