Learn R Programming

propagate (version 1.0-4)

rDistr: Creating random samples from a variety of useful distributions

Description

These are random sample generators for 15 different continuous distributions which are not readily available as other Distributions in R. Some of them are implemented in other specialized packages (i.e. rsn in package 'sn' or rtrapezoid in package 'trapezoid'), but here they are collated in a way that makes them easily accessible for Monte Carlo-based uncertainty propagation.

Arguments

Value

A vector with n samples from the corresponding distribution.

Details

Random samples can be drawn from the following distributions: 1) Skewed-normal distribution: propagate:::rsn(n, location = 0, scale = 1, shape = 0) 2) Generalized normal distribution: propagate:::rgnorm(n, alpha = 1, xi = 1, kappa = -0.1) 3) Scaled and shifted t-distribution: propagate:::rst(n, mean = 0, sd = 1, df = 2) 4) Gumbel distribution: propagate:::rgumbel(n, location = 0, scale = 1) 5) Johnson SU distribution: propagate:::rJSU(n, xi = 0, lambda = 1, gamma = 1, delta = 1) 6) Johnson SB distribution: propagate:::rJSB(n, xi = 0, lambda = 1, gamma = 1, delta = 1) 7) 3P Weibull distribution: propagate:::rweibull2(n, location = 0, shape = 1, scale = 1) 8) 4P Beta distribution: propagate:::rbeta2(n, alpha1 = 1, alpha2 = 1, a = 0, b = 0) 9) Triangular distribution: propagate:::rtriang(n, a = 0, b = 1, c = 0.5) 10) Trapezoidal distribution: propagate:::rtrap(n, a = 0, b = 1, c = 2, d = 3) 11) Curvilinear Trapezoidal distribution: propagate:::rctrap(n, a = 0, b = 1, d = 0.1) 12) Generalized trapezoidal distribution: propagate:::rgtrap(n, min = 0, mode1 = 1/3, mode2 = 2/3, max = 1, n1 = 2, n3 = 2, alpha = 1) 13) Laplacian distribution: propagate:::rlaplace(n, mean = 0, sigma = 1) 14) Arcsine distribution: propagate:::rarcsin(n, a = 2, b = 1) 15) von Mises distribution: propagate:::rmises(n, mu = 1, kappa = 3) with n = number of samples.

1) - 10) and 13) - 14) use the inverse cumulative distribution function as mapping functions for runif (Inverse Transform Method): (1) \(U \sim \mathcal{U}(0, 1)\) (2) \(Y = F^{-1}(U, \beta)\)

11), 12) and 15) employ "Rejection Sampling" using a uniform envelope distribution (Acceptance Rejection Method): (1) Find \(F_{max} = \max(F([x_{min}, x_{max}], \beta)\) (2) \(U_{max} = 1/(x_{max} - x_{min})\) (3) \(A = F_{max}/U_{max}\) (4) \(U \sim \mathcal{U}(0, 1)\) (5) \(X \sim \mathcal{U}(x_{min}, x_{max})\) (6) \(Y \iff U \le A \cdot \mathcal{U}(X, x_{min}, x_{max})/F(X, \beta)\)

These three distributions are coded in a vectorized approach and are hence not much slower than implementations in C/C++ (0.2 - 0.5 sec for 100000 samples; 3 GHz Quadcore processor, 4 GByte RAM). The code for the random generators is in file "distr-samplers.R".

References

Inverse CDFs were taken from: "The Ultimate Univariate Probability Distribution Explorer" http://blog.wolfram.com/data/uploads/2013/02/ProbabilityDistributionExplorer.zip.

Rejection Sampling in R: Playing with R: Rejection Sampling. http://playingwithr.blogspot.de/2011/06/rejection-sampling.html.

An example of rejection sampling. http://www.mas.ncl.ac.uk/~ndjw1/teaching/sim/reject/circ.html.

Rejection Sampling in general: Non-uniform random variate generation. Devroye L. Springer-Verlag, New York (1986).

Distributions: Continuous univariate distributions, Volume 1. Johnson NL, Kotz S and Balakrishnan N. Wiley Series in Probability and Statistics, 2.ed (2004).

See Also

See also propagate, in which GUM 2008 Supplement 1 examples use these distributions.

Examples

Run this code
# NOT RUN {
## First we create random samples from the
## von Mises distribution.
X <- propagate:::rmises(100000, mu = 10, kappa = 3)

## then we fit all available distributions
## with 'fitDistr'.
fitDistr(X)$aic
## => von Mises wins! (lowest AIC)
# }

Run the code above in your browser using DataLab