sampleObsMat: Draw Bootstrap Samples

View source: R/sampleObsMat.R

sampleObsMatR Documentation

Draw Bootstrap Samples

Description

sampleObsMat returns nsim bootstrap samples of a set of indicator observations from the same year or reference values.

Usage

sampleObsMat(
  ICunitId = NULL,
  value = NULL,
  distrib = NULL,
  mu = NULL,
  sig = NULL,
  customDistribution = NULL,
  imputations = NULL,
  obsMethod = "sample",
  obsType = NULL,
  impYear = NULL,
  nsim = 1000
)

Arguments

ICunitId

integer vector

value

numeric vector with expected values

distrib

character vector with names of model distributions

mu

numeric vector with parameter 1 of model distribution

sig

numeric vector with parameter 2 of model distribution

customDistribution

list of distribution objects and NAs

imputations

optional list of class niImputations

obsMethod

string, either "sample" or "constant"

obsType

character vector with observation types. Valid elements are:
"tradObs": corresponding observation is a two-parameter, non-negative, probability distribution given by corresponding elements in distrib, mu and sig
"customObs": corresponding observation is a custom distribution object in customDistribution
"imputations": corresponding observation is stored in the object imputations as nsim draws, one from each of nsim imputed distributions.

impYear

character, year in question. The parameter is only relevant when the data set includes imputed values. Used to identify the correct elements in imputations which might include observations from several years. The parameter is not relevant for sets of reference values.

nsim

integer - number of bootstrap simulations, default is 1000.

Details

Bootstrap samples consist of either nsim random draws from a set of probability distributions, or nsim copies of the elements of value, depending on the parameter obsMethod.

Probability distributions are either two-parameter, non-negative probability distributions given by vectors distrib, mu and sig, or distribution objects in the list customDistribution, or a distribution of nsim sampled, imputed values in imputes.

sampleObsMat presumes that the set of probability distributions only includes the truncated normal-, lognormal-, weibull-, gamma-, zero-inflated exponential, poisson-, negative binomial-, and zero-inflated poisson distributions. The lower bound in the truncated normal distribution is always zero, while the upper bound is infinity.

sampleObsMat is a utility function adapted to the mathematical framework for calculating the nature index.

sampleObsMat calls functions sampleobs and sampleDistribution which do the random draws.

Value

numeric matrix, dim = c(length(values), nsim), nsim bootstrap samples of the set of indicator observations or reference values.

Author(s)

Bård Pedersen

See Also

sampleobs, sampleDistribution

Examples

x <- themeData$indicatorValues$`2019`[11:20,]
sampleObsMat(ICunitId = x$ICunitId,
             value = x$expectedValue,
             distrib = x$distributionFamilyName,
             mu = x$distParameter1,
             sig = x$distParameter2,
             customDistribution = x$customDistribution,
             obsMethod = "sample",
             obsType = "tradObs",
             nsim = 5)


NINAnor/NIcalc documentation built on Oct. 26, 2023, 9:37 a.m.