Created
October 28, 2020 16:47
-
-
Save J08nY/03bfc960d41bf1e2668be3a7a850e925 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 24, | |
"metadata": { | |
"ExecuteTime": { | |
"end_time": "2020-10-28T16:36:07.071910Z", | |
"start_time": "2020-10-28T16:36:07.064192Z" | |
} | |
}, | |
"outputs": [], | |
"source": [ | |
"from ipywidgets import interact, interactive, fixed, interact_manual\n", | |
"import ipywidgets as widgets\n", | |
"from IPython.display import display, HTML" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 27, | |
"metadata": { | |
"ExecuteTime": { | |
"end_time": "2020-10-28T16:37:37.728387Z", | |
"start_time": "2020-10-28T16:37:37.697984Z" | |
} | |
}, | |
"outputs": [], | |
"source": [ | |
"pop = widgets.IntText(value=4_400_000, description=\"Populácia\")\n", | |
"attendance = widgets.FloatSlider(value=0.7, min=0, step=0.02, max=1, description=\"Účasť\")\n", | |
"true_infected = widgets.IntText(value=50_000, description=\"Nakazení\")\n", | |
"sensitivity = widgets.FloatSlider(value=0.67, min=0.3, step=0.02, max=1, description=\"Senzitivita testu\", readout_format=\".3f\")\n", | |
"specificity = widgets.FloatSlider(value=0.995, min=0.9, step=0.002, max=1, description=\"Špecificita testu\", readout_format=\".3f\")\n", | |
"\n", | |
"def compute(population, attendance, infected, sensitivity, specificity):\n", | |
" tested_population = population * attendance\n", | |
" # Assumption that attendance is uniform among infected and non-infected\n", | |
" tested_infected = infected * attendance\n", | |
" tested_clean = tested_population - tested_infected\n", | |
" \n", | |
" # Calculate the true/false and negative/positive from the tested sample, with given sensitivity and specificity\n", | |
" true_clean = tested_clean * specificity\n", | |
" false_infected = tested_clean * (1 - specificity)\n", | |
" true_infected = tested_infected * sensitivity\n", | |
" false_clean = tested_infected * (1 - sensitivity)\n", | |
" \n", | |
" # Calculate the missed infected\n", | |
" missed_infected = infected * (1 - attendance)\n", | |
" display(HTML(f\"\"\"<table>\n", | |
" <thead>\n", | |
" <tr><th>True positive</th><th>False positive</th><th>True negative</th><th>False negative</th><th>Missed positive</th></tr>\n", | |
" </thead>\n", | |
" <tr>\n", | |
" <td>{round(true_infected)}</td><td>{round(false_infected)}</td><td>{round(true_clean)}</td><td>{round(false_clean)}</td><td>{round(missed_infected)}</td>\n", | |
" </tr></table>\"\"\"))" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 30, | |
"metadata": { | |
"ExecuteTime": { | |
"end_time": "2020-10-28T16:41:15.763328Z", | |
"start_time": "2020-10-28T16:41:15.729535Z" | |
} | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"application/vnd.jupyter.widget-view+json": { | |
"model_id": "d707e059afc24a029e92462d79dbbb0d", | |
"version_major": 2, | |
"version_minor": 0 | |
}, | |
"text/plain": [ | |
"interactive(children=(IntText(value=4400000, description='Populácia'), FloatSlider(value=0.32, description='Úč…" | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
} | |
], | |
"source": [ | |
"interactive(compute, population=pop, attendance=attendance, infected=true_infected, sensitivity=sensitivity, specificity=specificity)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
} | |
], | |
"metadata": { | |
"@webio": { | |
"lastCommId": "66229aa642fa420e8f7b4d3f6c9de5a5", | |
"lastKernelId": "f4a2050d-6128-42fa-8b36-a0e54759b78c" | |
}, | |
"hide_input": false, | |
"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.8.6" | |
}, | |
"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 | |
}, | |
"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 | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 4 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment