RunGDM: Wrapper function to run a Generalized Dissimilarity Model

Description Usage Arguments Details Value References Examples

View source: R/RunGDM.R

Description

Wrapper function to run a Generalized Dissimilarity Model

Usage

1
RunGDM(occ.table, env.vars, index, use.geo, do.VarSel, field.names)

Arguments

occ.table

data frame with species occurrence and sampling information. Each occurrence must contain XY coordinates species fields.

env.vars

a rasterStack object of meaningful environmental variables to predict biological dissimilarity.

index

the dissimilarity index to use. Valid options are "jaccard", "bray" or "betasim".

use.geo

logical. If TRUE geographic distance is included in model as a predictor.

do.VarSel

logical. If TRUE variable selection based on explained deviance is performed.

field.names

a vector of field names in the occurrence table in the following order: species name, coordinates x, coordinates y.

Details

RunGDM adds functionality to the gdm function available in the gdm package. Specifically, 1) it adds betasim, a richness independent measure of turnover (Lenon et al. 2001), 2) perfoms variable selection by excluding from models variables with coefficients of 0 or that upon removal decrease the explained deviance less than 5 to aid in the visualization of turnover.

Value

A list with the following objects:

occ.table

The input occurrence table

gdm.res

A gdm object returned by the gdm function in gdm-package

gdm.rasters

A RasterStack of gdm transformed environmental predictors returned by the gdm.transform function in gdm-package

gdm.map

A list returned by the MapGDMLight function

References

Lennon, J. J., Koleff, P., Greenwood, J. J. D., & Gaston, K. J. (2001). The geographical structure of British bird distributions: diversity, spatial turnover and scale. Journal of Animal Ecology, 70(6), 966-979.

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
## 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)

## End(Not run)

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