StochasticDynamics is an R package for simulating and visualizing stochastic dynamical processes on complex networks.
It provides implementations of epidemic models (SIR, SIRS, SEIR, behavioral SIR, general compartment models), opinion dynamics, and reaction–diffusion failure processes, with optional 3D visualization and video export.
-
Epidemic spreading models:
runSIR,runSIRS,runSIRb(behavioral SIR with adaptive contacts)- Generalized
runGeneralCompartmentModelfor custom compartmental dynamics - Incidence extractors (
getSIRIncidence,getGeneralCompartmentIncidence, etc.)
-
Opinion dynamics:
runGeneralOpinionModelfor multi-state adoption/flip dynamics
-
Reaction–diffusion / failure spreading:
runOFSModelfor operative–failed–safe dynamics- General incidence computation for reaction-diffusion
-
Visualization:
- 3D dynamic rendering with
rgl makeVideo,makeVideoFailure, andmakeVideoMemoryto export temporal evolution to.mp4
- 3D dynamic rendering with
-
Utilities:
- Graph editing functions like
removeAdjacentEdges
- Graph editing functions like
You can install the development version from source:
# clone the repo locally, then in R:
devtools::install("path/to/StochasticDynamics")Dependencies:
igraphrglggplot2,ggsci,dplyr,reshape2scales
Scripts are provided under inst/examples/:
SIR_dynamic_viz.R– animate an epidemic spreading on a stochastic block modelSIR_dynamic_failure_viz.R– simulate epidemic-induced failures (nodes dropping edges)SIRS_stochastic.R– analyze epidemic incidence vs centrality measuresOpinion_stochastic.R– run a general opinion modelReactionDiffusion_stochastic.R– simulate failure spreading with recoverycascade_failure.R– visualize cascading failures in networks
Run them with:
Rscript inst/examples/SIR_dynamic_viz.RVideos will be saved to your working directory.
Unit tests are provided in tests/testthat/. Run them with:
devtools::test()MIT License
Copyright (c) 2025 CoMuNeLab