make_spatialenv: Create a Random Spatial Landscape.

View source: R/Parameter_functions.R

make_spatialenvR Documentation

Create a Random Spatial Landscape.

Description

This function creates a spatially explicit environmental landscape and samples random points from it for simulations of Moran Metacommunity model. Environmental landscapes can be generated randomly or with spatial autocorrelation using IDW interpolation.

Usage

make_spatialenv(
  n.sites,
  n.meas,
  env.maxmin,
  x.max = 100,
  y.max = 100,
  idp = 2,
  autocor = TRUE,
  steps = 4,
  reps = 2
)

Arguments

n.sites

Numeric 1L, Number of communities in metacommunity.

n.meas

Numeric 1L, Number of environmental measures to simulate.

env.maxmin

List with length equal to n.meas. Each element in the list is a Numeric vector with two elements, the minimum and maximum values for each environmental variable.

x.max, y.max

Numeric 1L, Maximum distance in x and y directions for landscape extent.

idp

Numeric, power parameter for IDW interpolation.

autocor

Logical, if TRUE uses IDW interpolation to create landscape.

steps

# Numeric, number to divide range by to create gradient of interpolation point values (see details).

reps

Numeric, Number of repetitions for each interpolation point value.

Details

This function generates a spatially explicit landscape that can be used in Moran metacommunity simulations. Environmental variables are mapped to the landscape in one of two ways. If autocor = TRUE, then the function generates a vector of values (using the steps and reps arguments) between the maximum and minimum of of each environmental variable being simulated. For example, say that the user inputs that pH in the landscape ranges from 6 to 8. If steps = 4 and rep = 2, the function creates a vector with the values (6, 6, 6.5, 6.5, 7, 7, 7.5, 7.5, 8, 8). These values are then shuffled into a random order and assigned to randomly placed points on the landscape. From these points, the function uses IDW interpolation to fill in the environmental variables for the rest of the landscapes. If autocor = FALSE, then environmental values are randomly generated for each cell using a uniform distribution. NOTE: the landscape generated is in raster format.

Value

Returns a list with the following elements:

xy: A dataframe with the x and y coordinates of communities to be sampled

env.vals: A dataframe with the environmental values sampled from each of the communities.

rasters: A raster brick with all of the environmental landscapes

sp.points: A SpatialPointsDataFrame with the x and y coordinates of the communities to be sampled.

Examples


pH <- c(6, 8)
eC <- c(0.01, 0.15)
temp <- c(70, 85)

envlist <- list(pH, eC, temp)

make_spatialenv(n.sites = 10, n.meas = 3, env.maxmin = envlist)
make_spatialenv(n.sites = 10, n.meas = 3, env.maxmin = envlist, autocor = FALSE)


trevorjwilli/CommSimABCR documentation built on Feb. 4, 2025, 1:22 a.m.