thin_data: Spatial thinning of occurrence data

View source: R/thin_data.R

thin_dataR Documentation

Spatial thinning of occurrence data

Description

thin_data rarefies spatially occurrence data using a distance in kilometers. Multiple distances are alowed if distinct classes are defined.

Usage

thin_data(data, longitude, latitude, thin_class = NULL,
          raster_layer = NULL, thin_distance = 0, save = FALSE,
          name = "occurrences_thin")

Arguments

data

data.frame of occurrence records containing at least longitude and latitude columns.

longitude

(character) name of the column with longitude data.

latitude

(character) name of the column with latitude data.

thin_class

(character) name of optional column with numeric values to represent classes for thinning data using distinct distances.

raster_layer

optional RasterLayer to define duplicates based on its cell size.

thin_distance

(numeric) distance in kilometers to thin the data. Default = 0. If distinct classes are defined in thin_class, a vector of length equal to the number of classes is required.

save

(logical) whether or not to save the results in the working directory. Default = FALSE.

name

(character) if save = TRUE, name of the csv file to be written; format (.csv) is atomatically added. Default = "occurrences_thin".

Value

A data.frame with thinned data and messages about how many records were erased and kept.

Examples

# reading data
occurrences <- read.csv(system.file("extdata", "occurrences_gbif.csv",
                                    package = "ellipsenm"))
colnames(occurrences)

# simple thinning based on one distance
thin_occurrences <- thin_data(occurrences, longitude = "longitude",
                              latitude = "latitude", thin_distance = 5)

# thinning using a raster (only duplicates are erased)
r_layer <- raster::raster(system.file("extdata", "bio_1.tif",
                                       package = "ellipsenm"))

thin_occurrences1 <- thin_data(occurrences, longitude = "longitude",
                               latitude = "latitude", raster_layer = r_layer)

# thinning with different distances according to distinct classes
occurrences1 <- read.csv(system.file("extdata", "occurrences_spa_cor.csv",
                                    package = "ellipsenm"))
colnames(occurrences1)
occurrences1$thin_factor # to check classes (1 = 5 km, 2 = 10 km, 3 = 15 km)

thin_occurrences2 <- thin_data(occurrences1, longitude = "longitude",
                               latitude = "latitude", thin_class = "thin_factor",
                               thin_distance = c(5, 10, 15))

# saving thinned data
thin_occurrences2 <- thin_data(occurrences1, longitude = "longitude",
                               latitude = "latitude", thin_class = "thin_factor",
                               thin_distance = c(5, 10, 15), save = TRUE,
                               name = "thin_data")

# Check dimensions of original data and results
dim(occurrences)
dim(thin_occurrences)
dim(thin_occurrences1)
dim(occurrences1)
dim(thin_occurrences2)

marlonecobos/ellipsenm documentation built on Oct. 18, 2023, 8:09 a.m.