Learn R Programming

SimInf (version 11.1.0)

nodes: Example data with spatial distribution of nodes

Description

Example data containing spatial coordinates for 1600 nodes, used to initialize spatially distributed population models and visualize simulation results.

Usage

data(nodes)

Arguments

Format

A data.frame with 1600 rows and 2 columns:

x

Numeric vector of x-coordinates.

y

Numeric vector of y-coordinates.

Examples

Run this code
## For reproducibility, specify the number of threads.
set_num_threads(1)

## Create an 'SIR' model with 1600 nodes and initialize
## it to run over 4*365 days. Add one infected individual
## to the first node.
u0 <- u0_SIR()
u0$I[1] <- 1
tspan <- seq(from = 1, to = 4*365, by = 1)

model <- SIR(
    u0     = u0,
    tspan  = tspan,
    events = events_SIR(),
    beta   = 0.16,
    gamma  = 0.077
)

## Run the model to generate a single stochastic trajectory.
## For reproducibility, specify the seed.
result <- run(model, seed = 22)

## Determine nodes with one or more infected individuals in the
## trajectory. Extract the 'I' compartment and check for any
## infected individuals in each node.
infected <- colSums(trajectory(result, ~ I, format = "matrix")) > 0

## Display infected nodes in 'blue' and non-infected nodes in 'yellow'.
data("nodes", package = "SimInf")
plot(
    y ~ x,
    nodes,
    col = ifelse(infected, "blue", "yellow"),
    pch = 20,
    asp = 1
)

Run the code above in your browser using DataLab