Skip to content

Commit

Permalink
Create notebook to plot sojourn time distributions
Browse files Browse the repository at this point in the history
  • Loading branch information
romain-ragonnet committed Aug 2, 2023
1 parent c4c4429 commit c8d9bfe
Showing 1 changed file with 81 additions and 0 deletions.
81 changes: 81 additions & 0 deletions notebooks/user/rragonnet/utils/sojourn_distribution.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from scipy import stats\n",
"from numpy import linspace\n",
"import matplotlib.pyplot as plt"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Average sojourn time\n",
"mean_period = 5.\n",
"\n",
"# number of serial compartments to compare (list can be extended)\n",
"n_comps_to_compare = [1, 4]"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"fig, axes = plt.subplots(1, len(n_comps_to_compare), figsize=(5.*len(n_comps_to_compare), 4))\n",
"x_min, x_max = 0., 14\n",
"x = linspace(x_min, x_max, 1000)\n",
"\n",
"for i, n_comps in enumerate(n_comps_to_compare):\n",
" ax = axes[i]\n",
" distri = stats.gamma(a=n_comps, scale=mean_period / n_comps)\n",
" ax.fill_between(x, distri.pdf(x), alpha=.5, color='blue')\n",
" ax.set_xlabel(\"days\")\n",
" ax.set_title(f\"{n_comps} compartment(s)\")\n",
"\n",
" # Print some percentages\n",
" print(f\"Using {n_comps} compartment(s):\")\n",
" for quantile in [7., 10., 14.]:\n",
" perc_greater = round(100* (1 - distri.cdf(quantile)))\n",
" print(f\"\\t{perc_greater}% have sojourn time > {quantile} days\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "summer2",
"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.10.11"
},
"orig_nbformat": 4
},
"nbformat": 4,
"nbformat_minor": 2
}

0 comments on commit c8d9bfe

Please sign in to comment.