{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "### Predicting rare things is hard\n", "\n" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import numpy as np" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Incidence of schizophrenia 0.000163\n" ] } ], "source": [ "schiz_incidence = 16.3 / 100000\n" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Incidence of schizophrenia 0.000163\n", "Specificity: 0.999\n", "Sensitivity: 0.999\n", "True positives: 163\n", "False positives: 1000\n", "True negatives: 998837\n", "False negatives: 0\n", "Positive predictive value: 0.1401\n" ] } ], "source": [ "specificity = .999\n", "sensitivity = .999\n", "n_screened = 1000000\n", "print(f\"Incidence of schizophrenia {schiz_incidence:.04}\")\n", "print(f\"Specificity: {specificity:.04}\")\n", "print(f\"Sensitivity: {sensitivity:.04}\")\n", "\n", "# True positives\n", "tp = n_screened * schiz_incidence * sensitivity\n", "\n", "# False negatives\n", "fn = n_screened * schiz_incidence - tp\n", "\n", "# True negatives\n", "tn = n_screened * (1 - schiz_incidence) * specificity\n", "\n", "# False positives\n", "fp = n_screened * (1 - schiz_incidence) - tn\n", "\n", "\n", "print(f\"True positives: {tp:.0f}\")\n", "print(f\"False positives: {fp:.0f}\")\n", "print(f\"True negatives: {tn:.0f}\")\n", "print(f\"False negatives: {fn:.0f}\")\n", "\n", "# Positive predictive value\n", "ppv = tp / (tp + fp)\n", "print(f\"Positive predictive value: {ppv:.04}\")\n", "\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.12.4" } }, "nbformat": 4, "nbformat_minor": 2 }