Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
228 changes: 114 additions & 114 deletions _book/r-session-03.html

Large diffs are not rendered by default.

Binary file modified _book/r-session-03_files/figure-html/unnamed-chunk-30-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified _book/r-session-03_files/figure-html/unnamed-chunk-43-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions _book/search.json
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@
"href": "r-session-03.html",
"title": "\n8  R Session 03\n",
"section": "",
"text": "8.1 Setup\nCodelibrary(here)\nlibrary(rio)\nlibrary(deSolve)\nlibrary(tidyverse)\nlibrary(ggtext)\nlibrary(gt)\nCodetheme_set(theme_minimal())\nCode# Loads the datasets: flu, measles, niamey, plauge\nflu <- rio::import(\n \"https://raw.githubusercontent.com/arnold-c/SISMID-Module-02_2023/main/data/flu.csv\"\n)\nniamey <- rio::import(\n \"https://raw.githubusercontent.com/arnold-c/SISMID-Module-02_2023/main/data/niamey.csv\"\n)\n# flu <- rio::import(here::here(\"data\", \"flu.csv\"))\n# niamey <- rio::import(here::here(\"data\", \"niamey.csv\"))",
"text": "8.1 Setup\nCodelibrary(here)\nlibrary(rio)\nlibrary(deSolve)\nlibrary(tidyverse)\nlibrary(ggtext)\nlibrary(gt)\nCodetheme_set(theme_minimal())\nCode# Loads the datasets: flu, measles, niamey, plauge\nflu <- rio::import(\n \"https://raw.githubusercontent.com/arnold-c/SISMID-Module-02_2025/main/data/flu.csv\"\n)\nniamey <- rio::import(\n \"https://raw.githubusercontent.com/arnold-c/SISMID-Module-02_2025/main/data/niamey.csv\"\n)\n# flu <- rio::import(here::here(\"data\", \"flu.csv\"))\n# niamey <- rio::import(here::here(\"data\", \"niamey.csv\"))",
"crumbs": [
"Day 2",
"<span class='chapter-number'>8</span>  <span class='chapter-title'>R Session 03</span>"
Expand All @@ -555,7 +555,7 @@
"href": "r-session-03.html#estimating-r_0-from-the-final-outbreak-size",
"title": "\n8  R Session 03\n",
"section": "\n8.3 Estimating \\(R_0\\) From The Final Outbreak Size",
"text": "8.3 Estimating \\(R_0\\) From The Final Outbreak Size\nOur first approach is to estimate \\(R_0\\) from the final outbreak size. Although unhelpful at the early stages of an epidemic (before the final epidemic size is observed), this method is nonetheless a useful tool for post hoc analysis. The method is general and can be motivated by the argument listed in (Keeling and Rohani 2008):\nFirst, we assume that the epidemic is started by a single infectious individual in a completely susceptible population. On average, this individual infects \\(R_0\\) others. The probability a particular individual escaped infection is therefore \\(e^{-R_0 / N}\\).\nIf \\(Z\\) individuals have been infected, the probability of an individual escaping infection from all potential sources is \\(e^{-Z R_0 / N}\\). It follows that at the end of the epidemic a proportion \\(R(\\infty) = Z / N\\) have been infected and the fraction remaining susceptible is \\(S(\\infty) = e^{-R(\\infty) R_0}\\), which is equal to \\(2 - R(\\infty)\\).\n\n\n\n\n\n\nNote\n\n\n\n\n\n\\(S(\\infty) = e^{-R(\\infty) R_0}\\) can be calculated by acknowledging that at equilibrium (\\(t = \\infty\\)), \\(S(\\infty) = 1 - R(\\infty) = Z / N\\), so substituting \\(R(\\infty)\\) into \\(1 - e^{-Z R_0 / N}\\) gives the desired result.\nIt could also be calculated by dividing \\(\\frac{\\dd{S}}{\\dd{t}}\\) by \\(\\frac{\\dd{R}}{\\dd{t}}\\):\n\\[\\begin{aligned}\n\\frac{\\dd{S}}{\\dd{R}} &= - \\frac{\\beta S}{\\gamma} \\\\\n&= - R_0 S\n\\end{aligned}\\]\nwhich is a separable differential equation, so can be integrated as follows:\n\\[\\begin{aligned}\n- \\int_{0}^{t} \\frac{1}{R_0 S} \\dd{S} &= \\int_{0}^{t} \\dd{R} \\\\\n- \\frac{1}{R_0} \\left(\\ln{S(t)} - \\ln{S(0)} \\right) &= R(t) - \\cancelto{0}{R(0)} \\\\\n\\ln{S(t)} &= \\ln{S(0)} - R_0 R(t) \\\\\nS(t) &= S(0) e^{-R_0 R(t)}\n\n\\end{aligned}\\]\n\n\n\nPutting this together, we get:\n\\[\n1 - R(\\infty) - e^{-R(\\infty) R_0} = 0\n\\]\nRearranging, we have the estimator\n\\[\n \\hat{R_0} = \\frac{\\ln(1 - Z / N)}{-Z / N},\n\\]\nwhich, in this case, evaluates to \\(\\frac{\\ln(1 - 512 / 764)}{-512 / 764} = 1.655\\).\n\n8.3.1 Exercise 1\nThis equation shows the important one-to-one relationship between \\(R_0\\) and the final epidemic size. Plot the relationship between the total epidemic size and \\(R_0\\) for the complete range of values between 0 and 1.",
"text": "8.3 Estimating \\(R_0\\) From The Final Outbreak Size\nOur first approach is to estimate \\(R_0\\) from the final outbreak size. Although unhelpful at the early stages of an epidemic (before the final epidemic size is observed), this method is nonetheless a useful tool for post hoc analysis. The method is general and can be motivated by the argument listed in (Keeling and Rohani 2008):\nFirst, we assume that the epidemic is started by a single infectious individual in a completely susceptible population. On average, this individual infects \\(R_0\\) others. The probability a particular individual escaped infection is therefore \\(e^{-R_0 / N}\\).\nIf \\(Z\\) individuals have been infected, the probability of an individual escaping infection from all potential sources is \\(e^{-Z R_0 / N}\\). It follows that at the end of the epidemic a proportion \\(R(\\infty) = Z / N\\) have been infected and the fraction remaining susceptible is \\(S(\\infty) = e^{-R(\\infty) R_0}\\), which is equal to \\(1 - R(\\infty)\\).\n\n\n\n\n\n\nNote\n\n\n\n\n\n\\(S(\\infty) = e^{-R(\\infty) R_0}\\) can be calculated by acknowledging that at equilibrium (\\(t = \\infty\\)), \\(S(\\infty) = 1 - R(\\infty) = Z / N\\), so substituting \\(R(\\infty)\\) into \\(1 - e^{-Z R_0 / N}\\) gives the desired result.\nIt could also be calculated by dividing \\(\\frac{\\dd{S}}{\\dd{t}}\\) by \\(\\frac{\\dd{R}}{\\dd{t}}\\):\n\\[\\begin{aligned}\n\\frac{\\dd{S}}{\\dd{R}} &= - \\frac{\\beta S}{\\gamma} \\\\\n&= - R_0 S\n\\end{aligned}\\]\nwhich is a separable differential equation, so can be integrated as follows:\n\\[\\begin{aligned}\n- \\int_{0}^{t} \\frac{1}{R_0 S} \\dd{S} &= \\int_{0}^{t} \\dd{R} \\\\\n- \\frac{1}{R_0} \\left(\\ln{S(t)} - \\ln{S(0)} \\right) &= R(t) - \\cancelto{0}{R(0)} \\\\\n\\ln{S(t)} &= \\ln{S(0)} - R_0 R(t) \\\\\nS(t) &= S(0) e^{-R_0 R(t)}\n\n\\end{aligned}\\]\n\n\n\nPutting this together, we get:\n\\[\n1 - R(\\infty) - e^{-R(\\infty) R_0} = 0\n\\]\nRearranging, we have the estimator\n\\[\n \\hat{R_0} = \\frac{\\ln(1 - Z / N)}{-Z / N},\n\\]\nwhich, in this case, evaluates to \\(\\frac{\\ln(1 - 512 / 764)}{-512 / 764} = 1.655\\).\n\n8.3.1 Exercise 1\nThis equation shows the important one-to-one relationship between \\(R_0\\) and the final epidemic size. Plot the relationship between the total epidemic size and \\(R_0\\) for the complete range of values between 0 and 1.",
"crumbs": [
"Day 2",
"<span class='chapter-number'>8</span>  <span class='chapter-title'>R Session 03</span>"
Expand Down
4 changes: 2 additions & 2 deletions _freeze/r-session-03/execute-results/html.json

Large diffs are not rendered by default.

Binary file modified _freeze/r-session-03/figure-html/unnamed-chunk-30-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified _freeze/r-session-03/figure-html/unnamed-chunk-43-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion r-session-03.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ On average, this individual infects $R_0$ others.
The probability a particular individual escaped infection is therefore $e^{-R_0 / N}$.

If $Z$ individuals have been infected, the probability of an individual escaping infection from all potential sources is $e^{-Z R_0 / N}$.
It follows that at the end of the epidemic a proportion $R(\infty) = Z / N$ have been infected and the fraction remaining susceptible is $S(\infty) = e^{-R(\infty) R_0}$, which is equal to $2 - R(\infty)$.
It follows that at the end of the epidemic a proportion $R(\infty) = Z / N$ have been infected and the fraction remaining susceptible is $S(\infty) = e^{-R(\infty) R_0}$, which is equal to $1 - R(\infty)$.

::: {.callout-note collapse="true"}
$S(\infty) = e^{-R(\infty) R_0}$ can be calculated by acknowledging that at equilibrium ($t = \infty$), $S(\infty) = 1 - R(\infty) = Z / N$, so substituting $R(\infty)$ into $1 - e^{-Z R_0 / N}$ gives the desired result.
Expand Down
Binary file modified r-session-03_files/figure-html/unnamed-chunk-30-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified r-session-03_files/figure-html/unnamed-chunk-43-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.