Learn R Programming

hybridModels (version 0.2.6)

hybridModel: Hybrid model simulation.

Description

hybridModel function runs hybrid models simulations.

Usage

hybridModel(network, var.names, link.type = "migration", model = "custom", init.cond, fill.time = F, model.parms, prop.func = NULL, state.change.matrix = NULL, state.var = NULL, ssa.method = list(method = "D", epsilon = 0.03, nc = 10, dtf = 10, nd = 100), nodesCensus = NULL, sim.number = 1, pop.correc = TRUE, num.cores = "max")

Arguments

network
a data.frame with variables that describe the donor node, the reciever node, the time when each connection between donor to the reciever happened and the weight of these connection.
var.names
a list with variable names of the network: the donor node, the reciever node, the time when each connection between donor to the reciever 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.
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.change.matrix
is a state-change matrix. See references for more details
state.var
a character vector with the state varialbes of the propensity functions.
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 algothim 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, 25(12).

See Also

GillespieSSA.

Examples

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

var.names <- list(from = 'originID', to = 'destinyID', Time = 'Dia',
                  arc = 'num.animais')
                  
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$destinyID))))
names(init.cond) <- paste('S', unique(c(networkSample$originID,
                                        networkSample$destinyID)), sep = '')
init.cond <- c(init.cond, c(I36811 = 10, I36812 = 10)) # adding infection
                  
# running simulations, check num 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"))

Run the code above in your browser using DataLab