---
title: EpiJS Module - Comp
---
<!-- Generated by documentation.js. Update this documentation by updating the source code. -->

### Table of Contents


*   [Idiom][2]
    *   [Parameters][3]
    *   [Examples][4]
*   [Susceptible][5]
    *   [Parameters][6]
    *   [Examples][7]
*   [Infected][8]
    *   [Parameters][9]
    *   [Examples][10]
*   [Exposed][11]
    *   [Parameters][12]
    *   [Examples][13]
*   [Critical][14]
    *   [Parameters][15]
    *   [Examples][16]
*   [Hospitalized][17]
    *   [Parameters][18]
    *   [Examples][19]
*   [Dead][20]
    *   [Parameters][21]
    *   [Examples][22]
*   [Vaccinated][23]
    *   [Parameters][24]
    *   [Examples][25]
*   [Recovered][26]
    *   [Parameters][27]
    *   [Examples][28]

# Comp
EpiJS module for creating compartments, which can be combined into models.

Import it with:
```javascript
       const comp = require('@epispot/epijs').comp
```
## Idiom

Class for a custom compartments.

### Parameters

*   `equation` **[String][29]** The equation for the compartment. This defines what to run to get a new value for the next day in the model. Use any variable in the equation (1 char max), but when making this a model, you need to define this in the key.
    If using other compartment classes, they each have their own corresponding variable: 
     *  'S' - Susceptible
    *   'E' - Exposed
    *   'I' - Infectious
    *   'R' - Recovered
    *   'D' - Dead
    *   'C' - Critical
    *   'H' - Hospitalized
    *   'V' - Vaccinated
    *   'w' - Reserved for stochastic models. If put, it will be replaced with a random number generated from the gaussian distribution.

### Examples

```javascript
let susceptible = new Idiom("S-(B*S*I)")
```

## Susceptible

Class for Suscepible compartment.

### Parameters

*   `next` **[Array][30]** List of rates of the next compartments This is multiplied by the current susceptible population.
*   `prev` **[Array][30]** List of rates of the previous compartments, which include sub-arrays
    with the compartment id (one letter only), as a string, and the rate for the compartment.
    If reffering to this compartment's population, use "S" as the id. This parameter is useful
    if you want to model a disease with re-susceptibility.
*   `stochastic` **[Boolean][31]** If true, the compartment will be stochastic. You can still pass in your normal equation, and epijs will
    auto generate the equations from what you pass in.

### Examples

```javascript
// Note that you can pass in a number as a rate too, 
     // but we use a string because we want to multiply 
     // by other compartment populations. This applies to the prev parameter too. 
     let S = new Susceptible(["I*0.4/N"], [], true)
```

## Infected

Class for Infected compartment.

### Parameters

*   `next` **[Array][30]** List of rates of the next compartments This is multiplied by the current infected population.
*   `prev` **[Array][30]** List of rates of the previous compartments, which include sub-arrays
    with the compartment id (one letter only), as a string, and the rate for the compartment.
    If reffering to this compartment's population, use "I" as the id.
*   `stochastic` **[Boolean][31]** If true, the compartment will be stochastic.

### Examples

```javascript
// Note that you can pass in a string as a rate too, 
     // but we use a number in this case because we don't need to multiply 
     // by other compartment populations. We do actually do this for the prev parameter, though.
     let I = new Infected([0.3], [["S", "I*0.4/N"]], false)
```

## Exposed

Class for Exposed compartment.

### Parameters

*   `next` **[Array][30]** List of rates of the next compartments This is multiplied by the current exposed population.
*   `prev` **[Array][30]** List of rates of the previous compartments, which include sub-arrays
    with the compartment id (one letter only), as a string, and the rate for the compartment.
    If reffering to this compartment's population, use "E" as the id.
*   `stochastic` **[Boolean][31]** If true, the compartment will be stochastic.

### Examples

```javascript
// Note that you can pass in a string as a rate too, 
     // but we use a number in this case because we don't need to multiply 
     // by other compartment populations. We do actually do this for the prev parameter, though.
     let E = new Exposed([1/14], ["S*0.4/N"], false)
```

## Critical

Class for Critical compartment.

### Parameters

*   `next` **[Array][30]** List of rates of the next compartments This is multiplied by the current critical population.
*   `prev` **[Array][30]** List of rates of the previous compartments, which include sub-arrays
    with the compartment id (one letter only), as a string, and the rate for the compartment.
    If reffering to this compartment's population, use "C" as the id.
*   `stochastic` **[Boolean][31]** If true, the compartment will be stochastic.

### Examples

```javascript
// Note that you can pass in a string as a rate too, 
     // but we use a number in this case because we don't need to multiply 
     // by other compartment populations.
     let C = new Critical([0.14, 0.1], [["H", 0.3]], false)
```

## Hospitalized

Class for Hospitalized compartment.

### Parameters

*   `next` **[Array][30]** List of rates of the next compartments This is multiplied by the current hospitalized population.
*   `prev` **[Array][30]** List of rates of the previous compartments, which include sub-arrays
    with the compartment id (one letter only), as a string, and the rate for the compartment.
    If reffering to this compartment's population, use "H" as the id.
*   `stochastic` **[Boolean][31]** If true, the compartment will be stochastic.

### Examples

```javascript
// Note that you can pass in a string as a rate too, 
     // but we use a number in this case because we don't need to multiply 
     // by other compartment populations.
     let H = new Hospitalized([0.3], [["I", 0.1], ["E", 0.2]], false)
```

## Dead

Class for the Dead compartment.

### Parameters

*   `next` **[Array][30]** List of rates of the next compartments. This is multiplied by the current dead population.
    Useful if you want to have a dead population that can also be the walking dead.
*   `prev` **[Array][30]** List of rates of the previous compartments, which include sub-arrays
    with the compartment id (one letter only), as a string, and the rate for the compartment.
    If reffering to this compartment's population, use "D" as the id.
*   `stochastic` **[Boolean][31]** If true, the compartment will be stochastic.

### Examples

```javascript
// Note that you can pass in a string as a rate too, 
     // but we use a number in this case because we don't need to multiply 
     // by other compartment populations. We do actually do this for the prev parameter, though.
     let D = new Dead([0.3], [["I", 0.3]], false) // This disease also gives you a 3/10 chance to come alive after death.
```

## Vaccinated

Class for Vaccinated compartment.

### Parameters

*   `next` **[Array][30]** List of rates of the next compartments, good if the vaccine isn't 100% effective. This is multiplied by the current vaccinated population.
*   `prev` **[Array][30]** List of rates of the previous compartments, which include sub-arrays
    with the compartment id (one letter only), as a string, and the rate for the compartment.
    If reffering to this compartment's population, use "V" as the id.
*   `stochastic` **[Boolean][31]** If true, the compartment will be stochastic.

### Examples

```javascript
// Note that you can pass in a string as a rate too, 
     // but we use a number in this case because we don't need to multiply 
     // by other compartment populations. We do actually do this for the prev parameter, though.
     let I = new Infected([0.001], ["S*0.4"], false)
```

## Recovered

Class for Recovered compartment.

### Parameters

*   `next` **[Array][30]** List of rates of the next compartments, good if the vaccine isn't 100% effective. This is multiplied by the current vaccinated population.
*   `prev` **[Array][30]** List of rates of the previous compartments, which include sub-arrays
    with the compartment id (one letter only), as a string, and the rate for the compartment.
    If reffering to this compartment's population, use "V" as the id.
*   `stochastic` **[Boolean][31]** If true, the compartment will be stochastic.

### Examples

```javascript
// Note that you can pass in a string as a rate too, 
     // but we use a number in this case because we don't need to multiply 
     // by other compartment populations. We do actually do this for the prev parameter, though.
     let R = new Recovered([ ], [["I", 0.1]], false)
```

[1]: #math

[2]: #idiom

[3]: #parameters

[4]: #examples

[5]: #susceptible

[6]: #parameters-1

[7]: #examples-1

[8]: #infected

[9]: #parameters-2

[10]: #examples-2

[11]: #exposed

[12]: #parameters-3

[13]: #examples-3

[14]: #critical

[15]: #parameters-4

[16]: #examples-4

[17]: #hospitalized

[18]: #parameters-5

[19]: #examples-5

[20]: #dead

[21]: #parameters-6

[22]: #examples-6

[23]: #vaccinated

[24]: #parameters-7

[25]: #examples-7

[26]: #recovered

[27]: #parameters-8

[28]: #examples-8

[29]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String

[30]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array

[31]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean
