bgSample: Randomly sample pseudo-absence points from a raster

Description Usage Arguments Value See Also Examples

Description

Randomly sample n pseudo-absence points at pixels of raster (excluding NA pixels). If prob = TRUE the is assumed to be a bias grid and the random sampling is weighted toward pixels with the greatest value. If spatial = TRUE a SpatialPoints object is returned, else a matrix of coordinates.

Usage

1
bgSample(raster, n = 1000, prob = FALSE, replace = FALSE, spatial = TRUE)

Arguments

raster

The raster from which to sample at random.

n

The number of pseudo-absence points to sample.

prob

Whether to weight samples by the values of the pixels in raster.

replace

Whether to sample with replacement.

spatial

Whether to return a SpatialPoints object (if TRUE, the default) or a matrix of coordinates (if FALSE)

Value

Either a SpatialPoints object or a matrix of coordinates.

See Also

sample, bgDistance, biasGrid, SpatialPoints

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
# load a test raster
r <- raster(system.file("external/test.grd", package="raster"))

# randomly sample 10000 background points without replacement
pts <- bgSample(r, n = 1000)

# plot the raster
plot(r)
# the pseudo-absences (with transparency)
plot(pts, add = TRUE, pch = 16, cex = 0.8, col = rgb(0, 0, 0, 0.2))


# this time with replacement 
pts <- bgSample(r, n = 1000, replace = TRUE)

plot(r)
plot(pts, add = TRUE, pch = 16, cex = 0.8, col = rgb(0, 0, 0, 0.2))


# now with replacement and biased by the values of the raster
pts <- bgSample(r, n = 1000, replace = TRUE, prob = TRUE)

plot(r)
plot(pts, add = TRUE, pch = 16, cex = 0.8, col = rgb(0, 0, 0, 0.2))

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