Skip to contents

This function samples a new observations point of a species within the uncertainty circle around each observation assuming a bivariate Normal distribution.

Usage

sample_from_binormal_circle(observations, p_norm = 0.95, seed = NA)

Arguments

observations

An sf object with POINT geometry and a time_point and coordinateUncertaintyInMeters column. If the former column is not present, the function will assume a single time point. If the latter column is not present, the function will assume no uncertainty (zero meters) around the observation points.

p_norm

A numeric value between 0 and 1. The proportion of all possible samples from a bivariate Normal distribution that fall within the uncertainty circle. Default is 0.95. See Details.

seed

A positive numeric value setting the seed for random number generation to ensure reproducibility. If NA (default), then set.seed() is not called at all. If not NA, then the random number generator state is reset (to the state before calling this function) upon exiting this function.

Value

An sf object with POINT geometry containing the locations of the sampled occurrences and a coordinateUncertaintyInMeters column containing the coordinate uncertainty for each observation.

Details

A new observation point is sampled from a bivariate Normal distribution with means equal to the X and Y coordinates of its original observation point and variances equal to (-coordinateUncertaintyInMeters^2) / (2 * log(1 - p_norm)), ensuring p_norm % of all possible samples fall within the uncertainty circle.

See also

Other designation: sample_from_uniform_circle()

Examples

library(sf)
library(dplyr)

# Create four random points
n_points <- 4
xlim <- c(3841000, 3842000)
ylim <- c(3110000, 3112000)
coordinate_uncertainty <- rgamma(n_points, shape = 5, rate = 0.1)

observations_sf <- data.frame(
  lat = runif(n_points, ylim[1], ylim[2]),
  long = runif(n_points, xlim[1], xlim[2]),
  time_point = 1,
  coordinateUncertaintyInMeters = coordinate_uncertainty
) %>%
  st_as_sf(coords = c("long", "lat"), crs = 3035)

# Sample points within uncertainty circles according to normal rules
sample_from_binormal_circle(
  observations = observations_sf,
  p_norm = 0.95,
  seed = 123
)
#> Simple feature collection with 4 features and 2 fields
#> Geometry type: POINT
#> Dimension:     XY
#> Bounding box:  xmin: 3841171 ymin: 3109977 xmax: 3841969 ymax: 3110673
#> Projected CRS: ETRS89-extended / LAEA Europe
#>   time_point coordinateUncertaintyInMeters                geometry
#> 1          1                      39.28695 POINT (3841171 3110097)
#> 2          1                      82.51448 POINT (3841969 3110402)
#> 3          1                      68.26574 POINT (3841438 3110673)
#> 4          1                      61.83829 POINT (3841758 3109977)