SIR.js is a JS library implementing the SIR epidemic simulation model.
npm i --save sir.js
let SIRjs = require('sir.js');
let solution = SIRjs.solve({S0: 100, I0: 10, R0: 0, t:1, N: 10, beta: 0.8, gamma: 0.4});
SIRjs.printChart(solution);
It has only 2 functions: solve() and printChart()
solve() function takes an object argument with the following keys:
- S0: Initial S (Susceptible) value
- I0: Initial I (Infectious) value
- R0: Initial R (Recovered) value
- t: The time step
- N: The time span (in units of time) aka the length of the simulation
- beta: The parameter controlling how often a susceptible-infected contact results in a new infection
- gamma: The rate an infected recovers and moves into the resistant phase
It returns an array of objects that contain S,I and R values for each moment.
printChart() function prints an ASCII chart for each one of the S,I,R variables
i.e
=========== S ===========
00.00 โผโโโโโฎ
87.95 โค โฐโโโโฎ
75.90 โค โฐโโโโโโฎ
63.84 โค โฐโโโโฎ
51.79 โค โฐโโโโโโฎ
39.74 โค โฐโโโโโโโโโโโโฎ
27.69 โค โฐโโ
=========== I ===========
22.27 โค โญโโโโโโโโฎ
20.23 โค โญโโโโฏ โฐโโโโฎ
18.18 โค โญโโฏ โฐโโโโฎ
16.14 โค โญโโฏ โฐโโโโฎ
14.09 โค โญโโโโฏ โฐโโฎ
12.05 โคโญโโฏ โฐโโ
10.00 โผโฏ
=========== R ===========
70.63 โผ โญโโโโ
58.86 โค โญโโโโโโฏ
47.08 โค โญโโโโโโฏ
35.31 โค โญโโโโโโฏ
23.54 โค โญโโโโโโฏ
11.77 โค โญโโโโโโฏ
0.00 โผโโโโโฏ
SIR.js is licensed under MIT license.