| Title: | Mechanistic Metacommunity Simulator |
|---|---|
| Description: | Flexible, mechanistic, and spatially explicit simulator of metacommunities. It extends our previous package - 'rangr' (see <https://github.com/ropensci/rangr>), which implemented a mechanistic virtual species simulator integrating population dynamics and dispersal. The 'mrangr' package adds the ability to simulate multiple species interacting through an asymmetric matrix of pairwise relationships, allowing users to model all types of biotic interactions — competitive, facilitative, or neutral — within spatially explicit virtual environments. This work was supported by the National Science Centre, Poland, grant no. 2018/29/B/NZ8/00066 and the Poznań Supercomputing and Networking Centre (grant no. pl0090-01). |
| Authors: | Katarzyna Markowska [aut, cre, cph], Lechosław Kuczyński [aut, cph] |
| Maintainer: | Katarzyna Markowska <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 1.0.1 |
| Built: | 2026-05-25 07:39:42 UTC |
| Source: | https://github.com/cran/mrangr |
A square numeric matrix representing interaction coefficients between
species. a_ij is the per-capita interaction strength of species j
on species i. It expresses the change in carrying capacity of species i
by a single individual of species j.
This data is compatible with n1_map_eg.tif and K_map_eg.tif maps.
a_ega_eg
A numeric matrix with 4 rows and 4 columns containing interaction coefficients.
Data generated in-house to serve as an example
A pre-initialized sim_com_data object used to demonstrate community
structure and simulation input. It contains 4 species with spatially
correlated carrying capacity and initial abundance maps.
This object can be accessed via the get_community function.
An object of class sim_com_data from the mrangr package generated
using initialise_com.
Data generated in-house to serve as an example
Calculates the diagonal length of a raster's extent, accounting for the coordinate reference system.
diagonal(x)diagonal(x)
x |
A raster object. |
The diagonal distance in meteres.
library(terra) # Read data from the mrangr package K_map <- rast(system.file("input_maps/K_map_eg.tif", package = "mrangr")) diagonal(K_map)library(terra) # Read data from the mrangr package K_map <- rast(system.file("input_maps/K_map_eg.tif", package = "mrangr")) diagonal(K_map)
Loads a pre-simulated example of a spatial community object, useful for demos and testing.
get_community()get_community()
An object of class sim_com_data containing community structure,
simulation parameters, species-specific carrying capacity and initial
abundance maps.
community <- get_community() summary(community)community <- get_community() summary(community)
Loads a pre-run simulation output, based on the example community data. Useful for examples, unit tests, or visualization.
get_simulated_com()get_simulated_com()
An object of class sim_com_results containing simulation output for
a community over time.
sim <- get_simulated_com() plot(sim)sim <- get_simulated_com() plot(sim)
Generates a Gaussian random field (GRF) based on the Matern model of spatial autocorrelation.
grf(x, range, fun = "scale", ...)grf(x, range, fun = "scale", ...)
x |
A template raster of class |
range |
Numeric. The range parameter of the variogram model (in spatial units of |
fun |
A function to apply to the generated values (default is |
... |
Additional arguments passed to the function specified in |
A SpatRaster object containing the generated Gaussian random field.
library(terra) r <- rast(nrows = 100, ncols = 100, xmin = 0, xmax = 100, ymin = 0, ymax = 100) grf_field <- grf(r, range = 30) plot(grf_field)library(terra) r <- rast(nrows = 100, ncols = 100, xmin = 0, xmax = 100, ymin = 0, ymax = 100) grf_field <- grf(r, range = 30) plot(grf_field)
Prepares community-level input data for a spatial simulation.
This function builds on rangr::initialise()
by organising inputs for multiple species and their interactions.
initialise_com( n1_map = NULL, K_map, r, a, dlist = NULL, invasion = NULL, use_names_K_map = TRUE, ... )initialise_com( n1_map = NULL, K_map, r, a, dlist = NULL, invasion = NULL, use_names_K_map = TRUE, ... )
n1_map |
A |
K_map |
A |
r |
A numeric vector of intrinsic growth rates. It can be a single-element vector (if all species have the same intrinsic growth rate) or a vector of length equal to the number of species in the community. |
a |
A square numeric matrix representing interaction coefficients between species. Each element |
dlist |
Optional. A list; target cells at a specified distance calculated for every cell within the study area. |
invasion |
Optional. A named list of specifying invasion configuration (can be prepared using
|
use_names_K_map |
Logical. If |
... |
Additional named arguments passed to
|
A list of class sim_com_data containing:
A list of sim_data objects (one per species) returned by initialise().
The number of species.
The interaction matrix.
Intrinsic growth rate(s).
Initial abundance maps (wrapped SpatRaster).
Carrying capacity maps (wrapped SpatRaster).
The maximum dispersal distance across all species.
A list; target cells at a specified distance calculated for every cell within the study area.
Invasion configuration (if any).
The matched call.
library(terra) # Read data from the mrangr package ## Input maps K_map <- rast(system.file("input_maps/K_map_eg.tif", package = "mrangr")) n1_map <- rast(system.file("input_maps/n1_map_eg.tif", package = "mrangr")) ## Interaction coefficients matrix a <- a_eg # Initialise simulation parameters community_01 <- initialise_com( K_map = K_map, n1_map = n1_map, r = 1.1, a = a, rate = 0.002) # With invaders invasion <- initialise_inv( invaders = c(1, 3), invasion_times = c(2, 5)) community_02 <- initialise_com( K_map = K_map, r = 1.1, a = a, rate = 0.002, invasion = invasion) # Custom kernel function abs_rnorm <- function(n, mean, sd) { abs(rnorm(n, mean = mean, sd = sd)) } community_03 <- initialise_com( K_map = K_map, n1_map = n1_map, r = c(1.1, 1.05, 1.2, 1), a = a, kernel_fun = c("rexp", "rexp", "abs_rnorm", "abs_rnorm"), kernel_args = list( list(rate = 0.002), list(rate = 0.001), list(mean = 0, sd = 1000), list(mean = 0, sd = 2000)) )library(terra) # Read data from the mrangr package ## Input maps K_map <- rast(system.file("input_maps/K_map_eg.tif", package = "mrangr")) n1_map <- rast(system.file("input_maps/n1_map_eg.tif", package = "mrangr")) ## Interaction coefficients matrix a <- a_eg # Initialise simulation parameters community_01 <- initialise_com( K_map = K_map, n1_map = n1_map, r = 1.1, a = a, rate = 0.002) # With invaders invasion <- initialise_inv( invaders = c(1, 3), invasion_times = c(2, 5)) community_02 <- initialise_com( K_map = K_map, r = 1.1, a = a, rate = 0.002, invasion = invasion) # Custom kernel function abs_rnorm <- function(n, mean, sd) { abs(rnorm(n, mean = mean, sd = sd)) } community_03 <- initialise_com( K_map = K_map, n1_map = n1_map, r = c(1.1, 1.05, 1.2, 1), a = a, kernel_fun = c("rexp", "rexp", "abs_rnorm", "abs_rnorm"), kernel_args = list( list(rate = 0.002), list(rate = 0.001), list(mean = 0, sd = 1000), list(mean = 0, sd = 2000)) )
Prepares a list of invasion configuration details, including the identifiers of the invading species, the times of invasion and the number of individuals introduced at each event.
Result of this helper function is designed to be passed to initialise_com() as invasion argument.
initialise_inv(invaders, invasion_times, propagule_size = 1)initialise_inv(invaders, invasion_times, propagule_size = 1)
invaders |
An integer vector of species indices indicating which species are invaders.These indices should match the species layers in the input maps ( |
invasion_times |
A matrix or vector specifying when each invader enters the system. If a vector is provided, it is assumed to apply to all invaders. If a matrix, it must have one row per invader and columns corresponding to invasion events. |
propagule_size |
A numeric scalar specifying the number of individuals introduced at each invasion time. Defaults to 1. |
A named list with the following components:
Integer vector of invading species indices.
Number of individuals introduced per invasion event.
Matrix of invasion times, with one row per invader.
# Define invaders and invasion times initialise_inv( invaders = c(1, 3), invasion_times = matrix(c(5, 10, 5, 20), nrow = 2, byrow = TRUE), propagule_size = 10 ) # Uniform invasion times across all invaders initialise_inv( invaders = c(2, 4), invasion_times = c(5, 10, 15) )# Define invaders and invasion times initialise_inv( invaders = c(1, 3), invasion_times = matrix(c(5, 10, 5, 20), nrow = 2, byrow = TRUE), propagule_size = 10 ) # Uniform invasion times across all invaders initialise_inv( invaders = c(2, 4), invasion_times = c(5, 10, 15) )
SpatRaster object with 4 layer that can be
passed to initialise_com a as simulation (sim_com) starting point.
This map is compatible with n1_map_eg.tif.
SpatRaster object with 4 layers, each
with 15 rows and 15 columns. Contains numeric values representing carrying
capacity and NA's indicating unsuitable areas.
Data generated in-house to serve as an example (using spatial autocorrelation).
terra::rast(system.file("input_maps/K_map_eg.tif", package = "mrangr"))terra::rast(system.file("input_maps/K_map_eg.tif", package = "mrangr"))
Generates multiple carrying capacity maps based on spatially autocorrelated Gaussian Random Fields (GRFs), with optional correlation between layers.
K_sim(n, id, range, cor_mat = NULL, qfun = qnorm, ...)K_sim(n, id, range, cor_mat = NULL, qfun = qnorm, ...)
n |
Integer. Number of maps to generate. |
id |
A |
range |
Numeric. Spatial autocorrelation parameter passed to the |
cor_mat |
Optional correlation matrix. If |
qfun |
Quantile function to apply to the generated GRFs (default: |
... |
Additional arguments passed to the quantile function |
A SpatRaster object with n layers, each representing a carrying capacity map.
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)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)
SpatRaster object with 4 layer that can be
passed to initialise_com a as simulation (sim_com) starting point.
This map is compatible with K_map_eg.tif.
SpatRaster object with 4 layers, each
with 15 rows and 15 columns. Contains integer values representing abundance
and NA's indicating unsuitable areas.
Data generated in-house to serve as an example.
terra::rast(system.file("input_maps/n1_map_eg.tif", package = "mrangr"))terra::rast(system.file("input_maps/n1_map_eg.tif", package = "mrangr"))
This function plots a community time-series for a given location and time.
plot_series( obj, x = seq(dim(obj$N_map)[1]), y = seq(dim(obj$N_map)[2]), time = seq(obj$sim_time), species = seq(dim(obj$N_map)[4]), trans = NULL, ... )plot_series( obj, x = seq(dim(obj$N_map)[1]), y = seq(dim(obj$N_map)[2]), time = seq(obj$sim_time), species = seq(dim(obj$N_map)[4]), trans = NULL, ... )
obj |
An object of class |
x |
Indices for the x-dimension - first dimension of the |
y |
Indices for the y-dimension - second dimension of the |
time |
Indices for the time-dimension - third dimension of the |
species |
Indices for the species - fourth dimension of the |
trans |
An optional function to apply to the calculated mean series
before plotting (e.g., |
... |
Additional graphical parameters passed to |
Invisibly returns a matrix of the mean (and possibly transformed) abundance values for each species.
# Read simulation data from the mrangr package simulated_com <- get_simulated_com() # Plot plot_series(simulated_com) plot_series(simulated_com, x = 5:12, y = 1:5) plot_series(simulated_com, time = 1:5) plot_series(simulated_com, trans = log1p)# Read simulation data from the mrangr package simulated_com <- get_simulated_com() # Plot plot_series(simulated_com) plot_series(simulated_com, x = 5:12, y = 1:5) plot_series(simulated_com, time = 1:5) plot_series(simulated_com, trans = log1p)
sim_com_results ObjectDraws simulated abundance maps for any species at any time
## S3 method for class 'sim_com_results' plot( x, species = seq_len(dim(x$N_map)[4]), time_points = x$sim_time, type = "continuous", main, range, ... )## S3 method for class 'sim_com_results' plot( x, species = seq_len(dim(x$N_map)[4]), time_points = x$sim_time, type = "continuous", main, range, ... )
x |
An object of class |
species |
Integer vector. Species ID(s) to plot. |
time_points |
Integer vector. Time step(s) to plot (excluding burn-in). |
type |
Character vector of length 1. Type of map: "continuous" (default), "classes" or "interval" (case-sensitive) |
main |
Character vector. Plot titles (one for each layer) |
range |
Numeric vector of length 2. Range of values to be used for the
legend (if |
... |
Further arguments passed to |
#' * If length(time_points) == 1, returns a SpatRaster with species as layers.
If only one species is selected with multiple time points, returns a single SpatRaster.
# Read simulation data from the mrangr package simulated_com <- get_simulated_com() # Plot plot(simulated_com)# Read simulation data from the mrangr package simulated_com <- get_simulated_com() # Plot plot(simulated_com)
sim_com_data ObjectPrint sim_com_data Object
## S3 method for class 'sim_com_data' print(x, ...)## S3 method for class 'sim_com_data' print(x, ...)
x |
|
... |
further arguments passed to or from other methods; currently none specified |
sim_com_data object is invisibly returned (the x param)
# Read community data from the mrangr package community <- get_community() # Print print(community)# Read community data from the mrangr package community <- get_community() # Print print(community)
sim_com_results ObjectPrint sim_com_results Object
## S3 method for class 'sim_com_results' print(x, ...)## S3 method for class 'sim_com_results' print(x, ...)
x |
|
... |
further arguments passed to or from other methods; none specified |
sim_com_results object is invisibly returned (the x param)
# Read simulation data from the mrangr package simulated_com <- get_simulated_com() # Print print(simulated_com)# Read simulation data from the mrangr package simulated_com <- get_simulated_com() # Print print(simulated_com)
summary.sim_com_data ObjectPrint summary.sim_com_data Object
## S3 method for class 'summary.sim_com_data' print(x, ...)## S3 method for class 'summary.sim_com_data' print(x, ...)
x |
An object of class |
... |
Additional arguments (not used) |
Invisibly returns x
# Read community data from the mrangr package community <- get_community() # Print summary sim_com_data_summary <- summary(community) print(sim_com_data_summary)# Read community data from the mrangr package community <- get_community() # Print summary sim_com_data_summary <- summary(community) print(sim_com_data_summary)
summary.sim_results ObjectPrint summary.sim_results Object
## S3 method for class 'summary.sim_com_results' print(x, ...)## S3 method for class 'summary.sim_com_results' print(x, ...)
x |
|
... |
further arguments passed to or from other methods; currently none specified |
None
# Read simulation data from the mrangr package simulated_com <- get_simulated_com() # Print summary sim_com_summary <- summary(simulated_com) print(sim_com_summary)# Read simulation data from the mrangr package simulated_com <- get_simulated_com() # Print summary sim_com_summary <- summary(simulated_com) print(sim_com_summary)
This function takes an object and sets all non-missing values to zero, while leaving missing values unchanged.
set_zero(x)set_zero(x)
x |
A vector or other object for which |
An object of the same type as x with all originally non-missing
elements replaced by zero.
# Example with a numeric vector vec <- c(1, 2, NA, 4, NA, 5) set_zero(vec)# Example with a numeric vector vec <- c(1, 2, NA, 4, NA, 5) set_zero(vec)
This function simulates species interactions and population dynamics over a given period. It accounts for species invasions and updates population abundances at each time step.
sim_com(obj, time, burn = 0, progress_bar = TRUE)sim_com(obj, time, burn = 0, progress_bar = TRUE)
obj |
An object of class |
time |
Integer. Total number of simulation steps. Must be >= 2. |
burn |
Integer. Number of initial burn-in steps to exclude from the output. Must be >= 0 and < |
progress_bar |
Logical. Whether to display a progress bar during the simulation. |
An object of class sim_com_results, a list containing:
Named logical vector indicating species that went extinct.
Integer. Duration of the output simulation (excluding burn-in).
A SpatRaster object used as a geographic template.
4D array [rows, cols, time, species] of population abundances.
# Read community data from the mrangr package community <- get_community() # Simulation simulated_com_01 <- sim_com(obj = community, time = 10) # Simulation with burned time steps simulated_com_02 <- sim_com(obj = community, time = 10, burn = 3)# Read community data from the mrangr package community <- get_community() # Simulation simulated_com_01 <- sim_com(obj = community, time = 10) # Simulation with burned time steps simulated_com_02 <- sim_com(obj = community, time = 10, burn = 3)
A sim_com_results object containing results of a 20-step simulation of
a 4-species community.
The simulation was generated using the community_eg object.
This object can be accessed via the get_simulated_com function.
An object of class sim_com_results from the mrangr package
generated using sim_com.
Data generated in-house to serve as an example
get_simulated_com, plot.sim_com_results, sim_com
sim_com_data ObjectSummary Of sim_com_data Object
## S3 method for class 'sim_com_data' summary(object, ...)## S3 method for class 'sim_com_data' summary(object, ...)
object |
|
... |
further arguments passed to or from other methods; currently none used |
A list of class summary.sim_com_data
# Read community data from the mrangr package community <- get_community() # Summary summary(community)# Read community data from the mrangr package community <- get_community() # Summary summary(community)
sim_com_results ObjectSummary Of sim_com_results Object
## S3 method for class 'sim_com_results' summary(object, ...)## S3 method for class 'sim_com_results' summary(object, ...)
object |
|
... |
further arguments passed to or from other methods; none specified |
summary.sim_com_results object
# Read simulation data from the mrangr package simulated_com <- get_simulated_com() # Summary summary(simulated_com)# Read simulation data from the mrangr package simulated_com <- get_simulated_com() # Summary summary(simulated_com)
sim_com_results to SpatRaster(s)Converts simulated population abundance data from a sim_com_results object
(produced by sim_com()) into SpatRaster objects.
## S3 method for class 'sim_com_results' to_rast( obj, species = seq_len(dim(obj$N_map)[4]), time_points = obj$sim_time, ... )## S3 method for class 'sim_com_results' to_rast( obj, species = seq_len(dim(obj$N_map)[4]), time_points = obj$sim_time, ... )
obj |
An object of class |
species |
Integer vector. Species ID(s) to extract. |
time_points |
Integer vector. Time step(s) to extract (excluding burn-in). |
... |
Currently unused. |
If length(time_points) == 1, returns a SpatRaster with species as layers.
If length(time_points) > 1, returns a named list of SpatRaster objects, one per species.
If only one species is selected with multiple time points, returns a single SpatRaster.
# Read simulation data from the mrangr package simulated_com <- get_simulated_com() # Extract one timestep, all species r1 <- to_rast(simulated_com, time_points = 10) # Extract multiple timesteps, one species r2 <- to_rast(simulated_com, species = 2, time_points = c(1, 5, 10)) # Extract multiple timesteps, multiple species r3 <- to_rast(simulated_com, species = c(1, 2), time_points = c(1, 5, 10))# Read simulation data from the mrangr package simulated_com <- get_simulated_com() # Extract one timestep, all species r1 <- to_rast(simulated_com, time_points = 10) # Extract multiple timesteps, one species r2 <- to_rast(simulated_com, species = 2, time_points = c(1, 5, 10)) # Extract multiple timesteps, multiple species r3 <- to_rast(simulated_com, species = c(1, 2), time_points = c(1, 5, 10))
sim_com_data ObjectUpdates the parameters used to create a sim_com_data object, returned
by initialise_com().
## S3 method for class 'sim_com_data' update(object, ..., evaluate = TRUE)## S3 method for class 'sim_com_data' update(object, ..., evaluate = TRUE)
object |
A |
... |
Named arguments to update. These should be valid arguments to |
evaluate |
Logical (default |
If dispersal-related arguments such as max_dist, kernel_fun, or kernel_args
are changed, the existing dlist is removed and recalculated unless a new dlist
is explicitly provided.
If n1_map or K_map is updated, the dlist will also be removed to
ensure consistency.
If evaluate = TRUE, a new sim_com_data object with updated parameters.
If evaluate = FALSE, a call object representing the updated function call.
library(terra) # Read data from the mrangr package ## Input maps K_map <- rast(system.file("input_maps/K_map_eg.tif", package = "mrangr")) n1_map <- rast(system.file("input_maps/n1_map_eg.tif", package = "mrangr")) ## Competition coefficients matrix a <- a_eg # Initialise simulation parameters community_01 <- initialise_com( K_map = K_map, r = 1.1, a = a, rate = 0.002) # Update simulation parameters # Custom kernel function abs_rnorm <- function(n, mean, sd) { abs(rnorm(n, mean = mean, sd = sd)) } community_02 <- update(community_01, kernel_fun = c("rexp", "rexp", "abs_rnorm", "abs_rnorm"), kernel_args = list( list(rate = 0.002), list(rate = 0.001), list(mean = 0, sd = 1000), list(mean = 0, sd = 2000)))library(terra) # Read data from the mrangr package ## Input maps K_map <- rast(system.file("input_maps/K_map_eg.tif", package = "mrangr")) n1_map <- rast(system.file("input_maps/n1_map_eg.tif", package = "mrangr")) ## Competition coefficients matrix a <- a_eg # Initialise simulation parameters community_01 <- initialise_com( K_map = K_map, r = 1.1, a = a, rate = 0.002) # Update simulation parameters # Custom kernel function abs_rnorm <- function(n, mean, sd) { abs(rnorm(n, mean = mean, sd = sd)) } community_02 <- update(community_01, kernel_fun = c("rexp", "rexp", "abs_rnorm", "abs_rnorm"), kernel_args = list( list(rate = 0.002), list(rate = 0.001), list(mean = 0, sd = 1000), list(mean = 0, sd = 2000)))
Organizes and extracts community data from a simulated community object based on one of three sampling methods: random proportion, constant random sites, or user-provided sites.
virtual_ecologist( obj, type = c("random_one_layer", "random_all_layers", "from_data"), sites = NULL, prop = 0.01, obs_error = c("rlnorm", "rbinom"), obs_error_param = NULL )virtual_ecologist( obj, type = c("random_one_layer", "random_all_layers", "from_data"), sites = NULL, prop = 0.01, obs_error = c("rlnorm", "rbinom"), obs_error_param = NULL )
obj |
An object created by the |
type |
character vector of length 1; describes the sampling type (case-sensitive):
|
sites |
An optional data frame specifying the sites for data extraction.
This data frame must contain three columns: |
prop |
A numeric value between 0 and 1. The proportion of cells to randomly sample from the raster. |
obs_error |
character vector of length 1; type of the distribution
that defines the observation process: " |
obs_error_param |
numeric vector of length 1; standard deviation
(on a log scale) of the random noise in the observation process when
|
A data frame with 6 columns:
id: unique cell identifier (factor)
x, y: sampled cell coordinates
species: species number or name
time: sampled time step
n: sampled abundance
# Read simulated community data from the mrangr package simulated_com <- get_simulated_com() # Option 1: Randomly sample sites (the same for each year) sampled_data_01 <- virtual_ecologist(simulated_com) head(sampled_data_01) # Option 2: Randomly sample sites (different for each year) sampled_data_02 <- virtual_ecologist(simulated_com, type = "random_all_layers") head(sampled_data_02) # Option 3: Sample sites based on user-provided data frame custom_sites <- data.frame( x = c(250500, 252500, 254500), y = c(600500, 602500, 604500), time = c(1, 10, 20) ) sampled_data_03 <- virtual_ecologist(simulated_com, sites = custom_sites) head(sampled_data_03) # Option 4. Add noise - "rlnorm" sampled_data_04 <- virtual_ecologist( simulated_com, sites = custom_sites, obs_error = "rlnorm", obs_error_param = log(1.2) ) head(sampled_data_04) # Option 5. Add noise - "rbinom" sampled_data_05 <- virtual_ecologist( simulated_com, sites = custom_sites, obs_error = "rbinom", obs_error_param = 0.8 ) head(sampled_data_05)# Read simulated community data from the mrangr package simulated_com <- get_simulated_com() # Option 1: Randomly sample sites (the same for each year) sampled_data_01 <- virtual_ecologist(simulated_com) head(sampled_data_01) # Option 2: Randomly sample sites (different for each year) sampled_data_02 <- virtual_ecologist(simulated_com, type = "random_all_layers") head(sampled_data_02) # Option 3: Sample sites based on user-provided data frame custom_sites <- data.frame( x = c(250500, 252500, 254500), y = c(600500, 602500, 604500), time = c(1, 10, 20) ) sampled_data_03 <- virtual_ecologist(simulated_com, sites = custom_sites) head(sampled_data_03) # Option 4. Add noise - "rlnorm" sampled_data_04 <- virtual_ecologist( simulated_com, sites = custom_sites, obs_error = "rlnorm", obs_error_param = log(1.2) ) head(sampled_data_04) # Option 5. Add noise - "rbinom" sampled_data_05 <- virtual_ecologist( simulated_com, sites = custom_sites, obs_error = "rbinom", obs_error_param = 0.8 ) head(sampled_data_05)