# trajectory: Extract data from a simulated trajectory In SimInf: A Framework for Data-Driven Stochastic Disease Spread Simulations

## Description

Extract the number of individuals in each compartment in every node after generating a single stochastic trajectory with run.

## Usage

  1 2 3 4 5 6 7 8 9 10 11 12 13 14 trajectory( model, compartments = NULL, index = NULL, format = c("data.frame", "matrix") ) ## S4 method for signature 'SimInf_model' trajectory( model, compartments = NULL, index = NULL, format = c("data.frame", "matrix") ) 

## Arguments

 model the model to extract the result from. compartments specify the names of the compartments to extract data from. The compartments can be specified as a character vector e.g. compartments = c('S', 'I', 'R'), or as a formula e.g. compartments = ~S+I+R (see ‘Examples’). Default (compartments=NULL) is to extract the number of individuals in each compartment i.e. the data from all discrete state compartments in the model. In models that also have continuous state variables e.g. the SISe model, use ~. instead of NULL to also include these. index indices specifying the subset of nodes to include when extracting data. Default (index = NULL) is to extract data from all nodes. format the default (format = "data.frame") is to generate a data.frame with one row per node and time-step with the number of individuals in each compartment. Using format = "matrix" returns the result as a matrix, which is the internal format (see ‘Details’).

## Value

A data.frame if format = "data.frame", else a matrix.

## Internal format of the discrete state variables

Description of the layout of the internal matrix (U) that is returned if format = "matrix". U[, j] contains the number of individuals in each compartment at tspan[j]. U[1:Nc, j] contains the number of individuals in node 1 at tspan[j]. U[(Nc + 1):(2 * Nc), j] contains the number of individuals in node 2 at tspan[j] etc, where Nc is the number of compartments in the model. The dimension of the matrix is N_n N_c \times length(tspan) where N_n is the number of nodes.

## Internal format of the continuous state variables

Description of the layout of the matrix that is returned if format = "matrix". The result matrix for the real-valued continuous state. V[, j] contains the real-valued state of the system at tspan[j]. The dimension of the matrix is N_ndim(ldata)[1] \times length(tspan).

## Examples

  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 ## Create an 'SIR' model with 6 nodes and initialize ## it to run over 10 days. u0 <- data.frame(S = 100:105, I = 1:6, R = rep(0, 6)) model <- SIR(u0 = u0, tspan = 1:10, beta = 0.16, gamma = 0.077) ## Run the model to generate a single stochastic trajectory. result <- run(model) ## Extract the number of individuals in each compartment at the ## time-points in 'tspan'. trajectory(result) ## Extract the number of recovered individuals in the first node ## at the time-points in 'tspan'. trajectory(result, compartments = "R", index = 1) ## Extract the number of recovered individuals in the first and ## third node at the time-points in 'tspan'. trajectory(result, compartments = "R", index = c(1, 3)) ## Create an 'SISe' model with 6 nodes and initialize ## it to run over 10 days. u0 <- data.frame(S = 100:105, I = 1:6) model <- SISe(u0 = u0, tspan = 1:10, phi = rep(0, 6), upsilon = 0.02, gamma = 0.1, alpha = 1, epsilon = 1.1e-5, beta_t1 = 0.15, beta_t2 = 0.15, beta_t3 = 0.15, beta_t4 = 0.15, end_t1 = 91, end_t2 = 182, end_t3 = 273, end_t4 = 365) ## Run the model result <- run(model) ## Extract the continuous state variable 'phi' which represents ## the environmental infectious pressure. trajectory(result, "phi") 

### Example output

   node time   S  I R
1     1    1 100  1 0
2     2    1 101  2 0
3     3    1 101  4 0
4     4    1 102  4 1
5     5    1 104  5 0
6     6    1 103  8 0
7     1    2 100  1 0
8     2    2 101  2 0
9     3    2  99  6 0
10    4    2 101  5 1
11    5    2 103  6 0
12    6    2 103  8 0
13    1    3  99  2 0
14    2    3 101  2 0
15    3    3  98  7 0
16    4    3 100  6 1
17    5    3 102  7 0
18    6    3 103  8 0
19    1    4  98  3 0
20    2    4 101  2 0
21    3    4  96  9 0
22    4    4  99  6 2
23    5    4 102  6 1
24    6    4  99 10 2
25    1    5  97  4 0
26    2    5 101  2 0
27    3    5  95  9 1
28    4    5  99  6 2
29    5    5 101  6 2
30    6    5  97 12 2
31    1    6  96  5 0
32    2    6 101  1 1
33    3    6  94 10 1
34    4    6  97  8 2
35    5    6  97 10 2
36    6    6  93 15 3
37    1    7  95  6 0
38    2    7 101  1 1
39    3    7  93  9 3
40    4    7  96  8 3
41    5    7  97  9 3
42    6    7  89 16 6
43    1    8  94  5 2
44    2    8 101  1 1
45    3    8  91 11 3
46    4    8  95  9 3
47    5    8  96 10 3
48    6    8  86 19 6
49    1    9  92  6 3
50    2    9  99  3 1
51    3    9  88 14 3
52    4    9  93  9 5
53    5    9  96  9 4
54    6    9  82 23 6
55    1   10  92  6 3
56    2   10  97  5 1
57    3   10  87 14 4
58    4   10  93  7 7
59    5   10  95  9 5
60    6   10  81 23 7
node time R
1     1    1 0
2     1    2 0
3     1    3 0
4     1    4 0
5     1    5 0
6     1    6 0
7     1    7 0
8     1    8 2
9     1    9 3
10    1   10 3
node time R
1     1    1 0
2     3    1 0
3     1    2 0
4     3    2 0
5     1    3 0
6     3    3 0
7     1    4 0
8     3    4 0
9     1    5 0
10    3    5 1
11    1    6 0
12    3    6 1
13    1    7 0
14    3    7 3
15    1    8 2
16    3    8 3
17    1    9 3
18    3    9 3
19    1   10 3
20    3   10 4
node time         phi
1     1    1 0.009911990
2     2    1 0.009719738
3     3    1 0.028582429
4     4    1 0.037394178
5     5    1 0.045882560
6     6    1 0.045056045
7     1    2 0.018337182
8     2    2 0.017981515
9     3    2 0.052877493
10    4    2 0.059833434
11    5    2 0.084882735
12    6    2 0.083353683
13    1    3 0.025498595
14    2    3 0.015295288
15    3    3 0.073528298
16    4    3 0.069561008
17    5    3 0.108858573
18    6    3 0.106897667
19    1    4 0.031585795
20    2    4 0.022720732
21    3    4 0.091081481
22    4    4 0.077829445
23    5    4 0.110889411
24    6    4 0.126910053
25    1    5 0.026858926
26    2    5 0.029032360
27    3    5 0.106001688
28    4    5 0.084857617
29    5    5 0.112615623
30    6    5 0.143920581
31    1    6 0.022841087
32    2    6 0.034397244
33    3    6 0.128207673
34    4    6 0.090831564
35    5    6 0.114082903
36    6    6 0.167388539
37    1    7 0.019425924
38    2    7 0.038957395
39    3    7 0.137558950
40    4    7 0.095909418
41    5    7 0.115330092
42    6    7 0.187336303
43    1    8 0.016523036
44    2    8 0.052542262
45    3    8 0.145507536
46    4    8 0.090879800
47    5    8 0.116390202
48    6    8 0.204291903
49    1    9 0.014055580
50    2    9 0.044671923
51    3    9 0.152263835
52    4    9 0.095950418
53    5    9 0.117291295
54    6    9 0.209695153
55    1   10 0.011958243
56    2   10 0.037982134
57    3   10 0.158006688
58    4   10 0.100260444
59    5   10 0.118057225
60    6   10 0.214287916


SimInf documentation built on Dec. 6, 2020, 5:07 p.m.