Skip to content

Instantly share code, notes, and snippets.

@lgaff
Created March 7, 2013 21:53
Show Gist options
  • Save lgaff/5112170 to your computer and use it in GitHub Desktop.
Save lgaff/5112170 to your computer and use it in GitHub Desktop.
(defn bayes [a b-given-a b-given-c]
; p(a|b ) = p(b | a) * p(b) / p(a)
(let [c (- 1.0 a)] ; Complementary event of a
(/ (* b-given-a a)
(+ (* b-given-a a) (* b-given-c c)))))
(def plots (take 20 (iterate #(+ % 0.005) 0.005)))
(println "Accuracy of a drug test that is 99% sensitive, 99% specific")
(println "(eg. 99% true positive for users, 99% true negative for non-users)")
(print (map #(format "Accuracy if %.2f%% of test set are users: %.3f\n"
(* 100 %)
(bayes % 0.99 0.01)) plots))
Ξ ~ → clojure bayesdrug.clj
Accuracy of a drug test that is 99% sensitive, 99% specific
(eg. 99% true positive for users, 99% true negative for non-users)
Accuracy if 0.50% of test set are users: 0.332
Accuracy if 1.00% of test set are users: 0.500
Accuracy if 1.50% of test set are users: 0.601
Accuracy if 2.00% of test set are users: 0.669
Accuracy if 2.50% of test set are users: 0.717
Accuracy if 3.00% of test set are users: 0.754
Accuracy if 3.50% of test set are users: 0.782
Accuracy if 4.00% of test set are users: 0.805
Accuracy if 4.50% of test set are users: 0.823
Accuracy if 5.00% of test set are users: 0.839
Accuracy if 5.50% of test set are users: 0.852
Accuracy if 6.00% of test set are users: 0.863
Accuracy if 6.50% of test set are users: 0.873
Accuracy if 7.00% of test set are users: 0.882
Accuracy if 7.50% of test set are users: 0.889
Accuracy if 8.00% of test set are users: 0.896
Accuracy if 8.50% of test set are users: 0.902
Accuracy if 9.00% of test set are users: 0.907
Accuracy if 9.50% of test set are users: 0.912
Accuracy if 10.00% of test set are users: 0.917
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment