Learn R Programming

population (version 0.3)

project_parallel: Parallel population projections

Description

Run parallel stochastic population projections. Non-Windows systems only.

Usage

project_parallel(years, runs, initial_population, survival, litter, cores)

Arguments

years

Number of years to project the population.

runs

Number of times (or Monte Carlo runs) to project the population.

initial_population

Vector of initial number of individuals for each class. This vector must contain only positive integers.

survival

Matrix of survival for each class, with nrow = number of classes and ncol = 2. The first column is the median value of the survival of each class. The second column is the standard deviation of the survival of each class.

litter

Matrix of litter size for each class, with nrow = number of classes and ncol = 2. The first column is the median value of the litter size of each class. The second column is the standard deviation of the litter size of each class.

cores

(optional) number of cores to use for the parallel projections. If missing, it is set to the value returned by get_cores().

Value

runs

a 3-dimensional array of numbers of individuals with dimension c(years, classes, runs)

%% ...

Details

Run parallel stochastic population projections with an Individual-Based Model (IBM) compiled in C.

Examples

Run this code
# NOT RUN {
years <- 10
runs <- 100

init.pop <- c(30, 20, 15, 12, 10, 9, 8, 7, 6, 5)

surv.md <- c(0.5, 0.7, 0.9, 0.9, 0.9, 0.9, 0.9, 0.9, 0.9, 0.9)
surv.sd <- c(0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1)
surv.msd <- cbind(surv.md, surv.sd)

litter.md <- c(0.2, 1.1, 2.8, 2.8, 2.8, 2.8, 2.8, 2.8, 1.8, 0.2)
litter.sd <- c(0.1, 0.2, 0.15, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1)
litter.msd <- cbind(litter.md, litter.sd)

nclass <- 4 # vary number of classes

# with 2 cores
projection <- project_parallel(
	years = years,
	runs = runs,
	initial_population = init.pop[1:nclass],
	survival = surv.msd[1:nclass,],
	litter = litter.msd[1:nclass,],
	cores = 2
	)

# with all possible cores (not run)
# projection <- project_parallel(
# 	years = years,
# 	runs = runs,
# 	initial_population = init.pop[1:nclass],
# 	survival = surv.msd[1:nclass,],
# 	litter = litter.msd[1:nclass,]
# )
# }

Run the code above in your browser using DataLab