Create a random raster or raster stack using specified distribution

random.raster(
  r = NULL,
  n.row = 50,
  n.col = 50,
  n.layers = 1,
  x = seq(1, 10),
  min = 0,
  max = 1,
  mean = 0,
  sd = 1,
  p = 0.5,
  s = 1.5,
  distribution = c("random", "normal", "seq", "binominal", "gaussian")
)

Arguments

r

Optional existing raster defining nrow/ncol

n.row

Number of rows

n.col

Number of columns

n.layers

Number of layers in resulting raster stack

x

A vector of values to sample if distribution is "sample"

min

Minimum value of raster

max

Maximum value of raster

mean

Mean of centered distribution

sd

Standard deviation of centered distribution

p

p-value for binominal distribution

s

sigma value for Gaussian distribution

distribution

Available distributions, c("random", "normal", "seq", "binominal", "gaussian", "sample")

Value

RasterLayer or RasterStack object with random rasters

Details

Options for distributions are for random, normal, seq, binominal, gaussian and sample raster(s)

Author

Jeffrey S. Evans <jeffrey_evans@tnc.org>

Examples

library(raster) # Using existing raster to create random binominal r <- raster(system.file("external/rlogo.grd", package="raster")) r <- random.raster(r, distribution="binominal")
#> Calculating binominal distribution with 77 x 101 x 1 dimensions
#> Error in h(simpleError(msg, call)): error in evaluating the argument 'x' in selecting a method for function 'raster': Not an available distribution
# default; random, nrows=50, ncols=50, nlayers=1 rr <- random.raster(n.layer=5)
#> Calculating random distribution with 50 x 50 x 5 dimensions
# specified; binominal, nrows=20, ncols=20, nlayers=5 rr <- random.raster(n.layer=5, n.col=20, n.row=20, distribution="binominal")
#> Calculating binominal distribution with 20 x 20 x 5 dimensions
#> Error in h(simpleError(msg, call)): error in evaluating the argument 'x' in selecting a method for function 'raster': Not an available distribution
# specified; gaussian, nrows=50, ncols=50, nlayers=1 rr <- random.raster(n.col=50, n.row=50, s=8, distribution="gaussian")
#> Calculating gaussian distribution with 50 x 50 x 1 dimensions
# specified; sample, nrows=50, ncols=50, nlayers=1 rr <- random.raster(n.layer=1, x=c(2,6,10,15), distribution="sample" )
#> Calculating sample distribution with 50 x 50 x 1 dimensions
freq(rr)
#> $layer #> value count #> [1,] 2 666 #> [2,] 6 646 #> [3,] 10 603 #> [4,] 15 585 #>