Title: | Individual Based Models in R |
---|---|
Description: | Implementation of some (simple) Individual Based Models and methods to create new ones, particularly for population dynamics models (reproduction, mortality and movement). The basic operations for the simulations are implemented in Rcpp for speed. |
Authors: | Ricardo Oliveros-Ramos [aut, cre] |
Maintainer: | Ricardo Oliveros-Ramos <[email protected]> |
License: | GPL-2 |
Version: | 0.3.0 |
Built: | 2025-02-08 03:35:56 UTC |
Source: | https://github.com/roliveros-ramos/ibm |
Implementation of some (simple) Individual Based Models and methods to create new ones, particularly for population dynamics models (reproduction, mortality and movement). The basic operations for the simulations are implemented in Rcpp for speed.
Ricardo Oliveros-Ramos <[email protected]>
## Not run: set.seed(880820) par = list(alpha=5e-4, beta=5e-4, r=0.1, m=0.05, D=list(N=8e-5, P=8e-5), L=list(N=0.2, P=0.2)) N0 = with(par, m/(2*beta*L$P)) P0 = with(par, r/(2*alpha*L$N)) par$initial = list(N=round(N0), P=round(P0)) sim = localLotkaVolterra(par, T=240, replicates=100, maxpop = 1e4) plot(sim) ## End(Not run)
## Not run: set.seed(880820) par = list(alpha=5e-4, beta=5e-4, r=0.1, m=0.05, D=list(N=8e-5, P=8e-5), L=list(N=0.2, P=0.2)) N0 = with(par, m/(2*beta*L$P)) P0 = with(par, r/(2*alpha*L$N)) par$initial = list(N=round(N0), P=round(P0)) sim = localLotkaVolterra(par, T=240, replicates=100, maxpop = 1e4) plot(sim) ## End(Not run)
Set spatial restrictions to the domain.
boundaries(x, ...)
boundaries(x, ...)
x |
The positions of the particles. |
... |
Additional arguments for different methods. |
Boundaries is a generic and methods can be written. The default applies simmetric boundaries (dynamics over a torus) or reflexive barriers.
This funtions performs a brownian difussion over a set of particles. The dimension is automatically calculated from the number of columns of the object.
diffusion(object, sd, ...)
diffusion(object, sd, ...)
object |
The positions of the particles, dimension is taken from the number of columns or assumed to be 1 is no columns. |
sd |
Standard deviation for the gaussian jump, for dynamics models should be
set proportional to |
... |
Additional arguments for different methods. |
This functions apply a brownian diffusion to a set of point coordinates.
This function simulates several trajectories for a Lotka-Volterra model with local predation interactions as decribed in Brigatti et al. (2009).
localLotkaVolterra( par, T, replicates = 1, dim = 1, periodic = TRUE, spatial = FALSE, verbose = FALSE, maxpop = 1e+06, fill = NA, probs = seq(0, 1, 0.01) )
localLotkaVolterra( par, T, replicates = 1, dim = 1, periodic = TRUE, spatial = FALSE, verbose = FALSE, maxpop = 1e+06, fill = NA, probs = seq(0, 1, 0.01) )
par |
A list containing the parameters to run the model, currently the growth rate of prey (r), the mortality rate of predator (l), predation interaction parameters (alpha and beta), diffusion rates (D), diameters of local interaction (L) and initial population size (initial). For D, L and initial population, a list with two values (named N and P) is required. |
T |
Time horizon, number of time steps to be simulated. |
replicates |
Number of replicates (trajectories) to be simulated. |
dim |
Spatial dimension for the space. Can be 1, 2 or 3. |
periodic |
Spatial boundary conditions. If |
spatial |
Boolean, should spatial outputs (position of individuals) to be saved? |
verbose |
Boolean, to print population sizes by step? |
maxpop |
Maximum population size. If predator or prey population size |
fill |
Value to initially fill the population arrays. Default to NA, 0 is an option too. |
probs |
Vector of probabilities to compute quantiles of the predator-prey interactions. get bigger, the simulation ends. |
A list with the following elements:
N |
A matrix with prey population sizes by time (rows) and replicates (columns) |
P |
A matrix with predator population sizes by time (rows) and replicates (columns) |
pop |
Prey and predator positions by time, if |
Ricardo Oliveros–Ramos
Brigatti et al. 2009.
## Not run: set.seed(880820) par = list(alpha=5e-4, gamma=0.5, r=0.1, m=0.05, D=list(N=8e-5, P=8e-5), L=list(N=0.2, P=0.2)) N0 = with(par, m/(2*gamma*alpha*L$P)) P0 = with(par, r/(2*alpha*L$N)) par$initial = list(N=round(N0), P=round(P0)) sim = localLotkaVolterra(par, T=240, replicates=100, maxpop = 1e4) plot(sim) ## End(Not run)
## Not run: set.seed(880820) par = list(alpha=5e-4, gamma=0.5, r=0.1, m=0.05, D=list(N=8e-5, P=8e-5), L=list(N=0.2, P=0.2)) N0 = with(par, m/(2*gamma*alpha*L$P)) P0 = with(par, r/(2*alpha*L$N)) par$initial = list(N=round(N0), P=round(P0)) sim = localLotkaVolterra(par, T=240, replicates=100, maxpop = 1e4) plot(sim) ## End(Not run)
This functions performs the 'mortality' process over an object, decreasing the number of individuals. It is a generic, S3 methods can be specified for a particular specification of the population.
mortality(object, rates, ...)
mortality(object, rates, ...)
object |
The population object, containing the information about individuals. |
rates |
The mortality rate or rates. |
... |
Additional arguments for different methods. |
The rate can be a single value or a value for each individual calculated externally. No recycling is allowed.
This functions performs the 'reproduction' process over an object, increasing the number of individuals. It is a generic, S3 methods can be specified for a particular specification of the population.
reproduction(object, rates, ...)
reproduction(object, rates, ...)
object |
The population object, containing the information about individuals. |
rates |
The reproduction rate or rates. |
... |
Additional arguments for different methods. |
The rate can be a single value or a value for each individual calculated externally. No recycling is allowed.