Learn R Programming

metRology (version 0.9-16.1)

Triangular: 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).

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.

Details

The triangular distribution has density $$f(x)=2*(x-min) / ((max-min)*(mode-min)) (min < x <= 0="" mode)$$="" $$f(x)="2*(max-x)" ((max-min)*(max-mode))="" (mode="" <="" x="" max)$$="" and="" elsewhere.="" the="" mean="" is="" $$\frac{1}{3}(min="" +="" mode="" variance="" $$\frac{1}{18}(min^2="" mode^2="" max^2="" -="" min*mode="" min*max="" mode*max)$$="" 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.

See Also

runif

Examples

Run this code
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

Run the code above in your browser using DataLab