The latest stable version can be installed from CRAN:
install.packages('IBMPopSim')
The latest development version can be installed from github:
# install.packages("devtools")
devtools::install_github('DaphneGiorgi/IBMPopSim')
First example to check installation
To illustrate the use of the package and to check the installation, a
simple model with Poisson arrivals and exits is implemented. Starting
from an initial population pop
, we define two events
birth
and death
with intensity of Poisson
type, we create the model birth_death
and simulate the
population evolution over 10 years.
library(IBMPopSim)
init_size <- 100000
pop_init <- population(data.frame(birth = rep(0, init_size), death = NA))
birth = mk_event_poisson(type = 'birth', intensity = 'lambda')
death = mk_event_poisson(type = 'death', intensity = 'mu')
params = list('lambda' = 100, 'mu' = 100)
# mk_model compiles C++ code using sourceCpp from Rcpp
birth_death <- mk_model(characteristics = get_characteristics(pop_init),
events = list(birth, death),
parameters = params)
sim_out <- popsim(model = birth_death,
initial_population = pop_init,
events_bounds = c('birth' = params$lambda, 'death' = params$mu),
parameters = params,
time = 10)
num_births <- length(sim_out$population$birth) - init_size
num_deaths <- sum(!is.na(sim_out$population$death))
print(c("births" = num_births, "deaths" = num_deaths))
## births deaths
## 950 1007