R/single-discrete.R
singleDiscrete.Rd
This function, that can be wrapped within nosoiSim
, runs a single-host transmission chain simulation, with a discrete host population structure (e.g. spatial, socio-economic, etc.). The simulation stops either at
the end of given time (specified by length.sim
) or when the number of hosts infected threshold (max.infected
) is crossed.
singleDiscrete( length.sim, max.infected, init.individuals, init.structure, structure.matrix, diff.pExit = FALSE, timeDep.pExit = FALSE, hostCount.pExit = FALSE, pExit, param.pExit, diff.pMove = FALSE, timeDep.pMove = FALSE, hostCount.pMove = FALSE, pMove, param.pMove, diff.nContact = FALSE, timeDep.nContact = FALSE, hostCount.nContact = FALSE, nContact, param.nContact, diff.pTrans = FALSE, timeDep.pTrans = FALSE, hostCount.pTrans = FALSE, pTrans, param.pTrans, prefix.host = "H", print.progress = TRUE, print.step = 10 )
length.sim | specifies the length (in unit of time) over which the simulation should be run. |
---|---|
max.infected | specifies the maximum number of hosts that can be infected in the simulation. |
init.individuals | number of initially infected individuals. |
init.structure | in which state (e.g. location) the initially infected individuals are located. |
structure.matrix | transition matrix (probabilities) to go from location A (row) to B (column) |
diff.pExit | is pExit different between states of the structured population (TRUE/FALSE) |
timeDep.pExit | is pExit dependent on the absolute time of the simulation? (TRUE/FALSE) |
hostCount.pExit | does pExit varies with the host count in the state? (TRUE/FALSE); diff.pExit should be TRUE. |
pExit | function that gives the probability to exit the simulation for an infected host (either moving out, dying, etc.). |
param.pExit | parameter names (list of functions) for the pExit. |
diff.pMove | is pMove different between states of the structured population (TRUE/FALSE) |
timeDep.pMove | is pMove dependent on the absolute time of the simulation (TRUE/FALSE) |
hostCount.pMove | does pMove varies with the host count in the state? (TRUE/FALSE); diff.pMove should be TRUE. |
pMove | function that gives the probability of a host moving as a function of time. |
param.pMove | parameter names (list of functions) for the pMove. |
diff.nContact | is nContact different between states of the structured population (TRUE/FALSE) |
timeDep.nContact | is nContact dependent on the absolute time of the simulation? (TRUE/FALSE) |
hostCount.nContact | does nContact varies with the host count in the state? (TRUE/FALSE); diff.nContact should be TRUE. |
nContact | function that gives the number of potential transmission events per unit of time. |
param.nContact | parameter names (list of functions) for param.nContact. |
diff.pTrans | is pTrans different between states of the structured population (TRUE/FALSE) |
timeDep.pTrans | is pTrans dependent on the absolute time of the simulation? (TRUE/FALSE) |
hostCount.pTrans | does pTrans varies with the host count in the state? (TRUE/FALSE); diff.pTrans should be TRUE. |
pTrans | function that gives the probability of transmit a pathogen as a function of time since infection. |
param.pTrans | parameter names (list of functions) for the pExit. |
prefix.host | character(s) to be used as a prefix for the hosts identification number. |
print.progress | if TRUE, displays a progress bar (current time/length.sim). |
print.step | print.progress is TRUE, step with which the progress message will be printed. |
An object of class nosoiSim
, containing all results of the simulation.
The pExit
and pTrans
functions should return a single probability (a number between 0 and 1), and nContact
a positive natural number (positive integer) or 0.
The param
arguments should be a list of functions or NA. Each item name in the parameter list should have the same name as the argument in the corresponding function.
The use of timeDep
(switch to TRUE
) makes the corresponding function use the argument prestime
(for "present time").
The structure matrix provided provided should of class matrix
, with the same number of rows and columns, rows representing departure state and column the arrival state. All rows should add to 1.
The pMove
function should return a single probability (a number between 0 and 1).
The use of diff
(switch to TRUE
) makes the corresponding function use the argument current.in
(for "currently in"). Your function should in that case give a result for every possible discrete state.
The use of hostCount
(switch to TRUE
) makes the corresponding function use the argument host.count
.
The user specified function's arguments should follow this order: t
(mandatory), prestime
(optional, only if timeDep is TRUE),
current.in
(optional, only if diff is TRUE), host.count
(optional, only if hostCount is TRUE) and parameters
specified in the list.
For simulations with a structure in continuous space, see singleContinuous
. For simulations without any structures, see singleNone
.
# \donttest{ t_incub_fct <- function(x){rnorm(x,mean = 5,sd=1)} p_max_fct <- function(x){rbeta(x,shape1 = 5,shape2=2)} p_Exit_fct <- function(t){return(0.08)} p_Move_fct <- function(t){return(0.1)} proba <- function(t,p_max,t_incub){ if(t <= t_incub){p=0} if(t >= t_incub){p=p_max} return(p) } time_contact = function(t){round(rnorm(1, 3, 1), 0)} transition.matrix = matrix(c(0,0.2,0.4,0.5,0,0.6,0.5,0.8,0), nrow = 3, ncol = 3, dimnames=list(c("A","B","C"),c("A","B","C"))) set.seed(805) test.nosoiA <- nosoiSim(type="single", popStructure="discrete", length=20, max.infected=100, init.individuals=1, init.structure="A", structure.matrix=transition.matrix, pMove=p_Move_fct, param.pMove=NA, nContact=time_contact, param.nContact=NA, pTrans = proba, param.pTrans = list(p_max=p_max_fct, t_incub=t_incub_fct), pExit=p_Exit_fct, param.pExit=NA)#>#>#>#>#>#># }