FindNext: Finds the next most complementary or disimilar site on...

Description Usage Arguments Details Value Examples

View source: R/FindNext.R

Description

Finds the next most complementary or disimilar site on average to sampled sites within a set of candidate sites.

Usage

1
FindNext(pre.params, action, custom.coords = NULL)

Arguments

pre.params

The object resulting of running PreFindNext

action

One of the following

add

Add previously suggested site to the list of sampled sites and find next suggestion

reject

Reject previously suggested site and find next best site

modify

Modify previous suggestion with a new site with coordinates specified in custom.coords

custom.coords

A vector with the XY coordinates of a site to add to the list of selected sites

Details

This function implements stage 2 of the algorithm outlined by Manion & Ridges (2009). Specifically, it will take the results from PreFindNext or a previous iteration of FindNext and for option "add" will update the distance (nnDistance in params) from demand points to candidate sites considering that the sites suggested in the previous iteration is accepted (m2 in params). Then it finds the cell that reduces the most the environmental distance to demand points (XY coordinates in selCoords) compared to the previous iteration (nnDistanceUpdated in params object). The "reject" option will exclude the suggestion found in the previous iteration and find the next best site. The "modify" option will select the cell corresponding to custom.coords and find the next best site.

Value

A list with the following objects:

out.raster

A raster object displaying the complementarity of candidate sites

initED

The total complementarity of existing sites

outED

The total complementarity after selecting the suggested site

selCoords

Coordinates of the suggested survey site (i.e. the most complementary)

params

A list object to input in function FindNext

#' @references Manion, G., & Ridges, M. (2009). An optimisation of the survey gap analysis technique to minimise computational complexity and memory resources in order to accommodate fine grain environmental and site data. In 18th World IMACS/MODSIM Congress, Cairns, Australia (pp. 13-17).

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
## Not run: 
#To compute cell stats for colombian bats
library(lubridate)
library(raster)
library(rgbif)
library(WhereNext)

#Get occurrence data
gbif.key <- name_backbone(name = "Chiroptera")
gbif.res <- DownloadGBIF(gbif.key$orderKey, "your username", "your email", "your password", "CO") #Enter your GBIF credentials here

#Get environmental data
col <- getData("GADM", country="COL",level=0)
env.vars <- getData("worldclim", var="bio", res=5)
env.vars <- crop(env.vars, col)
env.vars <- mask(env.vars, col)
env.vars <- Normalize(env.vars) #Normalize environmental variables
env.vars <- RemCorrLayers(env.vars, 0.8) #Remove variables correlated more than r=0.8.

#Do minimal occ.table cleaning
occ.table <- gbif.res$occ.table
occ.table$eventDate <- as_date(occ.table$eventDate)
occ.table$individualCount <- 1 #Data is presence only
occ.table.clean <- subset(occ.table, !is.na(eventDate) & taxonRank=="SPECIES")
row.names(occ.table.clean) <- 1:nrow(occ.table.clean)
occ.table.clean <- CoordinateCleaner::clean_coordinates(occ.table.clean,
                                                        lon="decimalLongitude",
                                                        lat="decimalLatitude",
                                                        species="species",
                                                        countries = "countryCode",
                                                        value="clean",
                                                        tests=c("capitals","centroids", "equal", "gbif",
                                                                "institutions", "outliers", "seas","zeros"))

#Estimate cell sampling stats & filter occurrence data
occ.table.clean$cell <- cellFromXY(env.vars, occ.table.clean[, c("decimalLongitude","decimalLatitude")])
cell.stats <- RichSamp(occ.table.clean, env.vars, c("decimalLongitude","decimalLatitude","eventDate","species","individualCount","cell"))
selected.cells <- cell.stats$cell[which(cell.stats$n>3&cell.stats$Species>5)] #Consider places with at least 3 sampling events and 5 species recorded as well sampled
occ.table.sel <- occ.table.clean[which(occ.table.clean$cell %in% selected.cells), ] #Use only ocurrences of well sampled cells

#Run and map GDM
m1 <- RunGDM(occ.table.sel, env.vars, "bray", TRUE, TRUE, c("species", "decimalLongitude", "decimalLatitude"))
plotRGB(m1$gdm.map$pcaRast)

#Find initial survey suggestions
init <- PreFindNext(m1$gdm.res, m1$occ.table, m1$gdm.rasters, subset.size=1000, search.type="1")
plot(init$out.raster)
points(init$selCoords)

#Find additional survey suggestions
update <- FindNext(init, "add")
plot(update$out.raster)
points(update$selCoords)

## End(Not run)

jivelasquezt/WhereNext-Pkg documentation built on Oct. 11, 2021, 9:46 p.m.