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

### Table of Contents


*   [Model][2]
    *   [Parameters][3]
    *   [Examples][4]
    *   [get_data][5]
        *   [Parameters][6]
        *   [Examples][7]
    *   [remove][8]
        *   [Parameters][9]
        *   [Examples][10]
    *   [add][11]
        *   [Parameters][12]
        *   [Examples][13]
*   [mexport][14]
    *   [Parameters][15]
    *   [Examples][16]
*   [mimport][17]
    *   [Parameters][18]
    *   [Examples][19]

# Model

EpiJS module for creating custom models, which are made of compartments.

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

Create a model.

### Parameters

*   `compartments` **[Array][20]** Compartments in the model. Each should be a list, with the first value being the compartment, and the second being it's start value in the key.
*   `key` **[Object][21]** The key of values for any variable used in the equation. If you use any variable which represents the population of a compartment, add the starting value into the 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 key = {
 "S": 10000,
 "B": 0.3,
 "I": 100,
 "R": 0,
 "p": 10100,
 "u": 0.2
};

let sirm = new Model([[susceptible, "S"], [infected, "I"], [recovered, "R"]], key)
```

### get_data

Get data for the outbreak.

#### Parameters

*   `time` **[Number][22]** The total time to model.

#### 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 key = {
 "S": 10000,
 "B": 0.3,
 "I": 100,
 "R": 0,
 "p": 10100,
 "u": 0.2
};

let sirm = new Model([[susceptible, "S"], [infected, "I"], [recovered, "R"]], key)

model.get_data(100) // Get data for 100 days.
```

### remove

Remove a compartment from the model.

#### Parameters

*   `compartment` **[Object][21]** The compartment to remove.

#### 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 key = {
	"S": 10000,
	"B": 0.3,
	"I": 100,
	"R": 0,
	"p": 10100,
	"u": 0.2
};

let sirm = new Model([[susceptible, "S"], [infected, "I"], [recovered, "R"]], key)

sirm.remove(recovered) // Removes the recovered compartment.
```

### add

Add a compartment to the model.

#### Parameters

*   `compartment` **[Array][20]** The compartment to add, should be a list, with the first value being the compartment, and the second being it's value in the 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 key = {
	"S": 10000,
	"B": 0.3,
[1]: #model-2
	"R": 0,
	"p": 10100,
	"u": 0.2
[3]: #get-data

let sirm = new Model([[susceptible, "S"], [infected, "I"], [recovered, "R"]], key)

sirm.remove(susceptible) // Removes the susceptible compartment.
sirm.add([susceptible, "S"]) // Adds the susceptible compartment back.
```

## mexport

NodeJS only! Exports models to a file which can then be imported later on.

### Parameters

*   `model`  The EpiJS model to export
*   `output` **[String][23]** The output file path, doesn't have to exist
*   `file_type` **[String][23]** The file type to output. Supported inputs are ".json" and ".js". (optional, default `".json"`)

### 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 key = {
 "S": 10000,
 "B": 0.3,
 "I": 100,
 "R": 0,
 "p": 10100,
 "u": 0.2
};

let sirm = new Model([[susceptible, "S"], [infected, "I"], [recovered, "R"]], key)

mexport(sirm, "output.js", file_type=".js")
```

## mimport

NodeJS only! Imports a model from a file.

### Parameters

*   `input` **[String][23]** The input file path, as a relative path.
*   `file_type` **[String][23]** The file type of the input. Supported inputs are ".json" and ".js". (optional, default `".json"`)

### Examples

```javascript
// Use mexport to export a model into a file
let sirm = mimport("./output.json")
```

[1]: #fs

[2]: #model

[3]: #parameters

[4]: #examples

[5]: #get_data

[6]: #parameters-1

[7]: #examples-1

[8]: #remove

[9]: #parameters-2

[10]: #examples-2

[11]: #add

[12]: #parameters-3

[13]: #examples-3

[14]: #mexport

[15]: #parameters-4

[16]: #examples-4

[17]: #mimport

[18]: #parameters-5

[19]: #examples-5

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

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

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

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