1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
|
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/epi.R, R/sir.R
\name{time_bins}
\alias{time_bins}
\alias{time_bins.sir}
\alias{median.sir}
\alias{quantile.sir}
\alias{sir}
\title{SIR model on graphs}
\usage{
time_bins(x, middle = TRUE)
\method{time_bins}{sir}(x, middle = TRUE)
\method{median}{sir}(x, na.rm = FALSE, ...)
\method{quantile}{sir}(x, comp = c("NI", "NS", "NR"), prob, ...)
sir(graph, beta, gamma, no.sim = 100)
}
\arguments{
\item{x}{A \code{sir} object, returned by the \code{sir()} function.}
\item{middle}{Logical scalar, whether to return the middle of the time bins,
or the boundaries.}
\item{na.rm}{Logical scalar, whether to ignore \code{NA} values. \code{sir}
objects do not contain any \code{NA} values currently, so this argument is
effectively ignored.}
\item{\dots}{Additional arguments, ignored currently.}
\item{comp}{Character scalar. The component to calculate the quantile of.
\code{NI} is infected agents, \code{NS} is susceptibles, \code{NR} stands
for recovered.}
\item{prob}{Numeric vector of probabilities, in [0,1], they specify the
quantiles to calculate.}
\item{graph}{The graph to run the model on. If directed, then edge
directions are ignored and a warning is given.}
\item{beta}{Non-negative scalar. The rate of infection of an individual that
is susceptible and has a single infected neighbor. The infection rate of a
susceptible individual with n infected neighbors is n times beta. Formally
this is the rate parameter of an exponential distribution.}
\item{gamma}{Positive scalar. The rate of recovery of an infected
individual. Formally, this is the rate parameter of an exponential
distribution.}
\item{no.sim}{Integer scalar, the number simulation runs to perform.}
}
\value{
For \code{sir()} the results are returned in an object of class
\sQuote{\code{sir}}, which is a list, with one element for each simulation.
Each simulation is itself a list with the following elements. They are all
numeric vectors, with equal length: \describe{
\item{times}{The times of the events.}
\item{NS}{The number of susceptibles in the population, over time.}
\item{NI}{The number of infected individuals in the population, over
time.}
\item{NR}{The number of recovered individuals in the population, over
time.}
}
Function \code{time_bins()} returns a numeric vector, the middle or the
boundaries of the time bins, depending on the \code{middle} argument.
\code{median} returns a list of three named numeric vectors, \code{NS},
\code{NI} and \code{NR}. The names within the vectors are created from the
time bins.
\code{quantile} returns the same vector as \code{median} (but only one, the
one requested) if only one quantile is requested. If multiple quantiles are
requested, then a list of these vectors is returned, one for each quantile.
}
\description{
Run simulations for an SIR (susceptible-infected-recovered) model, on a
graph
}
\details{
The SIR model is a simple model from epidemiology. The individuals of the
population might be in three states: susceptible, infected and recovered.
Recovered people are assumed to be immune to the disease. Susceptibles
become infected with a rate that depends on their number of infected
neighbors. Infected people become recovered with a constant rate.
The function \code{sir()} simulates the model. This function runs multiple
simulations, all starting with a single uniformly randomly chosen infected
individual. A simulation is stopped when no infected individuals are left.
Function \code{time_bins()} bins the simulation steps, using the
Freedman-Diaconis heuristics to determine the bin width.
Function \code{median} and \code{quantile} calculate the median and
quantiles of the results, respectively, in bins calculated with
\code{time_bins()}.
}
\examples{
g <- sample_gnm(100, 100)
sm <- sir(g, beta = 5, gamma = 1)
plot(sm)
}
\references{
Bailey, Norman T. J. (1975). The mathematical theory of
infectious diseases and its applications (2nd ed.). London: Griffin.
}
\seealso{
\code{\link[=plot.sir]{plot.sir()}} to conveniently plot the results
Processes on graphs
\code{\link{plot.sir}()}
}
\author{
Gabor Csardi \email{csardi.gabor@gmail.com}. Eric Kolaczyk
(\url{http://math.bu.edu/people/kolaczyk/}) wrote the initial version in R.
}
\concept{processes}
\keyword{graphs}
\section{Related documentation in the C library}{\href{https://igraph.org/c/html/latest/igraph-Spatial-Games.html#igraph_sir}{\code{igraph_sir()}}.}
|