hybridModel: Hybrid model simulation.

Description Usage Arguments Value References See Also Examples

View source: R/hybrid_Model.R

Description

hybridModel function runs hybrid models simulations.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
hybridModel(
  network = stop("undefined 'network'"),
  var.names = NULL,
  link.type = "migration",
  model = "custom",
  probWeights = NULL,
  emigrRule = NULL,
  init.cond = stop("undefined 'initial conditions'"),
  fill.time = F,
  model.parms = stop("undefined 'model parmeters'"),
  prop.func = NULL,
  state.var = NULL,
  infl.var = NULL,
  state.change.matrix = NULL,
  ssa.method = NULL,
  nodesCensus = NULL,
  sim.number = 1,
  pop.correc = TRUE,
  num.cores = "max"
)

Arguments

network

a data.frame with variables that describe the donor node, the receiver node, the time when each connection between donor to the receiver happened and the number of individual or weight of these connection.

var.names

a list with variable names of the network: the donor node, the receiver node, the time when each connection between donor to the receiver happened and the weight of these connection. The variables names must be "from", "to", "Time" and "arc", respectively.

link.type

a character describing the link type between nodes. There are two types: 'migration' and 'influence'. In the migration link type there are actual migration between nodes. In the influence link type individuals does not migrate, just influences another node.

model

a character describing model's name.

probWeights

a named vector (optional and for migration type only) mapping state variables to migration probability weights based on state variables. These argument can be used to give weights for sampling individuals from node. They need not sum to one, they should be non-negative and not zero. For more information on the sampling method sample.

emigrRule

a string (optional and for migration type only) stating how many individual emigrate based on state variables. It requires that the network have weights instead of number of individuals that migrate.

init.cond

a named vector with initial conditions.

fill.time

It indicates whether to return all dates or just the dates when nodes get connected.

model.parms

a named vector with model's parameters.

prop.func

a character vector with propensity functions of a generic node. See references for more details

state.var

a character vector with the state variables of the propensity functions.

infl.var

a named vector mapping state variables to influence variables.

state.change.matrix

is a state-change matrix. See references for more details

ssa.method

a list with SSA parameters. The default method is the direct method. See references for more details

nodesCensus

a data.frame with the first column describing nodes' ID, the second column with the number of individuals and the third describing the day of the census.

sim.number

Number of repetitions.The default value is 1

pop.correc

Whether hybridModel function tries to balance the number of individuals or not. The default value is TRUE.

num.cores

number of threads/cores that the simulation will use. the default value is num.cores = 'max', the Algorithm will use all threads/cores available.

Value

Object containing a data.frame (results) with the number of individuals through time per node and per state.

References

[1] Pineda-krch, M. (2008). GillespieSSA : Implementing the Stochastic Simulation Algorithm in R. Journal of Statistical Software, Volume 25 Issue 12 <doi:10.1146/annurev.physchem.58.032806.104637>.

[2] Fernando S. Marques, Jose H. H. Grisi-Filho, Marcos Amaku et al. hybridModels: An R Package for the Stochastic Simulation of Disease Spreading in Dynamic Network. In: Jounal of Statistical Software Volume 94, Issue 6 <doi:10.18637/jss.v094.i06>.

See Also

GillespieSSA.

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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# Migration model
# Parameters and initial conditions for an SIS model
# loading the data set 
data(networkSample) # help("networkSample"), for more info
networkSample <- networkSample[which(networkSample$Day < "2012-03-20"),]

var.names <- list(from = 'originID', to = 'destinationID', Time = 'Day',
                  arc = 'num.animals')
                  
prop.func <- c('beta * S * I / (S + I)', 'gamma * I')
state.var <- c('S', 'I')
state.change.matrix <- matrix(c(-1,  1,  # S
                                 1, -1), # I
                              nrow = 2, ncol = 2, byrow = TRUE)
                              
model.parms <- c(beta = 0.1, gamma = 0.01)

init.cond <- rep(100, length(unique(c(networkSample$originID,
                                      networkSample$destinationID))))
names(init.cond) <- paste('S', unique(c(networkSample$originID,
                                        networkSample$destinationID)), sep = '')
init.cond <- c(init.cond, c(I36811 = 10, I36812 = 10)) # adding infection
                  
# running simulations, check the number of cores available (num.cores)
sim.results <- hybridModel(network = networkSample, var.names = var.names,
                           model.parms = model.parms, state.var = state.var,
                           prop.func = prop.func, init.cond = init.cond,
                           state.change.matrix = state.change.matrix,
                           sim.number = 2, num.cores = 2)

# default plot layout (plot.types: 'pop.mean', 'subpop', or 'subpop.mean')
plot(sim.results, plot.type = 'subpop.mean')

# changing plot layout with ggplot2 (example)
# uncomment the lines below to test new layout exemple
#library(ggplot2)
#plot(sim.results, plot.type = 'subpop') + ggtitle('New Layout') + 
#  theme_bw() + theme(axis.title = element_text(size = 14, face = "italic"))

# Influence model
# Parameters and initial conditions for an SIS model
# loading the data set 
data(networkSample) # help("networkSample"), for more info
networkSample <- networkSample[which(networkSample$Day < "2012-03-20"),]

var.names <- list(from = 'originID', to = 'destinationID', Time = 'Day',
                  arc = 'num.animals')
                  
prop.func <- c('beta * S * (I + i) / (S + I + s + i)', 'gamma * I')
state.var <- c('S', 'I')
infl.var <- c(S = "s", I = "i") # mapping influence
state.change.matrix <- matrix(c(-1,  1,  # S
                                 1, -1), # I
                              nrow = 2, ncol = 2, byrow = TRUE)
                              
model.parms <- c(beta = 0.1, gamma = 0.01)

init.cond <- rep(100, length(unique(c(networkSample$originID,
                                      networkSample$destinationID))))
names(init.cond) <- paste('S', unique(c(networkSample$originID,
                                        networkSample$destinationID)), sep = '')
init.cond <- c(init.cond, c(I36811 = 10, I36812 = 10)) # adding infection
                  
# running simulations, check num of cores available (num.cores)
# Uncomment to run
# sim.results <- hybridModel(network = networkSample, var.names = var.names,
#                            model.parms = model.parms, state.var = state.var,
#                            infl.var = infl.var, prop.func = prop.func,
#                            init.cond = init.cond,
#                            state.change.matrix = state.change.matrix,
#                            sim.number = 2, num.cores = 2)

# default plot layout (plot.types: 'pop.mean', 'subpop', or 'subpop.mean')
# plot(sim.results, plot.type = 'subpop.mean')

hybridModels documentation built on July 1, 2020, 7:51 p.m.