Part 2a: Non-Disease Applications - Network Diffusion

Though epiworldR focuses primarily on disease modeling, the epiworld framework is general enough to model any type of diffusion process, such as simulating the spread of ideas or rumors throughout a population. In this part of the workshop, we’ll walk through an example of social network diffusion.

Example Scenario: Academic Faculty Rumor

The example implements the following scenario:

  • Rumor: The dean will resign!
  • Population Description: A UK university faculty
  • Population size: 81 agents
  • Initial rumor prevalence: 2 agents
  • Probability of adopting the rumor: 0.1

Load Packages and Data

We use the igraph and netplot R packages for manipulating and plotting networks respectively. The file part2a.rda includes the UKfaculty friendship network from the igraphdata package, with the vertex attributes (UKfaculty_vertex) and edge list (UKfaculty_edgelist) as numeric matrices. We load the UKfaculty data and visualize the friendship network.

Code
load("part2a.rda")

nplot(UKfaculty)

Simulating the Rumor

Using the ModelDiffNet() function, we can simulate how the rumor spreads through the network. First, we create the network diffusion model. The prevalence of the rumor is set such that 2 agents are exposed to the rumor at the start of the simulation. The probability of an agent adopting the rumor is 0.1.

Code
library(epiworldR)

adopt_rumor <- ModelDiffNet(
  name       = "The dean will resign!",
  prevalence = 2/vcount(UKfaculty),
  prob_adopt = .1,
  data       = UKfaculty_vertex,
  params     = c(0, 5)
)

We then initialize the model agents using the agents_from_edgelist() function.

Code
# Reading in the network
agents_from_edgelist(
  adopt_rumor,
  size     = vcount(UKfaculty),
  source   = UKfaculty_edgelist[,1] - 1L,
  target   = UKfaculty_edgelist[,2] - 1L,
  directed = TRUE
  )

We run the model for 100 days and plot the results.

Code
verbose_off(adopt_rumor)
run(adopt_rumor, ndays = 100)

adopt_rumor
________________________________________________________________________________
Diffusion of Innovations - The dean will resign!
It features 81 agents, 1 virus(es), and 0 tool(s).
The model has 2 states.
The final distribution is: 0 Non adopters, and 81 Adopters.
Code
plot(adopt_rumor)

By day 16 or 17, the entire network had adopted the rumor that the dean will resign.

The transmission network is not always relevant for a diffusion network model, but in this case we can use it to visualize the spread of the rumor through the network. We get the transmission network using the get_transmissions() function, then plot the network using the igraph and netplot packages.

Code
transmissions <- get_transmissions(adopt_rumor)
Warning in get_transmissions.epiworld_diffnet(adopt_rumor): The transmission
network is not necesarily relevant for the diffnet model
Code
# Turning it into a network via igraph
tnet <- graph_from_data_frame(
  transmissions[, c(2, 3)] + 1, # To start from 1 (not 0)
  directed = TRUE,
  vertices = cbind(id = 1:81, UKfaculty_vertex)
  )

# Adding back vertex attributes
nplot(tnet)

Exercise

Create a diffusion network model using ModelDiffNet() to simulate the adoption of Chat-GPT among a population over 50 days.

  • Population size: 10,000 agents
  • Initial rumor prevalence: .01
  • Probability of adopting ChatGPT: 0.1
  • Logit Params: c(1, 4)

We’ve setup a synthetic network dataset for you to use.

Code
set.seed(2223)
n <- 10000

# Generating synthetic data on a matrix with 2 columns.
network_data <- cbind(
  age = sample(1:100, n, replace = TRUE),
  female = sample.int(2, n, replace = TRUE) - 1
)

Use the following parameters for agents_smallworld():

  • n = 10000
  • k = 8 (number of connections for each agent)
  • d = FALSE (whether the graph is directed)
  • p = .01 (probability of rewiring)

Create the model and run for 50 days, then plot the simulation with the plot() function.

Code
# Your solution here

Bonus Exercises and Exploration

If you want further exploration of network diffusion in epiworldR, here are some bonus topics and exercises to guide your learning.