Learn R Programming

spup (version 1.4-0)

genSample.MarginalNumericSpatial: Generating Monte Carlo sample from an uncertain object of a class 'MarginalNumericSpatial'

Description

Function that runs Monte Carlo simulations depending on the type of uncertain object. Facilitates unconditional gausian simulation of errors for spatially auto-correlated residulas, and random sampling, stratified sampling if no spatial auto-correlation is included.

Usage

# S3 method for MarginalNumericSpatial
genSample(
  UMobject,
  n,
  samplemethod,
  p = 0,
  asList = TRUE,
  debug.level = 1,
  ...
)

Value

A Monte Carlo sample of uncertain input of a class of distribution parameters.

Arguments

UMobject

uncertain object defined using defineUM().

n

Integer. Number of Monte Carlo realizations.

samplemethod

"ugs" for spatially correlated errors, "randomSampling" and "stratifiedSampling" if no spatial correlation of errors is considered.

p

A vector of quantiles. Optional. Only required if sample method is "stratifiedSampling" or "lhs".

asList

logical. If asList = TRUE returns list of all samples as a list. If asList = FALSE returns samples in a format of distribution parameters in UMobject.

debug.level

integer; set gstat internal debug level, see below for useful values. If set to -1 (or any negative value), a progress counter is printed.

...

Additional parameters that may be passed, e.g. in the "ugs" method. See examples.

Author

Kasia Sawicka, Stefan van Dam, Gerard Heuvelink

Details

"ugs" Unconditional gaussian simulation of spatially auto-correlated errors.

"stratifiedSampling" Number of samples (n) must be dividable by the number of quantiles to assure each quantile is evenly represented.

"lhs" Sampling method for at least two uncertain inputs. The uncertain.object is then a list of two or more. It uses startified sampling method to generate the inputs for the latin hypercude algorithm, hence the p is restricted as above.

Examples

Run this code

set.seed(12345)
# load data
data(dem30m, dem30m_sd)

# "ugs" method example
dem_crm <- makeCRM(acf0 = 0.78, range = 321, model = "Exp")
demUM <- defineUM(uncertain = TRUE, distribution = "norm", 
                   distr_param = c(dem30m, dem30m_sd), crm = dem_crm)
                   
# toy example
dem_sample <- genSample(UMobject = demUM, n = 2, samplemethod = "ugs", nmax = 6, asList = FALSE)
str(dem_sample)               
if (FALSE) {
dem_sample <- genSample(UMobject = demUM, n = 50, samplemethod = "ugs", nmax = 20, asList = FALSE)
str(dem_sample)
}


# "startifiedSampling" method example
demUM <- defineUM(uncertain = TRUE, distribution = "norm", distr_param = c(dem30m, dem30m_sd))
# toy example
dem_sample <- genSample(UMobject = demUM, n = 5, samplemethod = "stratifiedSampling", p = 0:5/5)
if (FALSE) {
dem_sample <- genSample(UMobject = demUM, n = 50, samplemethod = "stratifiedSampling", p = 0:5/5)
str(dem_sample)
}

# Examples with rasters
# (raster with auto-correlation)
data(OC, OC_sd)
OC_crm <- makeCRM(acf0 = 0.6, range = 1000, model = "Sph")
OC_UM <- defineUM(TRUE, distribution = "norm", distr_param = c(OC, OC_sd), crm = OC_crm, id = "OC")
class(OC_UM)
# toy example
some_sample <- genSample(OC_UM, n = 3, "ugs", nmax=6)
some_sample
if (FALSE) {
some_sample <- genSample(OC_UM, n = 50, "ugs", nmax=20)
some_sample
}

Run the code above in your browser using DataLab