{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Epidemiological Indicators\n", "In most epidemiological analyses we must start with simple measurements, or indicators about the raw data. In the `epigraphhub.epistats` module, some useful functions to calculate such indicators are provided." ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "ExecuteTime": { "end_time": "2022-09-20T11:34:41.877918Z", "start_time": "2022-09-20T11:34:41.510470Z" } }, "outputs": [], "source": [ "import pandas as pd\n", "from epigraphhub.analysis import epistats as es\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Calculating the posterior prevalence distribution\n", "The prevalence of a disease in a population can be modeled as a binomial random variable :math:`Bin(n,p)`, where a fraction of the cases in the population is the parameter :math:`p` and the population size is the parameter :math:`n`. If we have a prior guess on the proportion, which we can represent as a :math:`Beta(a,b)` distribution, we can obtain the posterior distribution of the prevalence for a point in time as a Beta(a+cases, b+population size-cases) as a result of a conjugate Bayesian analysis.\n" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "ExecuteTime": { "end_time": "2022-09-20T11:34:49.927138Z", "start_time": "2022-09-20T11:34:49.921296Z" } }, "outputs": [ { "data": { "text/plain": [ "0.010000979998040003" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Using a vague prior Beta(1,1)\n", "pdist = es.posterior_prevalence(pop_size=1e6,positives=10000,a=1,b=1)\n", "pdist.mean()" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "ExecuteTime": { "end_time": "2022-09-20T11:34:51.310228Z", "start_time": "2022-09-20T11:34:51.307610Z" } }, "outputs": [ { "data": { "text/plain": [ "9.950342051571256e-05" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "pdist.std()\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Incidence rate\n", "incidence is defined as the number of new cases in a population over a period of time, typically 1 year. The incidence rate is also usually scale to 100k people to facilitate comparisons between localities with different populations.\n" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "ExecuteTime": { "end_time": "2022-09-20T11:34:57.325469Z", "start_time": "2022-09-20T11:34:57.317630Z" } }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
populationcasesincidence_ratio
010005500.0
150005100.0
210000550.0
\n", "
" ], "text/plain": [ " population cases incidence_ratio\n", "0 1000 5 500.0\n", "1 5000 5 100.0\n", "2 10000 5 50.0" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ir = es.incidence_rate([1000, 5000, 10000], [5, 5, 5])\n", "pd.DataFrame({'population': [1000, 5000, 10000],\n", " 'cases': [5, 5, 5],\n", " 'incidence_ratio': ir\n", " })" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Relative Risk or Risk ratio\n", "Is the risk of contracting a disease given exposure to a risk factor. It is calculated from the results of a controlled experiment with Exposed and control groups.\n" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "ExecuteTime": { "end_time": "2022-09-20T11:35:02.302470Z", "start_time": "2022-09-20T11:35:02.300045Z" } }, "outputs": [ { "data": { "text/plain": [ "RelativeRiskResult(relative_risk=2.4495156482861398, exposed_cases=27, exposed_total=122, control_cases=44, control_total=487)" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "result = es.risk_ratio(exposed_cases=27, exposed_total=122, control_cases=44, control_total=487)\n", "result" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "ExecuteTime": { "end_time": "2022-09-20T11:35:03.472184Z", "start_time": "2022-09-20T11:35:03.469937Z" } }, "outputs": [ { "data": { "text/plain": [ "ConfidenceInterval(low=1.5836990926700116, high=3.7886786315466354)" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "result.confidence_interval(confidence_level=0.95)\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "hide_input": false, "kernelspec": { "display_name": "Python 3 (ipykernel)", "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.9.13" }, "latex_envs": { "LaTeX_envs_menu_present": true, "autoclose": false, "autocomplete": true, "bibliofile": "biblio.bib", "cite_by": "apalike", "current_citInitial": 1, "eqLabelWithNumbers": true, "eqNumInitial": 1, "hotkeys": { "equation": "Ctrl-E", "itemize": "Ctrl-I" }, "labels_anchors": false, "latex_user_defs": false, "report_style_numbering": false, "user_envs_cfg": false }, "nbTranslate": { "displayLangs": [ "*" ], "hotkey": "alt-t", "langInMainMenu": true, "sourceLang": "en", "targetLang": "fr", "useGoogleTranslate": true }, "toc": { "base_numbering": 1, "nav_menu": {}, "number_sections": true, "sideBar": true, "skip_h1_title": false, "title_cell": "Table of Contents", "title_sidebar": "Contents", "toc_cell": false, "toc_position": {}, "toc_section_display": true, "toc_window_display": false }, "varInspector": { "cols": { "lenName": 16, "lenType": 16, "lenVar": 40 }, "kernels_config": { "python": { "delete_cmd_postfix": "", "delete_cmd_prefix": "del ", "library": "var_list.py", "varRefreshCmd": "print(var_dic_list())" }, "r": { "delete_cmd_postfix": ") ", "delete_cmd_prefix": "rm(", "library": "var_list.r", "varRefreshCmd": "cat(var_dic_list()) " } }, "types_to_exclude": [ "module", "function", "builtin_function_or_method", "instance", "_Feature" ], "window_display": false }, "vscode": { "interpreter": { "hash": "f9e3a44f2f7108c4b7beba943bd42895a37b8963dbda2768ecd4cf1430c6d52e" } } }, "nbformat": 4, "nbformat_minor": 4 }