| Triangular {metRology} | R Documentation |
The triangular distribution.
Description
Density, distribution function, quantile function and random generation for the triangular distribution with range 'min' to 'max' and mode equal to 'mode'.
Usage
dtri(x, min=-sqrt(6), max=sqrt(6), mode = (min + max)/2,
log = FALSE)
ptri(q, min=-sqrt(6), max=sqrt(6), mode = (min + max)/2,
lower.tail = TRUE, log.p = FALSE)
qtri(p, min=-sqrt(6), max=sqrt(6), mode = (min + max)/2,
lower.tail = TRUE, log.p = FALSE)
rtri(n, min=-sqrt(6), max=sqrt(6), mode = (min + max)/2)
Arguments
x, q |
Vector of quantiles. |
p |
Vector of quantiles. |
n |
Number of observations. If 'length(n) > 1', the length is taken to be the number required. |
min |
Vector of lower limits of distribution. |
max |
Vector of upper limits of distribution. |
mode |
Vector of modes |
lower.tail |
logical; if TRUE (default), probabilities are P[X <= x]; otherwise, P[X > x]. |
log, log.p |
logical; if TRUE, probabilities p are given as log(p). |
Details
The triangular distribution has density
f(x)=2*(x-min) / ((max-min)*(mode-min)) (min < x <= mode)
f(x)=2*(max-x) / ((max-min)*(max-mode)) (mode < x < max)
and 0 elsewhere.
The mean is
\frac{1}{3}(min + mode + max)
and the variance is
\frac{1}{18}(min^2 + mode^2 + max^2 - min*mode - min*max - mode*max)
The default values of min, max and mode give a distribution with
mean 0 and unit variance.
If min>max, min amd max will be silently interchanged. If
mode is not within [min, max], the functions return NA, with a warning.
rtri calls runif(n, 0, 1) to generate probabilities which are passed to
qtri.
Value
A vector of densities, probabilities, quantiles or random deviates.
dtri gives the density, ptri gives the distribution function,
qtri gives the quantile function, and rtri generates random deviates.
Author(s)
S. L. R. Ellison s.ellison@lgc.co.uk
See Also
Examples
require(graphics)
x<-seq(-3,3,0.02)
par(mfrow=c(2,1))
plot(x, dtri(x), type="l", main="Density")
plot(x, ptri(x), type="l", main="p(X<x)")
u <- rtri(5000)
var(rtri(10000,-1,1)) # ~ = 1/6 = 0.167