rsMove (version 0.2.1)

backSample: backSample

Description

Background sample selection.

Usage

backSample(xy = xy, rid = rid, method = method, img = img, nb = NULL)

Arguments

xy

Object of class SpatialPoints of SpatialPointsDataFrame.

rid

Vector of region identifyers for each sample.

method

One of random or pca. Default is random.

img

Object of class RasterLayer, RasterStack or RasterBrick.

nb

Number of random background samples.

Value

A SpatialPoints or a SpatialPointsDataFrame.

Details

The function selects a set of n background samples where n is determined by nb. If nb is not provided all background pixels are considered. If the method is random these samples are returned in the form of a SpatialPoints object. If pca is used, a PCA analysis is performed over all available samples (provided and random). For each unique region ID (rid) the median and the Median Absolute Deviation (MAD) is estimated for a given Principal Component (PC). Background samples where the difference between their variance and the variance of the region samples exceeds the MAD are selected. Only the samples that are selected by all unique regions are kept. This process is repeated for all PC's with eigenvalues greater than 1 (Kaiser rule). The final set of samples corresponds to the unique records selected by the different PC's. These samples are returned as a SpatialPointsDataFrame containing the variables extracted from img.

See Also

labelSample hotMove dataQuery

Examples

Run this code
# NOT RUN {
{
 
 require(raster)
 
 # read raster data
 file <- list.files(system.file('extdata', '', package="rsMove"), 'tc.*tif', full.names=TRUE)
 rsStk <- stack(file)
 
 # read movement data
 moveData <- read.csv(system.file('extdata', 'konstanz_20130805-20130811.csv', package="rsMove"))
 moveData <- SpatialPointsDataFrame(moveData[,1:2], moveData, proj4string=crs(rsStk))
 
 # find sample regions
 label <- labelSample(xy=moveData, rad=500, npx=2, pxr=30)
 
 # select background samples
 ind <- which(label>0) # selected samples
 bSamples <- backSample(xy=moveData[ind,], rid=label[ind], img=rsStk, method='random')
 
}
# }

Run the code above in your browser using DataLab