simulate_spatial_niches: Create a Spatial Niche in Coordinate Data Frame

simulate_spatial_nichesR Documentation

Create a Spatial Niche in Coordinate Data Frame

Description

This function creates a spatial niche around specified origin points in a coordinate data frame. The niche is defined by a specified size and is used to modify values in the data frame based on proximity to the origin points.

Usage

simulate_spatial_niches(
  coords_df,
  origins,
  size,
  size_fct = 1.1,
  vt,
  vf = NULL,
  rr = c(0, 1),
  type = "small",
  seed = 123
)

Arguments

coords_df

A data frame containing spatial coordinates and other variables.

origins

A character vector specifying the barcodes of the origin points around which the niche will be created.

size

A numeric value specifying the size of the niche around each origin point.

vt

The name of the variable in coords_df to which values will be assigned.

vf

The name of the variable in coords_df from which values will be taken. If NULL (default), random values will be generated and assigned.

rr

A numeric vector of length 2 specifying the range for generating random values. Default is c(0, 1).

seed

A numeric value specifying the seed for random number generation. Default is 123.

Details

The function works by calculating the distances from each origin point to all other points in coords_df. Points that fall within the specified niche size around each origin are identified, and their values in the vt variable are modified based on the vf variable. If vf is NULL, random values within the specified range (rr) are generated and used.

Value

A data frame with the modified values based on the created spatial niche.

Examples

## Not run: 
df <- data.frame(x = runif(100, 0, 10), y = runif(100, 0, 10), value = rnorm(100))
df_with_niche <- simulate_spatial_niches(df, origins = c("A", "B"), size = 5, vt = "value")

## End(Not run)


theMILOlab/SPATA2 documentation built on Feb. 8, 2025, 11:41 p.m.