Skip to contents

Merges epidemiological data from two independent simulations of stochastic individual contact models from icm.

Usage

# S3 method for class 'icm'
merge(x, y, ...)

Arguments

x

An EpiModel object of class icm.

y

Another EpiModel object of class icm, with the identical model parameterization as x.

...

Additional merge arguments (not used).

Value

An EpiModel object of class icm containing the data from both x and y.

Details

This merge function combines the results of two independent simulations of icm class models, simulated under separate function calls. The model parameterization between the two calls must be exactly the same, except for the number of simulations in each call. This allows for manual parallelization of model simulations.

This merge function does not work the same as the default merge, which allows for a combined object where the structure differs between the input elements. Instead, the function checks that objects are identical in model parameterization in every respect (except number of simulations) and binds the results.

Examples

param <- param.icm(inf.prob = 0.2, act.rate = 0.8)
init <- init.icm(s.num = 1000, i.num = 100)
control <- control.icm(type = "SI", nsteps = 10,
                       nsims = 3, verbose = FALSE)
x <- icm(param, init, control)

control <- control.icm(type = "SI", nsteps = 10,
                       nsims = 1, verbose = FALSE)
y <- icm(param, init, control)

z <- merge(x, y)

# Examine separate and merged data
as.data.frame(x)
#>    sim time s.num i.num  num si.flow
#> 1    1    1  1000   100 1100       0
#> 2    1    2   985   115 1100      15
#> 3    1    3   961   139 1100      24
#> 4    1    4   940   160 1100      21
#> 5    1    5   909   191 1100      31
#> 6    1    6   884   216 1100      25
#> 7    1    7   860   240 1100      24
#> 8    1    8   839   261 1100      21
#> 9    1    9   813   287 1100      26
#> 10   1   10   779   321 1100      34
#> 11   2    1  1000   100 1100       0
#> 12   2    2   983   117 1100      17
#> 13   2    3   972   128 1100      11
#> 14   2    4   947   153 1100      25
#> 15   2    5   925   175 1100      22
#> 16   2    6   902   198 1100      23
#> 17   2    7   875   225 1100      27
#> 18   2    8   850   250 1100      25
#> 19   2    9   814   286 1100      36
#> 20   2   10   780   320 1100      34
#> 21   3    1  1000   100 1100       0
#> 22   3    2   986   114 1100      14
#> 23   3    3   967   133 1100      19
#> 24   3    4   941   159 1100      26
#> 25   3    5   918   182 1100      23
#> 26   3    6   901   199 1100      17
#> 27   3    7   875   225 1100      26
#> 28   3    8   850   250 1100      25
#> 29   3    9   821   279 1100      29
#> 30   3   10   792   308 1100      29
as.data.frame(y)
#>    sim time s.num i.num  num si.flow
#> 1    1    1  1000   100 1100       0
#> 2    1    2   989   111 1100      11
#> 3    1    3   968   132 1100      21
#> 4    1    4   948   152 1100      20
#> 5    1    5   919   181 1100      29
#> 6    1    6   884   216 1100      35
#> 7    1    7   848   252 1100      36
#> 8    1    8   826   274 1100      22
#> 9    1    9   799   301 1100      27
#> 10   1   10   758   342 1100      41
as.data.frame(z)
#>    sim time s.num i.num  num si.flow
#> 1    1    1  1000   100 1100       0
#> 2    1    2   985   115 1100      15
#> 3    1    3   961   139 1100      24
#> 4    1    4   940   160 1100      21
#> 5    1    5   909   191 1100      31
#> 6    1    6   884   216 1100      25
#> 7    1    7   860   240 1100      24
#> 8    1    8   839   261 1100      21
#> 9    1    9   813   287 1100      26
#> 10   1   10   779   321 1100      34
#> 11   2    1  1000   100 1100       0
#> 12   2    2   983   117 1100      17
#> 13   2    3   972   128 1100      11
#> 14   2    4   947   153 1100      25
#> 15   2    5   925   175 1100      22
#> 16   2    6   902   198 1100      23
#> 17   2    7   875   225 1100      27
#> 18   2    8   850   250 1100      25
#> 19   2    9   814   286 1100      36
#> 20   2   10   780   320 1100      34
#> 21   3    1  1000   100 1100       0
#> 22   3    2   986   114 1100      14
#> 23   3    3   967   133 1100      19
#> 24   3    4   941   159 1100      26
#> 25   3    5   918   182 1100      23
#> 26   3    6   901   199 1100      17
#> 27   3    7   875   225 1100      26
#> 28   3    8   850   250 1100      25
#> 29   3    9   821   279 1100      29
#> 30   3   10   792   308 1100      29
#> 31   4    1  1000   100 1100       0
#> 32   4    2   989   111 1100      11
#> 33   4    3   968   132 1100      21
#> 34   4    4   948   152 1100      20
#> 35   4    5   919   181 1100      29
#> 36   4    6   884   216 1100      35
#> 37   4    7   848   252 1100      36
#> 38   4    8   826   274 1100      22
#> 39   4    9   799   301 1100      27
#> 40   4   10   758   342 1100      41