Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

sampleStratified

Stratified random sample


Description

Take a stratified random sample from the cell values of a Raster* object (without replacement). An attempt is made to sample size cells from each stratum. The values in the RasterLayer x are rounded to integers; with each value representing a stratum.

Usage

## S4 method for signature 'RasterLayer'
sampleStratified(x, size, exp=10, na.rm=TRUE, xy=FALSE, ext=NULL, sp=FALSE, ...)

Arguments

x

Raster* object, with values (rounded to integers) representing strata

size

positive integer giving the number of items to choose

exp

numeric >= 1. 'Expansion factor' that is multiplied with size to get an intial sample. Can be increased when you get an insufficient number of samples for small strata

na.rm

logical. If TRUE (the default), NA values are removed from random sample

xy

logical. Return coordinates of cells rather than cell numbers

ext

Extent object. To limit regular sampling to the area within the extent

sp

logical. If TRUE, a SpatialPointsDataFrame is returned

...

Additional arguments. None implemented

Details

The function may not work well when the size (number of cells) of some strata is relatively small.

Value

matrix of cell numbers (and optionally coordinates) by stratum

See Also

Examples

r <- raster(ncol=10, nrow=10)
 names(r) <- 'stratum'
 values(r) <- round((runif(ncell(r))+0.5)*3)
 sampleStratified(r, size=3)

raster

Geographic Data Analysis and Modeling

v3.4-10
GPL (>= 3)
Authors
Robert J. Hijmans [cre, aut] (<https://orcid.org/0000-0001-5872-2872>), Jacob van Etten [ctb], Michael Sumner [ctb], Joe Cheng [ctb], Dan Baston [ctb], Andrew Bevan [ctb], Roger Bivand [ctb], Lorenzo Busetto [ctb], Mort Canty [ctb], Ben Fasoli [ctb], David Forrest [ctb], Aniruddha Ghosh [ctb], Duncan Golicher [ctb], Josh Gray [ctb], Jonathan A. Greenberg [ctb], Paul Hiemstra [ctb], Kassel Hingee [ctb], Institute for Mathematics Applied Geosciences [cph], Charles Karney [ctb], Matteo Mattiuzzi [ctb], Steven Mosher [ctb], Babak Naimi [ctb], Jakub Nowosad [ctb], Edzer Pebesma [ctb], Oscar Perpinan Lamigueiro [ctb], Etienne B. Racine [ctb], Barry Rowlingson [ctb], Ashton Shortridge [ctb], Bill Venables [ctb], Rafael Wueest [ctb]
Initial release
2021-05-02

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.