Skip to content

Instantly share code, notes, and snippets.

@toyeiei
Last active January 21, 2019 04:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save toyeiei/4d803ac9f170d5fea9499dc9bd3105b5 to your computer and use it in GitHub Desktop.
Save toyeiei/4d803ac9f170d5fea9499dc9bd3105b5 to your computer and use it in GitHub Desktop.
simple bayes
# get 15 head from 20 draws - fair coin
p_H15_fair <- dbinom(15, 20, prob = 0.50)
# get 15 head from 20 draws - biased coin
p_H15_biased <- dbinom(15, 20, prob = 0.75)
# subjective probability about the coin
p_fair <- 0.4
p_biased <- 1 - p_fair
# bayes theorem
p_fair_H15 <- p_H15_fair * p_fair / (p_H15_fair * p_fair + p_H15_biased * p_biased)
print(p_fair_H15)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment