Skip to content

Instantly share code, notes, and snippets.

@Harshit1694
Created July 11, 2019 11:51
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 Harshit1694/1775867933427b49c6902a7cb9c98836 to your computer and use it in GitHub Desktop.
Save Harshit1694/1775867933427b49c6902a7cb9c98836 to your computer and use it in GitHub Desktop.
#Bayes Theorem
cancer <- sample(c('No','Yes'), size=1000, replace=TRUE, prob=c(0.99852,0.00148))
test <- rep(NA, 1000) # creating a dummy variable
test[cancer=='No'] <- sample(c('Negative','Positive'), size=sum(cancer=='No'), replace=TRUE, prob=c(0.99,0.01))
test[cancer=='Yes'] <- sample(c('Negative','Positive'), size=sum(cancer=='Yes'), replace=TRUE, prob=c(0.07, 0.93))
P_cancer_and_pos<-0.00148*0.93
P_no_cancer_and_pos<-0.99852*0.01
Bayes_Theorem<-(P_cancer_and_pos/(P_cancer_and_pos+P_no_cancer_and_pos))
Bayes_Theorem
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment