{"id":16472009,"url":"https://github.com/stewid/siminf","last_synced_at":"2025-10-11T00:12:44.596Z","repository":{"id":25914324,"uuid":"29355211","full_name":"stewid/SimInf","owner":"stewid","description":"A framework for data-driven stochastic disease spread simulations","archived":false,"fork":false,"pushed_at":"2025-10-02T11:25:45.000Z","size":13961,"stargazers_count":35,"open_issues_count":1,"forks_count":16,"subscribers_count":6,"default_branch":"main","last_synced_at":"2025-10-02T13:29:51.144Z","etag":null,"topics":["cran","data-driven","epidemiology","high-performance-computing","markov-chain","mathematical-modelling","r"],"latest_commit_sha":null,"homepage":"http://stewid.github.io/SimInf/","language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/stewid.png","metadata":{"files":{"readme":"README.Rmd","changelog":"NEWS.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2015-01-16T15:50:44.000Z","updated_at":"2025-10-02T11:23:04.000Z","dependencies_parsed_at":"2023-02-14T05:15:23.153Z","dependency_job_id":"58c13b2e-996e-4abe-8056-268007da2d1b","html_url":"https://github.com/stewid/SimInf","commit_stats":{"total_commits":3342,"total_committers":7,"mean_commits":"477.42857142857144","dds":0.08497905445840814,"last_synced_commit":"a013f55e605e8ee2e7f4de9b5c6ab5e03a1ba2c4"},"previous_names":[],"tags_count":30,"template":false,"template_full_name":null,"purl":"pkg:github/stewid/SimInf","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stewid%2FSimInf","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stewid%2FSimInf/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stewid%2FSimInf/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stewid%2FSimInf/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stewid","download_url":"https://codeload.github.com/stewid/SimInf/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stewid%2FSimInf/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279005649,"owners_count":26083940,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-10T02:00:06.843Z","response_time":62,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cran","data-driven","epidemiology","high-performance-computing","markov-chain","mathematical-modelling","r"],"created_at":"2024-10-11T12:15:51.687Z","updated_at":"2025-10-11T00:12:44.591Z","avatar_url":"https://github.com/stewid.png","language":"R","funding_links":[],"categories":[],"sub_categories":[],"readme":"```{r, setup, echo = FALSE, message = FALSE}\nknitr::opts_chunk$set(\n  comment = \"#\u003e\",\n  tidy = FALSE,\n  error = FALSE,\n  fig.width = 8,\n  fig.height = 8,\n  fig.path = \"man/figures/README-\")\n```\n\n![](https://raw.githubusercontent.com/stewid/SimInf/main/logo/logo.png)\n\n\u003e A flexible and efficient framework for data-driven stochastic disease spread simulations\n\n[![Build Status](https://github.com/stewid/SimInf/actions/workflows/R-CI.yaml/badge.svg)](https://github.com/stewid/SimInf/actions/workflows/R-CI.yaml)\n[![CRAN status](https://www.r-pkg.org/badges/version/SimInf)](https://CRAN.R-project.org/package=SimInf)\n[![CRAN RStudio mirror downloads](https://cranlogs.r-pkg.org/badges/last-month/SimInf)](https://CRAN.R-project.org/package=SimInf)\n[![Code coverage](https://codecov.io/gh/stewid/SimInf/branch/main/graph/badge.svg)](https://app.codecov.io/gh/stewid/SimInf)\n\n# SimInf\n\nThe package provides an efficient and very flexible framework to\nconduct data-driven epidemiological modeling in realistic large scale\ndisease spread simulations. The framework integrates infection\ndynamics in subpopulations as continuous-time Markov chains using the\nGillespie stochastic simulation algorithm and incorporates available\ndata such as births, deaths and movements as scheduled events at\npredefined time-points. Using C code for the numerical solvers and\n'OpenMP' (if available) to divide work over multiple processors\nensures high performance when simulating a sample outcome. One of our\ndesign goals was to make the package extendable and enable usage of\nthe numerical solvers from other R extension packages in order to\nfacilitate complex epidemiological research. The package contains\ntemplate models and can be extended with user-defined models.\n\n## Getting started\n\nYou can use one of the predefined compartment models in SimInf, for\nexample, SEIR. But you can also define a custom model 'on the fly'\nusing the model parser method `mparse`. The method takes a character\nvector of transitions in the form of `X -\u003e propensity -\u003e Y` and\nautomatically generates the C and R code for the model. The left hand\nside of the first arrow (`-\u003e`) is the initial state, the right hand\nside of the last arrow (`-\u003e`) is the final state, and the propensity\nis written between the two arrows. The flexibility of the `mparse`\napproach allows for quick prototyping of new models or features. To\nillustrate the `mparse` functionality, let us consider the SIR model\nin a closed population i.e., no births or deaths. Let `beta` denote\nthe transmission rate of spread between a susceptible individual and\nan infectious individual and `gamma` the recovery rate from infection\n(`gamma` = 1 / average duration of infection). It is also possible to\ndefine variables which can then be used in calculations of\npropensities or in calculations of other variables. A variable is\ndefined by the operator `\u003c-`. Using a variable for the size of the\npopulation, the SIR model can be described as:\n\n```{r, message=FALSE}\nlibrary(SimInf)\n\ntransitions \u003c- c(\"S -\u003e beta*S*I/N -\u003e I\",\n                 \"I -\u003e gamma*I -\u003e R\",\n                 \"N \u003c- S+I+R\")\ncompartments \u003c- c(\"S\", \"I\", \"R\")\n```\n\nThe `transitions` and `compartments` variables together with the\nconstants `beta` and `gamma` can now be used to generate a model with\n`mparse`. The model also needs to be initialised with the initial\ncondition `u0` and `tspan`, a vector of time points where the state of\nthe system is to be returned. Let us create a model that consists of\n1000 replicates of a population, denoted a *node* in SimInf, that each\nstarts with 99 susceptibles, 5 infected and 0 recovered individuals.\n\n```{r}\nn \u003c- 1000\nu0 \u003c- data.frame(S = rep(99, n), I = rep(5, n), R = rep(0, n))\n\nmodel \u003c- mparse(transitions = transitions,\n                compartments = compartments,\n                gdata = c(beta = 0.16, gamma = 0.077),\n                u0 = u0,\n                tspan = 1:150)\n```\n\nTo generate data from the model and then print some basic information\nabout the outcome, run the following commands:\n\n```{r, echo=FALSE, results=\"hide\"}\n## For reproducibility of the example, set the seed and\n## the number of threads to use for the simulation.\nset.seed(123)\nset_num_threads(1)\n```\n\n```{r}\nresult \u003c- run(model)\nresult\n```\n\nThere are several functions in SimInf to facilitate analysis and\npost-processing of simulated data, for example, `trajectory`,\n`prevalence` and `plot`. The default `plot` will display the median\ncount in each compartment across nodes as a colored line together with\nthe inter-quartile range using the same color, but with transparency.\n\n```{r mparse-SIR, fig.width = 10, fig.height = 5}\nplot(result)\n```\n\nMost modeling and simulation studies require custom data analysis once\nthe simulation data has been generated.  To support this, SimInf\nprovides the `trajectory` method to obtain a `data.frame` with the\nnumber of individuals in each compartment at the time points specified\nin `tspan`. Below is the first 10 lines of the `data.frame` with\nsimulated data.\n\n```{r, eval=FALSE}\ntrajectory(result)\n```\n\n```\n#\u003e    node time  S I R\n#\u003e 1     1    1 98 6 0\n#\u003e 2     2    1 98 6 0\n#\u003e 3     3    1 98 6 0\n#\u003e 4     4    1 99 5 0\n#\u003e 5     5    1 97 7 0\n#\u003e 6     6    1 98 5 1\n#\u003e 7     7    1 99 5 0\n#\u003e 8     8    1 99 5 0\n#\u003e 9     9    1 97 7 0\n#\u003e 10   10    1 97 6 1\n...\n```\n\nFinally, let us use the `prevalence` method to explore the proportion\nof infected individuals across all nodes. It takes a model object and\na formula specification, where the left hand side of the formula\nspecifies the compartments representing cases i.e., have an attribute\nor a disease and the right hand side of the formula specifies the\ncompartments at risk. Below is the first 10 lines of the `data.frame`.\n\n```{r, eval=FALSE}\nprevalence(result, I ~ S + I + R)\n```\n\n```\n#\u003e    time prevalence\n#\u003e 1     1 0.05196154\n#\u003e 2     2 0.05605769\n#\u003e 3     3 0.06059615\n#\u003e 4     4 0.06516346\n#\u003e 5     5 0.06977885\n#\u003e 6     6 0.07390385\n#\u003e 7     7 0.07856731\n#\u003e 8     8 0.08311538\n#\u003e 9     9 0.08794231\n#\u003e 10   10 0.09321154\n...\n```\n\n## Learn more\n\nSee the\n[vignette](https://CRAN.R-project.org/package=SimInf/vignettes/SimInf.pdf)\nto learn more about special features that the SimInf R package\nprovides, for example, how to:\n\n- use continuous state variables\n\n- use the SimInf framework from another R package\n\n- incorporate available data such as births, deaths and movements as\n  scheduled events at predefined time-points.\n\n## Installation\n\nYou can install the released version of `SimInf` from\n[CRAN](https://CRAN.R-project.org/package=SimInf)\n\n```{r eval = FALSE}\ninstall.packages(\"SimInf\")\n```\n\nor use the `remotes` package to install the development version from\n[GitHub](https://github.com/stewid/SimInf)\n\n```{r eval = FALSE}\nlibrary(remotes)\ninstall_github(\"stewid/SimInf\")\n```\n\nWe refer to section 3.1 in the\n[vignette](https://CRAN.R-project.org/package=SimInf/vignettes/SimInf.pdf)\nfor detailed installation instructions.\n\n## Authors\n\nIn alphabetical order: Pavol Bauer [![ORCID\niD](https://info.orcid.org/wp-content/uploads/2019/11/orcid_16x16.png)](https://orcid.org/0000-0003-4328-7171),\nRobin Eriksson [![ORCID\niD](https://info.orcid.org/wp-content/uploads/2019/11/orcid_16x16.png)](https://orcid.org/0000-0002-4291-712X),\nStefan Engblom [![ORCID\niD](https://info.orcid.org/wp-content/uploads/2019/11/orcid_16x16.png)](https://orcid.org/0000-0002-3614-1732),\nand Stefan Widgren [![ORCID\niD](https://info.orcid.org/wp-content/uploads/2019/11/orcid_16x16.png)](https://orcid.org/0000-0001-5745-2284)\n**(Maintainer)**\n\nAny suggestions, bug reports, forks and pull requests are\nappreciated. Get in touch.\n\n## Citation\n\nIf you use SimInf in your research, please cite:\n\n---\n\n\u003e **Widgren S, Bauer P, Eriksson R, Engblom S (2019).**\n\u003e SimInf: An R Package for Data-Driven Stochastic Disease Spread Simulations.\n\u003e *Journal of Statistical Software, 91(12), 1–42.*\n\u003e [https://doi.org/10.18637/jss.v091.i12](https://doi.org/10.18637/jss.v091.i12)\n\n\u003e **Bauer P, Engblom S, Widgren S (2016).**\n\u003e Fast event-based epidemiological simulations on national scales.\n\u003e *International Journal of High Performance Computing Applications, 30(4), 438–453.*\n\u003e [https://doi.org/10.1177/1094342016635723](https://doi.org/10.1177/1094342016635723)\n\n---\n\n## Acknowledgments\n\nThis software has been made possible by support from the Swedish\nResearch Council within the UPMARC Linnaeus center of Excellence\n(Pavol Bauer, Robin Eriksson, and Stefan Engblom), the Swedish\nResearch Council Formas (Stefan Engblom and Stefan Widgren), the\nSwedish Board of Agriculture (Stefan Widgren), the Swedish strategic\nresearch program eSSENCE (Stefan Widgren), and in the framework of the\nFull Force project, supported by funding from the European Union’s\nHorizon 2020 Research and Innovation programme under grant agreement\nNo 773830: One Health European Joint Programme (Stefan Widgren).\n\n## Versioning\n\nThe `SimInf` package uses [semantic versioning](https://semver.org/).\n\n## License\n\nThe `SimInf` package is licensed under the\n[GPLv3](https://github.com/stewid/SimInf/blob/main/LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstewid%2Fsiminf","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstewid%2Fsiminf","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstewid%2Fsiminf/lists"}