extractAdmin: Extract covariates by admin units

Description Usage Arguments Value See Also Examples

Description

Given a SpatialPointsDataFrame object occurrence with Admin and GAUL columns and a RasterBrick or RasterStack object admin giving the admin layers, extract and summarize the values of covariates using the function fun for each polygon.

Usage

1

Arguments

occurrence

A SpatialPointsDataFrame of occurrence records containing at least a column named Admin giving the admin level of the polygon (an integer from 0 to 3, or -999 for point data) and a column named GAUL giving the GAUL codes for these polygons. This can be added using getGAUL.

covariates

A Raster* object giving covariates to use in the model.

admin

A RasterBrick or RasterStack object with four layers giving the GAUL codes for different admin levels. The layers must be in the order 0, 1, 2, 3, as they are in the example object admin.

fun

A function to summarize the covariate values accross each polygon, mean might be a good option for continuous covariates, or modal for discrete covariates.

Value

A matrix giving the summarized covariate values for each of the polygons in occurrence (i.e. point records will be missing).

See Also

getGAUL

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# load occurrence data, admin units and covariates
data(occurrence)
data(admin)
data(covariates)

# convert occurrence to an SPDF
occurrence <- occurrence2SPDF(occurrence)
# add on the GAUL codes
occurrence <- getGAUL(occurrence, admin)

# extract all covariates, taking the mean across each polygon
vals <- extractAdmin(occurrence, covariates, admin, fun = mean)
head(vals)

# note that point records are omitted
nrow(occurrence)
nrow(vals)

# it would be better to use different summary functions since cov_c is a factor
cov_ab <- extractAdmin(occurrence, covariates[[1:2]], admin, fun = mean)
cov_c <- extractAdmin(occurrence, covariates[[3]], admin, fun = modal)

head(cbind(cov_ab, cov_c))

SEEG-Oxford/seegSDM documentation built on May 9, 2019, 11:08 a.m.