Learn R Programming

mrangr (version 1.0.1)

K_sim: Carrying Capacity Map Simulator

Description

Generates multiple carrying capacity maps based on spatially autocorrelated Gaussian Random Fields (GRFs), with optional correlation between layers.

Usage

K_sim(n, id, range, cor_mat = NULL, qfun = qnorm, ...)

Value

A SpatRaster object with n layers, each representing a carrying capacity map.

Arguments

n

Integer. Number of maps to generate.

id

A SpatRaster object used as a geographic template.

range

Numeric. Spatial autocorrelation parameter passed to the grf function.

cor_mat

Optional correlation matrix. If NULL, maps are generated independently.

qfun

Quantile function to apply to the generated GRFs (default: qnorm).

...

Additional arguments passed to the quantile function qfun.

Examples

Run this code
library(terra)
library(FieldSimR)

# Community parameters
nspec <- 3
nrows <- ncols <- 10
xmin <- 250000; xmax <- xmin + nrows * 1000
ymin <- 600000; ymax <- ymin + ncols * 1000
id <- rast(nrows = nrows, ncols = ncols, xmin = xmin, xmax = xmax, ymin = ymin, ymax = ymax)
crs(id) <- "epsg:2180"
plot(id)

# Correlation matrix of carrying capacities
cor_mat <- matrix(c(1, 0.29, 0.32, 0.29, 1, 0.32, 0.32, 0.32, 1), nrow = nspec, ncol = nspec)
cor_mat

# Generate and define the distributions and parameters of correlated carrying capacity maps
K_map <- K_sim(nspec, id, range = 20000, cor_mat = cor_mat, qfun = qlnorm, meanlog = 2, sdlog = 0.5)
K_map
hist(K_map)
plot(K_map)

Run the code above in your browser using DataLab