-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.qmd
157 lines (125 loc) · 6.24 KB
/
index.qmd
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
---
title: "epiworldR Workshop - Sunbelt 2025"
---
::: {style="width: 70%;margin:auto;"}
```{r}
#| warning: false
#| echo: true
#| code-fold: true
#| label: fig-epiworldR
library(epiworldR)
# Create a model
mymodel <- ModelSEIRCONN(
name = "Nasty virus",
n = 10000,
prevalence = .001,
contact_rate = 4,
transmission_rate = .4,
incubation_days = 7,
recovery_rate = 1/7
) |> verbose_off()
# Add a second virus
add_virus(
mymodel,
virus(
name = "Nasty virus 2",
prob_infecting = .5,
recovery_rate = .3,
),
proportion = .001
)
# Rename the model
set_name(mymodel, mname = "SEIR COVID-19 model")
# Run the model
set.seed(8383)
run(mymodel, ndays = 100)
# Plot the model
# - Set graphical parameters to plot in 2x2 grid
op <- par(mfrow = c(2, 2), mar = par()$mar * c(1, 1, 1/2, 0))
# - Plot
plot(mymodel)
plot_reproductive_number(mymodel)
plot_incidence(mymodel)
plot_generation_time(mymodel)
# - Restore original graphical parameters
par(op)
```
:::
Welcome to the Sunbelt 2025 workshop **Simulating Complex Agent-Based Models with `epiworldR`**.
The [**`epiworldR`**](https://uofuepibio.github.io/epiworldR){target="_blank"} R package is a wrapper of the C++ library [`epiworld`](https://github.com/UofUEpi/epiworld){target="_blank"}.
It provides a fast, highly customizable framework for building network-based transmission/diffusion [agent-based models](https://en.wikipedia.org/wiki/Agent-based_model){target="_blank"} (ABM).
Key features of `epiworldR` include:
- Fast simulation with an average of 30 million agents/model-step/second
- Multi-disease models (e.g., competing pathogens, multiple rumors, etc.)
- Mutating pathogens
- User-defined interventions (events, tools, politices, etc.) that chagne model behavior while it's running
- Adapting transmission and recovery rates based on comorbidities
- Parallel computing out-of-the-box
- Likelihood-Free Markhov chain Monte Carlo (LFMCMC)
- Coming Soon: Models with an arbitrary number of compartments/states beyond SIR/SEIR (available in the `epiworld` C++ library and currently being ported to R)
Additionally, while `epiworldR` was built for models of disease transmission, the `epiworld` framework is general enough to build models for any type of diffusion process (covered in Part 2a of this workshop).
## Workshop Details
If you don't want to use your personal computer, we have an online RStudio server available for you to use.[^1]
[^1]: Please note that the online RStudio server and your data stored in it will be available for two weeks after the workshop. After that, the server will be shut down and all data will be deleted. If you would like to keep your data, please download it before the server is shut down.
### Schedule (Tentative)
- (10 min) Setup
- (50 min) [Part 1: Basic Modeling](./part1.qmd)
- (10 min) Break
- (30 min) [Part 2a: Non-Disease Applications - Network Diffusion](./part2a.qmd)
- (30 min) [Part 2b: Advanced Modeling - Multiple Diseases, Tools, and Events](./part2b.qmd)
- (10 min) Break
- (40 min) [Part 3: Multiple Simulation Runs](./part3.qmd)
### Install `epiworldR`
You can install the latest stable version of `epiworldR` from CRAN:
```{r}
#| eval: false
install.packages("epiworldR")
```
or the latest development version from GitHub:
```{r}
#| eval: false
# install.packages("devtools")
devtools::install_github("UofUEpiBio/epiworldR")
```
## Relevant Terminology
**Agent-based modeling (ABM)**: A powerful computational approach that enables the simulation and analysis of complex systems by representing individual agents and their interactions within an environment.
ABM provides a bottom-up perspective, allowing for the examination of emergent phenomena arising from the collective behavior of autonomous agents.
By capturing the heterogeneity, autonomy, and adaptive nature of agents, ABM offers a versatile tool for investigating various domains, including social sciences, economics, biology, and epidemiology, offering valuable insights into the dynamics and patterns that emerge from the interactions of individual entities within a larger system.
As `epiworldR` focuses heavily on epidemiological applications, below are some common epidemiological terms that will be used throughout:
- **SEIR, SIR, SIS, etc.:** Epidemiological models used to analyze the spread and dynamics of diseases in a population. The models are named after the different compartments or states that an individual agent can fall into: Susceptible (S), Exposed (E), Infected (I), Recovered (R). So, SEIR has all four states, while SIR doesn't have the Exposed state.
- **SEIR connected (SEIRCONN), SIR connected (SIRCONN), etc.:** Epidemiological models similar to their above counterparts (SEIR, SIR, etc.), but with the added assumption that each individual agent is connected to all other agents.
- **Reproductive number:** The average number of secondary transmissions from one infected person. For example, a reproductive number of 2.0 indicates that one infected person transmits the disease to two other people in the population on average.
- **Incidence:** The occurrence of new cases of disease or injury in a population over a specified period of time. In `epiworldR` each step of a model represents a "day", thus `epiworldR` computes daily incidence.
## About the Instructors
Andrew Pulsipher is a software developer and Dr. George G. Vega Yon is a Research Assistant Professor of Epidemiology, both at the University of Utah's School of Medicine.
::: {style="width: 70%;margin:auto"}
```{r}
#| echo: true
#| warning: false
#| message: false
#| fig-cap: "Example transmission network generated by epiworldR (plotted with netplot)"
#| fig-align: center
#| fig-width: 8
#| fig-height: 8
#| code-fold: true
#| label: fig-epiworldR-2
sir <- ModelSIR(
name = "COVID-19",
prevalence = .01,
transmission_rate = .5,
recovery_rate = .5
) |>
# Adding a Small world population
agents_smallworld(n = 500, k = 10, d = FALSE, p = .01) |>
# Running the model for 50 days
verbose_off() |>
run(ndays = 50, seed = 1912)
## Transmission network
net <- get_transmissions(sir)
## Plotting
library(netplot)
library(igraph)
x <- graph_from_edgelist(as.matrix(net[,2:3]) + 1)
nplot(x, edge.curvature = 0, edge.color = "gray", skip.vertex=TRUE)
```
:::