Learn R Programming

SimInf (version 6.2.0)

prevalence: Calculate prevalence from a model object with trajectory data

Description

Calculate the proportion of individuals with disease in the population, or the proportion of nodes with at least one diseased individual, or the proportion of individuals with disease in each node.

Usage

prevalence(model, formula, type = c("pop", "nop", "wnp"), node = NULL,
  as.is = FALSE)

Arguments

model

The model with trajectory data to calculate the prevalence from.

formula

A formula that specify the compartments that define the cases with a disease or a condition (numerator), and the compartments that define the entire population of interest (denominator). The left hand side of the formula defines the cases, and the right hand side defines the population, for example, I~S+I+R in a ‘SIR’ model (see ‘Examples’). The . (dot) is expanded to all compartments, for example, I~. is expanded to I~S+I+R in a ‘SIR’ model (see ‘Examples’).

type

The type of prevalence measure to calculate at each time point in tspan: pop (population prevalence) calculates the proportion of the individuals (cases) in the population, nop (node prevalence) calculates the proportion of nodes with at least one case, and wnp (within-node prevalence) calculates the proportion of cases within each node. Default is pop.

node

Indices specifying the subset nodes to include in the calculation of the prevalence. Default is NULL, which includes all nodes.

as.is

The default (as.is = FALSE) is to generate a data.frame with one row per time-step with the prevalence. Using as.is = TRUE returns the result as a matrix, which is the internal format.

Value

A data.frame if as.is = FALSE, else a matrix.

Examples

Run this code
# NOT RUN {
## Create an 'SIR' model with 6 nodes and initialize
## it to run over 10 days.
u0 <- data.frame(S = 100:105, I = c(0, 1, 0, 2, 0, 3), R = rep(0, 6))
model <- SIR(u0 = u0, tspan = 1:10, beta = 0.16, gamma = 0.077)

## Run the model to generate a single stochastic trajectory.
result <- run(model, threads = 1)

## Determine the proportion of infected individuals (cases)
## in the population at the time-points in 'tspan'.
prevalence(result, I~S+I+R)

## Identical result is obtained with the shorthand 'I~.'
prevalence(result, I~.)

## Determine the proportion of nodes with infected individuals at
## the time-points in 'tspan'.
prevalence(result, I~S+I+R, type = "nop")

## Determine the proportion of infected individuals in each node
## at the time-points in 'tspan'.
prevalence(result, I~S+I+R, type = "wnp")
# }

Run the code above in your browser using DataLab