Skip to content

Commit

Permalink
si_partnerships_sti model
Browse files Browse the repository at this point in the history
  • Loading branch information
stevencarlislewalker committed Sep 26, 2024
1 parent 970db56 commit 0dfaf70
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 0 deletions.
67 changes: 67 additions & 0 deletions inst/starter_models/si_partnerships_sti/README.Rmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
---
title: "STI Partnership Model"
output:
html_document:
df_print: paged
---

```{r setup}
library(macpan2)
library(ggplot2)
```

## Introduction

This document describes a **Sexually Transmitted Infection (STI) Partnership Model** implemented in `macpan2`. The model simulates how STIs spread within a population where individuals form and dissolve partnerships, incorporating both **within-partner transmission** and **external transmission**.

## Model Description

The compartments in the model are:

- **S**: Susceptible individuals
- **I**: Infected individuals
- **SS**: Susceptible-Susceptible partnerships
- **SI**: Susceptible-Infected partnerships
- **II**: Infected-Infected partnerships

### Dynamics:

1. **Partnership Formation**: Susceptible individuals form partnerships, transitioning into the **SS** or **SI** compartments.
2. **Partnership Dissolution**: Partnerships dissolve, moving individuals back to the **S** or **I** compartments.
3. **Within-Partner Transmission**: Infected partners in **SI** compartments transmit infection to their susceptible partners, transitioning them to **II**.
4. **External Transmission**: Susceptible individuals can be infected through external sources, moving from **S** to **I**.

## Model Simulation

We use the pre-defined model from the library.

```{r load_model}
# Load the pre-specified STI model
model <- mp_tmb_library("starter_models", "si_partnerships_sti", package = "macpan2")
```

## Running the Simulation

The simulation is run for 100 time steps, and results are captured for analysis.

```{r run_simulation}
simulated_results <- model |>
mp_simulator(time_steps = 100, outputs = c("S", "I", "SS", "SI", "II")) |>
mp_trajectory()
```

## Results

The plot below shows the changes in population across the compartments over time.

```{r plot_results}
ggplot(simulated_results, aes(x = time, y = value, color = matrix)) +
geom_line() +
facet_wrap(~ matrix, scales = "free_y") +
theme_bw() +
labs(title = "STI Partnership Model Dynamics", x = "Time", y = "Population")
```

## Conclusion

This model simulates STI spread through partnerships and external sources, offering insights into the role of relationship dynamics in disease transmission. The model can be expanded to explore additional features such as heterogeneity in the population or multiple infection strains.
36 changes: 36 additions & 0 deletions inst/starter_models/si_partnerships_sti/tmb.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Load macpan2 library
library(macpan2)

# Define the model with two-sided formulas for initial conditions and N
spec <- mp_tmb_model_spec(

# Define the initial population sizes using two-sided formulas
before = list(
S ~ 900, # 900 susceptible individuals
I ~ 100, # 100 infected individuals
SS ~ 200, # 200 Susceptible-Susceptible partnerships
SI ~ 100, # 100 Susceptible-Infected partnerships
II ~ 50, # 50 Infected-Infected partnerships
N ~ S + I + 2*(SS + SI + II) # Total population size as the sum of individuals
),

# Define partnership formation and dissolution flows
during = list(
mp_per_capita_flow("S", "SS", "partner_form_rate * S / N", "form_new_partnership"),
mp_per_capita_flow("SS", "S", "partner_dissolve_rate", "partnership_dissolution"),

# Within-partner transmission (SI -> II)
mp_per_capita_flow("SI", "II", "beta_SI * I / N", "within_partner_transmission"),

# Between-partner transmission (S -> I)
mp_per_capita_flow("S", "I", "beta_external * I / N", "external_transmission")
),

# Define default transmission rates and other parameters
default = list(
partner_form_rate = 0.05, # Partnership formation rate
partner_dissolve_rate = 0.02, # Partnership dissolution rate
beta_SI = 0.1, # Transmission rate within SI partnerships
beta_external = 0.05 # External transmission rate
)
)

0 comments on commit 0dfaf70

Please sign in to comment.