# prevalence: Calculate prevalence from a model object with trajectory data In SimInf: A Framework for Data-Driven Stochastic Disease Spread Simulations

## 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

 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16``` ```prevalence( model, formula, level = 1, index = NULL, format = c("data.frame", "matrix") ) ## S4 method for signature 'SimInf_model,formula' prevalence( model, formula, level = 1, index = NULL, format = c("data.frame", "matrix") ) ```

## Arguments

 `model` The `model` with trajectory data to calculate the prevalence from. `formula` A formula that specifies the compartments that define the cases with a disease or that have a specific characteristic (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’). The formula can also contain a condition (indicated by `|`) for each node and time step to further control the population to include in the calculation, for example, `I ~ . | R == 0` to calculate the prevalence when the recovered is zero in a ‘SIR’ model. The condition must evaluate to `TRUE` or `FALSE` in each node and time step. Note that if the denominator is zero, the prevalence is `NaN`. `level` The level at which the prevalence is calculated at each time point in `tspan`. 1 (population prevalence): calculates the proportion of the individuals (cases) in the population. 2 (node prevalence): calculates the proportion of nodes with at least one case. 3 (within-node prevalence): calculates the proportion of cases within each node. Default is `1`. `index` Indices specifying the subset of nodes to include in the calculation of the prevalence. Default is ```index = NULL```, which includes all nodes. `format` The default (`format = "data.frame"`) is to generate a `data.frame` with one row per time-step with the prevalence. Using `format = "matrix"` returns the result as a matrix.

## Value

A `data.frame` if `format = "data.frame"`, else a matrix.

## Examples

 ``` 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``` ```## 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) ## 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, level = 2) ## Determine the proportion of infected individuals in each node ## at the time-points in 'tspan'. prevalence(result, I ~ S + I + R, level = 3) ## Determine the proportion of infected individuals in each node ## at the time-points in 'tspan' when the number of recovered is ## zero. prevalence(result, I ~ S + I + R | R == 0, level = 3) ```

SimInf documentation built on Dec. 6, 2020, 5:07 p.m.