urtriang function

UNU.RAN Triangular random variate generator

UNU.RAN Triangular random variate generator

UNU.RAN random variate generator for the Triangular distribution with shape parameters a, m and b. It also allows sampling from the truncated distribution.

[Special Generator] -- Sampling Function: Triangular.

urtriang(n, a, m, b, lb=a, ub=b)

Arguments

  • n: size of required sample.
  • a,b: left and right boundary of domain
  • m: mode of distribution
  • lb: lower bound of (truncated) distribution.
  • ub: upper bound of (truncated) distribution.

Details

The Triangular distribution with domain (a,b)(a,b) and mode mm

has a density proportional to

f(x)(xa)/(ma)f(x) (xa)/(ma) f(x) \sim (x-a)/(m-a)f(x) ~ (x-a)/(m-a)

for a<=x<=ma <= x <= m, and

f(x)(bx)/(bm)f(x) (bx)/(bm) f(x) \sim (b-x)/(b-m)f(x) ~ (b-x)/(b-m)

for m<=x<=bm <= x <= b.

The generation algorithm uses fast numerical inversion. The parameters lb and ub can be used to generate variates from the Triangular distribution truncated to the interval (lb,ub).

See Also

runif and .Random.seed about random number generation and unuran for the UNU.RAN class.

References

W. H"ormann, J. Leydold, and G. Derflinger (2004): Automatic Nonuniform Random Variate Generation. Springer-Verlag, Berlin Heidelberg

Author(s)

Josef Leydold and Wolfgang H"ormann unuran@statmath.wu.ac.at .

Note

This function is a wrapper for the UNU.RAN class in .

Examples

## Create a sample of size 1000 x <- urtriang(n=1000,a=-1,m=0,b=2)
  • Maintainer: Josef Leydold
  • License: GPL (>= 2)
  • Last published: 2025-04-07