Learn R Programming

Runuran (version 0.21.0)

urtriang: UNU.RAN Triangular random variate generator

Description

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.

Usage

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)$ and mode $m$ has a density proportional to $$f(x) \sim (x-a)/(m-a)$$ for $a \le x \le m$, and $$f(x) \sim (b-x)/(b-m)$$ for $m \le x \le 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).

References

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

See Also

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

Examples

Run this code
## Create a sample of size 1000
x <- urtriang(n=1000,a=-1,m=0,b=2)

Run the code above in your browser using DataLab