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

### Table of Contents


*   [Virus][2]
    *   [Parameters][3]
    *   [Examples][4]
*   [Community][5]
    *   [Parameters][6]
    *   [Examples][7]
    *   [sir][8]
        *   [Parameters][9]
        *   [Examples][10]
    *   [seir][11]
        *   [Parameters][12]
        *   [Examples][13]
    *   [seird][14]
        *   [Parameters][15]
        *   [Examples][16]
    *   [custom][17]
        *   [Parameters][18]
        *   [Examples][19]
*   [compare][20]
    *   [Parameters][21]
    *   [Examples][22]

# Com

EpiJS module for representing communities

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

Class representing a virus, which can infect a community.

### Parameters

*   `rnaught` **[Number][23]** The disease's R-Naught
*   `u` **[Number][23]** The disease's recovery rate
*   `a` **[Number][23]** The disease's incubation period (optional, default `0`)
*   `d` **[Number][23]** The disease's death rate (for infected population) (optional, default `0`)

### Examples

```javascript
let covid = new Virus(5.7, 2.1/100)
```

## Community

Class representing a community, which can be infected with a disease, and compared to other communities.

### Parameters

*   `pop` **[Number][23]** The population of the community
*   `i` **[Number][23]** The start infected population of the community.
*   `s` **[Number][23]** The start susceptible population of the community

### Examples

```javascript
let NewYorkCity = new Community(8419000, 300, 8418700)
```

### sir

SIR model for the community

#### Parameters

*   `disease` **[Number][23]** A virus class. The virus to infect the community with and model for.
*   `time` **[Number][23]** Time to predict for.
*   `stochastic` **[Boolean][24]** Whether to make the model stochastic or not.

#### Examples

```javascript
let NewYorkCity = new Community(8419000, 300, 8418700)
let covid = new Virus(5.7, 2.1/100, 1/8, 1/100)

outbreak = NewYorkCity.sir(covid, 100, false)
```

### seir

SEIR model for the community

#### Parameters

*   `disease` **[Number][23]** A virus class. The virus to infect the community with and model for.
*   `time` **[Number][23]** Time to predict for.
*   `stochastic` **[Boolean][24]** Whether to make the model stochastic or not.

#### Examples

```javascript
let NewYorkCity = new Community(8419000, 300, 8418700)
let covid = new Virus(5.7, 2.1/100, 1/8, 1/100)

outbreak = NewYorkCity.seir(covid, 100, false)
```

### seird

SEIRD model for the community

#### Parameters

*   `disease` **[Number][23]** A virus class. The virus to infect the community with and model for.
*   `time` **[Number][23]** Time to predict for.
*   `stochastic` **[Boolean][24]** Whether to make the model stochastic or not.

#### Examples

```javascript
let NewYorkCity = new Community(8419000, 300, 8418700)
let covid = new Virus(5.7, 2.1/100, 1/8, 1/100)

outbreak = NewYorkCity.seird(covid, 100, false)
```

### custom

Custom model for the community

#### Parameters

*   `compartments` **[Array][25]** The compartments for the model. Pass in as an array with sub arrays of the form \[compartment, name in key].
    Note that the 'name in key' is a string with the same value that is stored in your extra key, otherwise it should be the same name that we store it as.
You can find these names below.

    *   Susceptible - stored as 'S'
    *   Infected - stored as 'I'
    *   Recovered - stored as 'R'

Make sure that you use the same names that are stored in the key in the equations for the compartments. These values are found from parameters passed into the virus class and the community class.

*   `time` **[Number][23]** The time to predict for.
*   `virus`  The virus class to infect the community with.
*   `extrakey` **[Object][26]** Optional, any extra parameters for the compartments equations.
We already have the following parameters:
    *   Population - stored as 'p' in our key.
    *   Susceptible Population - stored as 'S' in our key.
    *   R-naught - stored as 'rn' in our key.
    *   Recovery rate - stored as 'u' in our key.
    *   Recovered - stored as 'R' in our key.
    *   Infected - stored as 'I' in our key.
    *   Death Rate - stored as 'd' in our key.
    *   Incubation Period - stored as 'a' in our key.
#### Examples

```javascript
let susceptible = new Idiom("S-(B*S*I/p)");
let infected = new Idiom("I+(B*S*I/p)-(u*I)");
let recovered = new Idiom("R+(u*I)");

let NewYorkCity = new Community(8419000, 300, 8418700)
let covid = new Virus(5.7, 2.1/100, 1/8, 1/100)

outbreak = NewYorkCity.custom([[susceptible, 'S'], [infected, 'I'], [recovered, 'R']], 100, covid, {B: covid.rnaught*covid.u})
```

## compare

Compare's two different outbreaks, communities, or anything else.

### Parameters

*   `c` **[HTMLCanvasElement][27]** The canvas element
*   `model1` **[Function][28]** The first model to compare.
*   `model2` **[Function][28]** The second model to compare.
*   `m1name` **[String][29]** The name of the first model
*   `m2name` **[String][29]** The name of the second model
*   `days` **[Number][23]** The total amount of days to compare for.

### Examples

```javascript
let NewYorkCity = new Community(8419000, 300, 8418700)
let covid = new Virus(5.7, 2.1/100)
let covid_variant = new Virus(5, 4/100)

let chart = document.getElementById('model')

covid_outbreak = NewYorkCity.sir(covid, 100)
variant_outbreak = NewYorkCity.sir(covid_variant, 100)

compare(chart, covid_outbreak, variant_outbreak, "COVID-19", "COVID-19 Variant", 100) // We chose 100 as the amount of days, but it could be 50 or 25, not the lenght of the prediction that was in the model.
```

[1]: #chart

[2]: #virus

[3]: #parameters

[4]: #examples

[5]: #community

[6]: #parameters-1

[7]: #examples-1

[8]: #sir

[9]: #parameters-2

[10]: #examples-2

[11]: #seir

[12]: #parameters-3

[13]: #examples-3

[14]: #seird

[15]: #parameters-4

[16]: #examples-4

[17]: #custom

[18]: #parameters-5

[19]: #examples-5

[20]: #compare

[21]: #parameters-6

[22]: #examples-6

[23]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number

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

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

[26]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object

[27]: https://developer.mozilla.org/docs/Web/API/HTMLCanvasElement

[28]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function

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