{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "## Reed-Frost Model in R\n", "\n", "*Author*: Sangeeta Bhatia\n", "\n", "*Date*: 2018-10-01" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "- `xcurr` is the number of suspectible individuals at step j.\n", "- `ycurr` is the number of infected individuals at step j.\n", "- `q` is the probability that a suspectible individual \n", "escapes infection.\n", "- `ynext` is the number of infected persons at step j + 1.\n", "\n", "Everyone who is infected at step j becomes immune (or dies) at step j + 1. Thus at step j + 1, the number of susceptibles is `xcurr-ynext`. The following function gives the probability that the number of infected persons at \n", "$j+1$ is `ynext`." ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "reed_frost <- function(xcurr, ycurr, q, ynext) {\n", " pescape <- q^ycurr\n", " pynext <- choose(xcurr, ynext) *\n", " (1 - pescape)^ynext *\n", " pescape^(xcurr - ynext)\n", " pynext\n", "} " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The number of infected people at a time step can be no greater \n", "than the number of suspectibles at the current time step.\n", "So a sanity check for our code would for this number to be 0.\n" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/html": [ "0" ], "text/latex": [ "0" ], "text/markdown": [ "0" ], "text/plain": [ "[1] 0" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "reed_frost(10, 5, 0.5, 11)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "If the probability of escaping an infection is 1, then the \n", "probability that the number of infected at next time is 0 is 1.\n", "Similarly at the other extreme, if probability of escaping an\n", "infection is 0, then every susceptible becomes infected and \n", "the number of infected at next time is `xcurr`." ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/html": [ "