Density, distribution function and random generation for the triangular distribution.
dtriang(x, log=FALSE)
ptriang(q, lower.tail=TRUE, log.p=FALSE)
rtriang(n)
dtriang gives the density, ptriang gives the distribution function, and rtriang generates random deviates. The length of the result is determined by n for rasin, and is the maximum of the lengths of the numerical arguments for the other functions. The numerical arguments other than n are recycled to the length of the result. Only the first elements of the logical arguments are used.
vector of quantiles.
number of observations. If length(n) > 1, the length is taken to be the number required.
logical; if TRUE, probabilities p are given as log(p).
logical; if TRUE (default), probabilities are \(P[X\leq x]\), otherwise, \(P[X>x]\).
Diego Gallardo
The triangular distribution has density $$ f(x) = \left\{ \begin{array}{lr} 4x, & 0\leq x\leq 1/2,\\ 4(1-x), & 1/2<x\leq 1, \end{array} \right. $$ and cumulative distribution function $$ F(x) = \left\{ \begin{array}{lr} 2x^2, & 0\leq x\leq 1/2,\\ 2x^2-(2x-1)^2, & 1/2<x\leq 1, \end{array} \right. $$
dtriang(0.5)
ptriang(0.5)
rtriang(5)
Run the code above in your browser using DataLab