hybridModel {hybridModels} | R Documentation |
Hybrid model simulation.
Description
hybridModel
function runs hybrid models simulations.
Usage
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 |
var.names |
a |
link.type |
a |
model |
a |
probWeights |
a named |
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 |
fill.time |
It indicates whether to return all dates or just the dates when nodes get connected. |
model.parms |
a named |
prop.func |
a character |
state.var |
a character |
infl.var |
a named |
state.change.matrix |
is a state-change |
ssa.method |
a |
nodesCensus |
a |
sim.number |
Number of repetitions.The default value is 1 |
pop.correc |
Whether |
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
Examples
# 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')