| Title: | Toolkits to Develop Individual-Based Models in Infectious Disease |
|---|---|
| Description: | It provides a generic set of tools for initializing a synthetic population with each individual in specific disease states, and making transitions between those disease states according to the rates calculated on each timestep. The new version 1.0.0 has C++ code integration to make the functions run faster. It has also a higher level function to actually run the transitions for the number of timesteps that users specify. Additional functions will follow for changing attributes on demographic, health belief and movement. |
| Authors: | Sai Thein Than Tun [aut, cre] |
| Maintainer: | Sai Thein Than Tun <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 1.0.0 |
| Built: | 2026-06-02 08:00:38 UTC |
| Source: | https://github.com/saitheinthantun/ibmcraftr |
This function takes in a vector of probabilities of states transitions and calculate the probability of staying in the original state and output the cumulative probabilities for all possibilities.
cumprob(probs, actual = FALSE)cumprob(probs, actual = FALSE)
probs |
A numeric vector of the probabilities of transition to states. |
actual |
A logical value, if TRUE, will calculate actual cumulative probabilities which may surpass 1!. |
A numeric vector of cumulative probabilites inclusive of the probability of having the same state in the next timestep.
cumprob(c(.2,.2,.9)) cumprob(c(.2,.2,.9), actual=TRUE) cumprob(c(.2,.2,.2))cumprob(c(.2,.2,.9)) cumprob(c(.2,.2,.9), actual=TRUE) cumprob(c(.2,.2,.2))
ibmcraftr packare are here.Miscellaneous functions to support the ibmcraftr packare are here.
rate2prob(rates)rate2prob(rates)
rates |
A numeric scalar or vector to be transformed into rates. |
A numeric scalar or vector in terms of probabilities.
rate2prob(c(.1, .5))rate2prob(c(.1, .5))
Organize population data and transition parameters to run state_trans function over the given number of timesteps.
run_state_trans(timesteps, param, pop, transient = "", useC = TRUE)run_state_trans(timesteps, param, pop, transient = "", useC = TRUE)
timesteps |
A numeric scalar based on which the state_trans function will run for that specific no. of |
param |
A list of lists. Each low-level list must contain transition parameters required by the |
pop |
A state matrix created from |
transient |
A character vector. Each element must include formula(e)/expression(s) to evaluate dynamic parameters after each timestep. |
useC |
A logical value, which is TRUE by default, will run |
A summary matrix of the states all individuals in the population are in.
pop <- syn_pop(c(19,1,0,0,0)) #synthesizing population b <- 2 #effective contact rate param <- list( list(1,c(2,5),c(NA,.1)), #transition from state 1 to 2 using FOI lambda list(2,3,100), #transition from state 2 to 3, list(3,4,100) #the 3rd term ensures the transition to the next stage ) timesteps <- 10 transient <- c("param[[1]][[3]][1] <- rate2prob(b*sum(pop[,2],pop[,3])/sum(pop))") eval(parse(text=transient)) run_state_trans(timesteps, param, pop, transient) run_state_trans(timesteps, param, pop, transient, useC = FALSE)pop <- syn_pop(c(19,1,0,0,0)) #synthesizing population b <- 2 #effective contact rate param <- list( list(1,c(2,5),c(NA,.1)), #transition from state 1 to 2 using FOI lambda list(2,3,100), #transition from state 2 to 3, list(3,4,100) #the 3rd term ensures the transition to the next stage ) timesteps <- 10 transient <- c("param[[1]][[3]][1] <- rate2prob(b*sum(pop[,2],pop[,3])/sum(pop))") eval(parse(text=transient)) run_state_trans(timesteps, param, pop, transient) run_state_trans(timesteps, param, pop, transient, useC = FALSE)
Take in the matrix of the states of synthetic population (created by syn_pop function)
and calculate the transitions from one state to other state(s) using the transition rate(s).
state_trans(origin, new.states, params, s.matrix)state_trans(origin, new.states, params, s.matrix)
origin |
A number which represents the column index |
new.states |
A numeric vector or a number which represents the column index |
params |
A numeric vector of similar length to |
s.matrix |
A state matrix created from |
A transition matrix of the same dimension as s.matrix. -1 indicates that the individual has left
the corresponding state. +1 indicates that the individual has become the corresponding state.
pop <- syn_pop(c(19,1,0,0)) state_trans(1,2,.1,pop) state_trans(1,4,100,pop)pop <- syn_pop(c(19,1,0,0)) state_trans(1,2,.1,pop) state_trans(1,4,100,pop)
Take in the matrix of the states of synthetic population (created by syn_pop function)
and calculate the transitions from one state to other state(s) using the transition probabilities [not rate(s)].
The major difference from the R alone version was that instead of having the transition rate(s),
transition probabilities are used. These probabilities will thus be calculated with another function.
stRCPP(origin, new.states, params, s.matrix)stRCPP(origin, new.states, params, s.matrix)
origin |
A number which represents the column index |
new.states |
A numeric vector or a number which represents the column index |
params |
A numeric vector of similar length to |
s.matrix |
A state matrix created from |
A transition matrix of the same dimension as s.matrix. -1 indicates that the individual has left
the corresponding state. +1 indicates that the individual has become the corresponding state.
pop <- syn_pop(c(19,1,0,0)) stRCPP(1,2,.1,pop)pop <- syn_pop(c(19,1,0,0)) stRCPP(1,2,.1,pop)
Populate a matrix in which columns represent the states of the individuals and rows represent the individuals.
syn_pop(states, shuffle = FALSE)syn_pop(states, shuffle = FALSE)
states |
A numeric vector with each element representing the number of individuals in a particular state its index corresponds to. |
shuffle |
A logical value to enable shuffling of the individuals (rows) in the resulting matrix. |
A matrix of 0s, and 1s. The rows representing the individuals and the columns representing the states the individuals are in
syn_pop(c(3,2,1)) syn_pop(c(0,0,1,5), shuffle=TRUE)syn_pop(c(3,2,1)) syn_pop(c(0,0,1,5), shuffle=TRUE)