From 2385fc476ed0fca604e2039df28382ba1106c033 Mon Sep 17 00:00:00 2001 From: Lara Herriott <58111273+laraherriott@users.noreply.github.com> Date: Wed, 4 Oct 2023 20:50:31 +0100 Subject: [PATCH] Change tau to more standard 7 days --- python_examples/R0_inference/learn_R.ipynb | 390 ++++++++++----------- 1 file changed, 191 insertions(+), 199 deletions(-) diff --git a/python_examples/R0_inference/learn_R.ipynb b/python_examples/R0_inference/learn_R.ipynb index fed976d1..792021a6 100644 --- a/python_examples/R0_inference/learn_R.ipynb +++ b/python_examples/R0_inference/learn_R.ipynb @@ -22,7 +22,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 12, "id": "3c186640", "metadata": {}, "outputs": [], @@ -46,7 +46,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 2, "id": "f944a7ab", "metadata": {}, "outputs": [], @@ -68,7 +68,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 3, "id": "922b364f", "metadata": {}, "outputs": [], @@ -90,7 +90,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 10, "id": "d37630e8", "metadata": {}, "outputs": [], @@ -104,7 +104,7 @@ "num_timepoints = len(locally_infected_cases)\n", "\n", "# Set parameters of the prior on Rt and the sliding window\n", - "tau = 3\n", + "tau = 7\n", "a = 1\n", "b = 1/5\n", "\n", @@ -137,7 +137,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 11, "id": "684adbf7", "metadata": {}, "outputs": [ @@ -156,10 +156,6 @@ "name": "Estimated R", "type": "scatter", "x": [ - 4, - 5, - 6, - 7, 8, 9, 10, @@ -185,33 +181,29 @@ 30 ], "y": [ - 11.210910457221274, - 10.123291855032315, - 7.637686814861059, - 6.353777342498756, - 4.740518533386022, - 4.099907865396977, - 4.331146955928072, - 4.871029968355105, - 5.680275662604347, - 5.693030025383368, - 5.974806458617816, - 5.925479284779409, - 6.060076816795219, - 5.976307254606396, - 5.744776460502163, - 5.516350052177704, - 5.194996053845396, - 4.814076073841199, - 4.413397080971373, - 3.998656410149536, - 3.5994394638889475, - 2.881166478521386, - 2.341637598599885, - 1.9670597109748957, - 1.6774026989115614, - 1.586413500266052, - 1.5283034820030326 + 5.088855174527887, + 4.565399918040406, + 4.675048790746537, + 5.066854732222062, + 5.535166072546366, + 5.4420443816780955, + 5.73170860601165, + 5.783554783580007, + 6.012907929689393, + 5.942798945151767, + 5.771516899345458, + 5.563833718146274, + 5.297003351631782, + 4.955803952938899, + 4.584775448744441, + 4.208166027531809, + 3.8386121837163882, + 3.19947048019266, + 2.7224610795282596, + 2.3934364452120107, + 2.1449929988721084, + 1.9522910324504958, + 1.7910901379661752 ] }, { @@ -225,10 +217,6 @@ "opacity": 0.5, "type": "scatter", "x": [ - 4, - 5, - 6, - 7, 8, 9, 10, @@ -274,67 +262,55 @@ 11, 10, 9, - 8, - 7, - 6, - 5, - 4 + 8 ], "y": [ - 5.612230998392108, - 5.901825364104409, - 4.7174991054560556, - 4.1673283261301695, - 3.2555466116886036, - 2.961400329735068, - 3.2569151095551536, - 3.695056962190816, - 4.243566686188017, - 4.142967647965451, - 4.311631665414721, - 4.255882122578549, - 4.348332563683921, - 4.279535914175053, - 4.117338908048573, - 3.9815968928025582, - 3.7826906150345083, - 3.5406566587313204, - 3.285936463904901, - 3.0195032517879286, - 2.762304169700794, - 2.25419739302415, - 1.8902917264173822, - 1.637043392304169, - 1.4420488620538385, - 1.4004202029693777, - 1.3754454437432322, - 1.7395675671248363, - 1.8440931556070796, - 1.992897462868998, - 2.3982313345217725, - 2.9352152419349635, - 3.677962821553434, - 4.647920044970912, - 5.231925726476671, - 5.8442809962506646, - 6.443924726910843, - 7.008231196402436, - 7.486212263745105, - 7.825541106733697, - 8.138303251259034, - 8.237698352623465, - 8.033569605287141, - 8.05711325301866, - 7.584372293362202, - 7.435312553022156, - 6.354286640207897, - 5.739053876179448, - 5.617138187923789, - 6.746967149002446, - 9.391695678141245, - 11.797155179136729, - 16.491332873738077, - 20.23038882688579 + 3.460051829375384, + 3.263788592104874, + 3.462084805036503, + 3.7832610739199954, + 4.094284057203918, + 3.9651498408202266, + 4.168331648537966, + 4.188267128973423, + 4.338313918177827, + 4.2649217651995315, + 4.140740866329341, + 4.01377717718498, + 3.8509213126227793, + 3.6347492648018016, + 3.3988020221321174, + 3.159510303067807, + 2.923433413305926, + 2.4728179651778777, + 2.1658996273076543, + 1.9567109578825357, + 1.7938692818999986, + 1.6652723722681337, + 1.554597749681786, + 2.095916800296777, + 2.3222099060029784, + 2.596754871790581, + 2.9646530361358434, + 3.455222700747595, + 4.111145822608873, + 4.983433464816006, + 5.53432338997289, + 6.093823884524081, + 6.647764591085995, + 7.152328517691955, + 7.549574159769455, + 7.852069471742735, + 8.07074521129568, + 8.13019249429288, + 7.787964948952789, + 7.6928928348733665, + 7.266028521780874, + 7.315897736638222, + 6.688089301268593, + 6.257802196985655, + 6.30306371441353, + 7.295436293360683 ] } ], @@ -1198,7 +1174,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "Average Rt over the first week = 6.928177117760639\n" + "Average Rt over the first week = 5.1578682393961435\n" ] } ], @@ -1263,7 +1239,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 6, "id": "c8e20939", "metadata": {}, "outputs": [], @@ -1327,7 +1303,47 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 8, + "id": "5c9d54f7", + "metadata": {}, + "outputs": [], + "source": [ + "tau = 7\n", + "a = 1\n", + "b = 1/5\n", + "\n", + "# Transform our incidence data into pandas dataframes\n", + "inc_data_strict = pd.DataFrame(\n", + " {\n", + " 'Time': np.arange(num_timepoints_strict),\n", + " 'Incidence Number': locally_infected_cases_strict\n", + " }\n", + ")\n", + "\n", + "imp_data_strict = pd.DataFrame(\n", + " {\n", + " 'Time': np.arange(num_timepoints_strict),\n", + " 'Incidence Number': imported_strict\n", + " }\n", + ")\n", + "\n", + "\n", + "inference_strict = branchpro.LocImpBranchProPosteriorMultSI(\n", + " inc_data=inc_data_strict, \n", + " imported_inc_data=imp_data_strict,\n", + " epsilon=1,\n", + " daily_serial_intervals=serial_intervals,\n", + " alpha=a,\n", + " beta=b)\n", + "\n", + "\n", + "inference_strict.run_inference(tau=tau)\n", + "intervals_strict = inference_strict.get_intervals(central_prob=.95)" + ] + }, + { + "cell_type": "code", + "execution_count": 9, "id": "6356f2f3", "metadata": {}, "outputs": [ @@ -1346,10 +1362,6 @@ "name": "Estimated R", "type": "scatter", "x": [ - 4, - 5, - 6, - 7, 8, 9, 10, @@ -1375,33 +1387,29 @@ 30 ], "y": [ - 6.339135876446108, - 5.151228901174985, - 3.0781468358450588, - 2.084711855410301, - 2.2262846803796768, - 2.574265186150349, - 3.242317140981207, - 3.853081896975847, - 5.089306119403667, - 4.774599529870164, - 4.132996507841874, - 3.723965783403737, - 3.471211880717753, - 3.7142839640288785, - 3.962789156346824, - 4.275708008060806, - 4.229870707468138, - 4.23637723739206, - 4.259635135947053, - 4.367602452630398, - 4.408330162983815, - 3.949594437736872, - 3.5892482352901554, - 3.303163085685887, - 3.0673688493648603, - 2.879717604312475, - 2.69829853966291 + 2.6884672828820007, + 3.017505133817429, + 3.1885207406484875, + 3.3759987104860416, + 4.345774741904275, + 4.274126478161447, + 3.9607209274235724, + 3.7436647088840993, + 3.7322776288403685, + 3.8941455608881084, + 3.993596753878349, + 4.166806483448932, + 4.080960628553019, + 4.137796796186296, + 4.206026903955725, + 4.351481100729856, + 4.377590396174351, + 3.998530987518842, + 3.7038707226417458, + 3.4900668392784655, + 3.3159914485278894, + 3.0940742353322785, + 2.8924834848745093 ] }, { @@ -1415,10 +1423,6 @@ "opacity": 0.5, "type": "scatter", "x": [ - 4, - 5, - 6, - 7, 8, 9, 10, @@ -1464,67 +1468,55 @@ 11, 10, 9, - 8, - 7, - 6, - 5, - 4 + 8 ], "y": [ - 2.8807621197658264, - 2.781431443881825, - 1.7471258747976857, - 1.24084850588315, - 1.4658602904171443, - 1.8245931904196968, - 2.4225384547188207, - 2.9221596574418394, - 3.8576747310310564, - 3.5007079639953855, - 3.02339633683213, - 2.7958281684056576, - 2.671425607466217, - 2.9093495624664794, - 3.104436806549354, - 3.313967415900968, - 3.2364890246539453, - 3.2298644286176645, - 3.251581498831359, - 3.334364851463601, - 3.3567060500506805, - 2.999928451278274, - 2.755244419950051, - 2.583869969919882, - 2.4414315756274845, - 2.325255791324362, - 2.206118889129832, - 3.3232863783814697, - 3.586037155318052, - 3.868815983607845, - 4.213488792640574, - 4.622919104001568, - 5.113190643964366, - 5.694146117842145, - 5.632222095575942, - 5.492586402637646, - 5.459955201588269, - 5.423872413491054, - 5.437865109711182, - 5.022748312820958, - 4.73550692373005, - 4.491271296930166, - 4.903973271061136, - 5.509494251819988, - 6.286306331900218, - 6.54432661489727, - 4.963080868548228, - 4.246560551090343, - 3.5203432188317003, - 3.221058189910733, - 3.2433393319754527, - 4.973012710636336, - 8.674239537755655, - 11.825235821085265 + 1.8233228775228056, + 2.179058110132189, + 2.369170286654658, + 2.5500035172624256, + 3.3420368637693905, + 3.2259579938934424, + 2.9670981757033186, + 2.845443577019176, + 2.881812686890919, + 3.028209564992113, + 3.096771736468661, + 3.215164173189427, + 3.130380396172033, + 3.1734845890237535, + 3.227597476734445, + 3.3327386794245353, + 3.3380657860146954, + 3.040634946379604, + 2.8418130025212545, + 2.7169147767337853, + 2.615391893594439, + 2.4662615611481535, + 2.332566072106705, + 3.601094553216136, + 3.8895742730190195, + 4.198618794670385, + 4.458066244083553, + 4.769908914160719, + 5.171119147501857, + 5.645021959191425, + 5.59443095137128, + 5.401382818962838, + 5.314646280558898, + 5.233529404479479, + 5.324087128542277, + 5.091509536345915, + 4.971459327926039, + 4.800672916253612, + 4.8669571781238865, + 5.174663691562602, + 5.526588220888103, + 5.572392475390817, + 4.389572109306665, + 4.2058219401733234, + 4.085067303646036, + 3.8251833404289846 ] } ], @@ -2388,7 +2380,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "Average Rt over the first week = 3.5280129251982406\n" + "Average Rt over the first week = 3.550159145046179\n" ] } ], @@ -2446,7 +2438,7 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 13, "id": "17f2c7ad", "metadata": {}, "outputs": [],