Description Usage Arguments Value Author(s) References See Also Examples
Select pairs of points from two sets (without replacement) that have a similar distance to their nearest point in another set of points.
For each point in "fixed
", a point is selected from "sample
" that has a similar distance (as defined by threshold
) to its nearest point in "reference
" (note that these are likely to be different points in reference
). The select point is either the nearest point nearest=TRUE
, or a randomly select point nearest=FALSE
that is within the threshold distance. If no point within the threshold distance is found in sample
, the point in fixed
is dropped.
Hijmans (2012) proposed this sampling approach to remove 'spatial sorting bias' (ssb
) from evaluation data used in cross-validation of presence-only species distribution models. In that context, fixed
are the testing-presence points, sample
the testing-absence (or testing-background) points, and reference
the training-presence points.
1 |
fixed |
two column matrix (x, y) or (longitude/latitude) or SpatialPoints object, for point locations for which a pair should be found in |
sample |
as above for point locations from which to sample to make a pair with a point from |
reference |
as above for reference point locations to which distances are computed |
n |
How many pairs do you want for each point in |
tr |
Numeric, normally below 1. The threshold distance for a pair of points (one of |
nearest |
Logical. If |
lonlat |
Logical. Use |
warn |
Logical. If |
A matrix of nrow(fixed) and ncol(n), that indicates, for each point (row) in fixed
which point(s) in sample
it is paired to; or NA
if no suitable pair was available.
Robert J. Hijmans
Hijmans, R.J., 2012. Cross-validation of species distribution models: removing spatial sorting bias and calibration with a null-model. Ecology 93: 679-688
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 | ref <- matrix(c(-54.5,-38.5, 2.5, -9.5, -45.5, 1.5, 9.5, 4.5, -10.5, -10.5), ncol=2)
fix <- matrix(c(-56.5, -30.5, -6.5, 14.5, -25.5, -48.5, 14.5, -2.5, 14.5,
-11.5, -17.5, -11.5), ncol=2)
r <- raster()
extent(r) <- c(-110, 110, -45, 45)
r[] <- 1
set.seed(0)
sam <- randomPoints(r, n=50)
par(mfrow=c(1,2))
plot(sam, pch='x')
points(ref, col='red', pch=18, cex=2)
points(fix, col='blue', pch=20, cex=2)
i <- pwdSample(fix, sam, ref, lonlat=TRUE)
i
sfix <- fix[!is.na(i), ]
ssam <- sam[i[!is.na(i)], ]
ssam
plot(sam, pch='x', cex=0)
points(ssam, pch='x')
points(ref, col='red', pch=18, cex=2)
points(sfix, col='blue', pch=20, cex=2)
# try to get 3 pairs for each point in 'fixed'
pwdSample(fix, sam, ref, lonlat=TRUE, n=3)
|
Loading required package: raster
Loading required package: sp
NOTE: rgdal::checkCRSArgs: no proj_defs.dat in PROJ.4 shared files
NOTE: rgdal::checkCRSArgs: no proj_defs.dat in PROJ.4 shared files
NOTE: rgdal::checkCRSArgs: no proj_defs.dat in PROJ.4 shared files
NOTE: rgdal::checkCRSArgs: no proj_defs.dat in PROJ.4 shared files
[,1]
[1,] 13
[2,] 7
[3,] NA
[4,] 25
[5,] 8
[6,] NA
x y
[1,] -4.5833333 -20.25
[2,] 0.9166667 15.75
[3,] -51.6388889 -31.25
[4,] -31.4722222 -19.75
[,1] [,2] [,3]
[1,] 13 NA NA
[2,] 8 NA NA
[3,] 7 NA NA
[4,] 25 47 18
[5,] 45 NA NA
[6,] NA NA NA
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.