R/SIR.R

Defines functions SIR

Documented in SIR

#' The SIR Epidemic Model
#' 
#' The derivative function of the SIR Epidemic Model, an example of a two-dimensional autonomous ODE system.
#' 
#' \code{SIR} evaluates the derivative of the following ODE at the point
#' \ifelse{html}{\out{(<i>t</i>, <i>x</i>, <i>y</i>)}}{\eqn{(t, x, y)}}:
#' 
#' \ifelse{html}{\out{<center><i>dx</i>/<i>dt</i> = -<i>&beta;xy</i>,
#' <i>dy</i>/<i>dt</i> = <i>&beta;xy</i> - <i>&nu;y</i>.</center>}}{\deqn{\frac{dx}{dt} = -\beta xy, \frac{dy}{dt} = \beta xy - \nu y.}}
#' 
#' Its format is designed to be compatible with \code{\link[deSolve]{ode}} from the \code{\link[deSolve]{deSolve}} package.
#' 
#' @param t The value of \ifelse{html}{\out{<i>t</i>}}{\eqn{t}}, the independent variable, to evaluate the derivative
#' at. Should be a single number.
#' @param y The values of \ifelse{html}{\out{<i>x</i>}}{\eqn{x}} and 
#' \ifelse{html}{\out{<i>y</i>}}{\eqn{y}}, the dependent
#' variables, to evaluate the derivative at. Should be a vector of length two.
#' @param parameters The values of the parameters of the system. Should be a vector
#' with parameters specified in the following order: \ifelse{html}{\out{<i>&beta;</i>}}{\eqn{\beta}}, \ifelse{html}{\out{<i>&nu;</i>}}{\eqn{\nu}}.
#' @return Returns a list containing the values of the two derivatives
#' at \ifelse{html}{\out{(<i>t</i>, <i>x</i>, <i>y</i>)}}{\eqn{(t, x, y)}}.
#' @author Michael J. Grayling
#' @seealso \code{\link[deSolve]{ode}}
#' @export
SIR <- function(t, y, parameters){
  list(c(-parameters[1]*y[1]*y[2],
         parameters[1]*y[1]*y[2] - parameters[2]*y[2]))
}

Try the phaseR package in your browser

Any scripts or data that you put into this service are public.

phaseR documentation built on Aug. 20, 2018, 5:03 p.m.