SDMs: Prepare presence and pseudo-absence data, run selected models...

Description Usage Arguments Value Examples

View source: R/FunctionSDMs.R

Description

This function uses presence points for a species with a background mask to generate pseudo-absences, and then uses these with environmental data layers to generate species distribution models using a range of different model algorithms. The function then selects the best perfoming model and outputs the distribution that that model predicts, an evaluation of the model performance and the model itself.

Usage

1
2
3
4
5
6
SDMs(occ = occurrence, bckg = NULL, varstack = vars,
  models = c("MaxEnt", "BioClim", "SVM", "RF", "GLM", "GAM", "BRT"),
  n_bg_points = NULL, prop_test_data = 0.25, covarResm = 300,
  max_tries = 2, lab = "species", rndm_occ = TRUE,
  out_flder = "Outputs/", precisionCol = precisionCol,
  coordsys = "m")

Arguments

occ

A SpatialPointsDataFrame of presence points.

bckg

A raster showing the background area in which pseudo-absence points will be placed. Cells from which background points should be taken should have a value of 1 and excluded cells should be NA. If no background mask is supplied, then pseudo absences with be generated from the variables layer.

varstack

A RasterStack of the environmental parameters to be used as predictor variables for the species range.

models

A character vector of the models to run and evaluate. This should be at least one of 'MaxEnt', 'BioClim', 'SVM', 'RF', 'GLM', 'GAM', 'BRT'. Default is to run all models.

n_bg_points

The number of pseudo-absence point to attempt to generate. Note that if a very restrictive mask is used the number actually generated may be fewer than that specified. Default is to attempt to generate the same number of pseudo-absences as presences for which there is data on the environmental parameters (this may be fewer than the number of points in occ if some of these fall in cells that are NA in one or more layers in varstack.

prop_test_data

Numeric, the proportion of data to keep back as testing data for evaluating the models. Default is 25%.

covarResm

Numeric, the resolution of the environmental covariate data layers, in metres. Data will not be discarded if it is of higher resolution than the environmental covariate layers.

max_tries

Numeric, the numbers of times the model is run.

lab

The name of the output files.

rndm_occ

Logical, Default is TRUE and will randomise the locations of presence points where the species occurrence data is low resolution, through calling the randomOcc function.

out_flder

The location of the output folder for your models.

coordsys

The coordinate system used to denote location, either "latlon" for decimal latitude and longitude or "bng" for british national grid easting and northings.

Value

A list containing the prediction from the best model (as a raster layer showing probability of species occurrence), the best model evaluation and the best model itself.

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
56
# Example using BNG data prep:
#load in the occurence data
data(ng_data)

#Prepare this using the bngPrep function available in this package
occurrence <- bngprep(speciesdf = ng_data, bngCol = 'OSGR', datafrom ='NBNatlas', mindata = 5000, minyear = 2007, covarRes = 300)

#convert to a SpatialPointsDataFrame
sp::coordinates(occurrence)<- ~ easting + northing

#get UK extent
UK <- ggplot2::map_data(map = "world", region = "UK")
max.lat <- ceiling(max(UK$lat))
min.lat <- floor(min(UK$lat))
max.lon <- ceiling(max(UK$long))
min.lon <- floor(min(UK$long))
extent <- raster::extent(x = c(min.lon, max.lon, min.lat, max.lat))

#get variables data
bio<-raster::getData('worldclim',var='bio',res=5,lon=-2,lat=40)
bio <- bio[[c("bio1","bio12")]]
names(bio) <- c("Temp","Prec")

#crop to uk
bio<-raster::crop(bio,extent)

#change to easting northing
vars <- raster::projectRaster(bio, crs="+init=epsg:27700")

#load background mask
data(background)

#run the species distribution models
SDMs(occ = occurrence, bckg = background, varstack = vars, max_tries = 2, lab = 'species', rndm_occ = TRUE, coordsys = "m", precisionCol = "precision")


# Example with lat lon data prep:
data(ng_data)
names(ng_data)[26] <- "Decimal longitude (WGS84)"

#preparing the data
speciesdf <- latlonprep(speciesdf = ng_data, xCol = "Decimal latitude (WGS84)", yCol = "Decimal longitude (WGS84)", precisionCol = "Coordinate uncertainty in metres", yearCol = "Year", minyear = 2000, maxyear = 2007, GBonly = FALSE)

#convert to spatial points data frame
names(speciesdf)
yCol = "longitude"
xCol = "latitude"
sp::coordinates(speciesdf)<- c(yCol, xCol)

# project the variable layer
data(vars)
latlong = "+init=epsg:4326"
vars = raster::projectRaster(vars, crs = latlong)

#run the model
SDMs(occ = speciesdf, bckg = NULL, varstack = vars, max_tries = 2, lab = 'species', rndm_occ = FALSE, coordsys = "latlon",precisionCol="precision")

jncc/sdms documentation built on Aug. 13, 2021, 4:21 a.m.