rdistq_fit {decisionSupport}R Documentation

Quantiles based univariate random number generation (by parameter fitting).

Description

This function generates random numbers for a set of univariate parametric distributions from given quantiles. Internally, this is achieved by fitting the distribution function to the given quantiles.

Usage

rdistq_fit(
  distribution,
  n,
  percentiles = c(0.05, 0.5, 0.95),
  quantiles,
  relativeTolerance = 0.05,
  tolConv = 0.001,
  fit.weights = rep(1, length(percentiles)),
  verbosity = 1
)

Arguments

distribution

A character string that defines the univariate distribution to be randomly sampled.

n

Number of generated observations.

percentiles

Numeric vector giving the percentiles.

quantiles

Numeric vector giving the quantiles.

relativeTolerance

numeric; the relative tolerance level of deviation of the generated individual percentiles from the specified percentiles. If any deviation is greater than relativeTolerance a warning is given.

tolConv

positive numerical value, the absolute convergence tolerance for reaching zero by fitting distributions get.norm.par will be shown.

fit.weights

numerical vector of the same length as a probabilities vector p containing positive values for weighting quantiles. By default all quantiles will be weighted by 1.

verbosity

integer; if 0 the function is silent; the larger the value the more verbose is the output information.

Details

The following table shows the available distributions and their identification (option: distribution) as a character string:

distribution Distribution Name length(quantiles) Necessary Package
"norm" Normal >=2
"beta" Beta >=2
"cauchy" Cauchy >=2
"logis" Logistic >=2
"t" Student t >=1
"chisq" Central Chi-Squared >=1
"chisqnc" Non-central Chi-Squared >=2
"exp" Exponential >=1
"f" Central F >=2
"gamma" Gamma with scale=1/rate >=2
"lnorm" Log Normal >=2
"unif" Uniform ==2
"weibull" Weibull >=2
"triang" Triangular >=3 mc2d
"gompertz" Gompertz >=2 eha
"pert" (Modified) PERT >=4 mc2d
"tnorm" Truncated Normal >=4 msm

percentiles and quantiles must be of the same length. percentiles must be >=0 and <=1.

The default for percentiles is 0.05, 0.5 and 0.95, so for the default, the quantiles argument should be a vector with 3 elements. If this is to be longer, the percentiles argument has to be adjusted to match the length of quantiles.

The fitting of the distribution parameters is done using rriskFitdist.perc.

Value

A numeric vector of length n with the sampled values according to the chosen distribution.

See Also

rriskFitdist.perc

Examples

# Fit a log normal distribution to 3 quantiles:
if ( requireNamespace("rriskDistributions", quietly = TRUE) ){
  percentiles<-c(0.05, 0.5, 0.95)
  quantiles=c(1,3,15)
  hist(r<-rdistq_fit(distribution="lnorm", n=10000, quantiles=quantiles),breaks=100)
  print(quantile(x=r, probs=percentiles))
}

[Package decisionSupport version 1.114 Index]