Skip to content

StochasticDynamics is an R package for simulating and visualizing stochastic processes on networks, including epidemic (SIR, SEIR, SIRS), opinion, and reaction–diffusion models. Provides incidence analysis, interactive 3D visualization with rgl, and video export tools.

License

Notifications You must be signed in to change notification settings

CoMuNeLab/StochasticDynamics

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

StochasticDynamics

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.


Features

  • Epidemic spreading models:

    • runSIR, runSIRS, runSIRb (behavioral SIR with adaptive contacts)
    • Generalized runGeneralCompartmentModel for custom compartmental dynamics
    • Incidence extractors (getSIRIncidence, getGeneralCompartmentIncidence, etc.)
  • Opinion dynamics:

    • runGeneralOpinionModel for multi-state adoption/flip dynamics
  • Reaction–diffusion / failure spreading:

    • runOFSModel for operative–failed–safe dynamics
    • General incidence computation for reaction-diffusion
  • Visualization:

    • 3D dynamic rendering with rgl
    • makeVideo, makeVideoFailure, and makeVideoMemory to export temporal evolution to .mp4
  • Utilities:

    • Graph editing functions like removeAdjacentEdges

Installation

You can install the development version from source:

# clone the repo locally, then in R:
devtools::install("path/to/StochasticDynamics")

Dependencies:

  • igraph
  • rgl
  • ggplot2, ggsci, dplyr, reshape2
  • scales

Examples

Scripts are provided under inst/examples/:

  • SIR_dynamic_viz.R – animate an epidemic spreading on a stochastic block model
  • SIR_dynamic_failure_viz.R – simulate epidemic-induced failures (nodes dropping edges)
  • SIRS_stochastic.R – analyze epidemic incidence vs centrality measures
  • Opinion_stochastic.R – run a general opinion model
  • ReactionDiffusion_stochastic.R – simulate failure spreading with recovery
  • cascade_failure.R – visualize cascading failures in networks

Run them with:

Rscript inst/examples/SIR_dynamic_viz.R

Videos will be saved to your working directory.


Tests

Unit tests are provided in tests/testthat/. Run them with:

devtools::test()

License

MIT License
Copyright (c) 2025 CoMuNeLab

About

StochasticDynamics is an R package for simulating and visualizing stochastic processes on networks, including epidemic (SIR, SEIR, SIRS), opinion, and reaction–diffusion models. Provides incidence analysis, interactive 3D visualization with rgl, and video export tools.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages