Learn R Programming

metaRange (version 1.1.4)

dispersal: Dispersal process

Description

Disperse a (abundance) matrix using a dispersal kernel and optional weights.

Usage

dispersal(dispersal_kernel, abundance, weights)

Value

<numeric matrix> Dispersed abundance matrix.

Arguments

dispersal_kernel

<numeric matrix> dispersal kernel.

abundance

<numeric matrix> abundance matrix.

weights

<numeric matrix> optional weights in form of a matrix that has the same dimensions as the abundance and a range: between 0, 1. Should not contain any NA.

Details

The abundance matrix is dispersed using the dispersal kernel. If a matrix of weights is supplied, the individuals will redistribute within the dispersal kernel according to the weights. I.e. individuals will more likely move towards areas with a higher weight, if they are within their dispersal distance. Note:

  • the abundance is modified in place, to optimize performance.

  • Any NA or NaN in abundance or weights will be (in-place) replaced by 0.

Examples

Run this code
n <- 10
n2 <- n^2
abu <- matrix(1:n2, nrow = n, ncol = n)
suitab <- matrix(1, nrow = n, ncol = n)
kernel <- calculate_dispersal_kernel(
    max_dispersal_dist = 4,
    kfun = negative_exponential_function,
    mean_dispersal_dist = 1.2
)
res1 <- dispersal(
    dispersal_kernel = kernel,
    abundance = abu
)
res2 <- dispersal(
    dispersal_kernel = kernel,
    abundance = abu,
    weights = suitab
)
stopifnot(sum(res1) - sum(res2) < 0.01)
# Note that the abundance is modified in place, i.e:
stopifnot(sum(abu - res2) < 0.01)

Run the code above in your browser using DataLab