These functions provide information about the triangular
distribution on the interval from min
to max
with mode equal
to mode
. dtri
gives the density function, estri
gives
the expected shortfall, mgtri
gives the moment generating function,
ptri
gives the distribution function, qtri
gives the quantile
function, and rtri
gives the random variate generator.
dtri(x, min = 0, max = 1, mode = 0.5, log = FALSE) ptri(q, min = 0, max = 1, mode = 0.5, lower_tail = TRUE, log_p = FALSE) qtri(p, min = 0, max = 1, mode = 0.5, lower_tail = TRUE, log_p = FALSE) rtri(n, min = 0, max = 1, mode = 0.5) mgtri(t, min = 0, max = 1, mode = 0.5) estri(p, min = 0, max = 1, mode = 0.5, lower_tail = TRUE, log_p = FALSE)
x, q | Vector of quantiles. |
---|---|
min | Lower limit of the distribution. Must have |
max | Upper limit of the distribution. Must have |
mode | The mode of the distribution. Must have |
log, log_p | Logical; if |
lower_tail | Logical; if |
p | Vector of probabilities. |
n | Number of observations. Must have length of one. |
t | Vector of dummy variables. |
dtri
gives the density function,
estri
gives the expected shortfall,
mgtri
gives the moment generating function,
ptri
gives the distribution function,
qtri
gives the quantile function, and
rtri
gives the random variate generator.
The numerical arguments other than n
with values of size one are
recycled to the length of t
for mgtri
, the length of x
for dtri
, the length of p
for estri
and qtri
,
the length of q
for ptri
, and n
for rtri
. This
determines the length of the result.
The logical arguments log
, lower_tail
, and log_p
must
be of length one each.
If min
, max
, or mode
are not specified they assume the
default values of 0
, 1
, and 0.5
respectively.
The triangular distribution has density $$0$$ for \(x < min\) or \(x > max\) $$f(x) = \frac{2(x - min)}{(max - min)(mode - min)}$$ for \(min \le x < mode\), and $$f(x) = \frac{2(max - x)}{(max - min)(max - mode)}$$ for \(mode < x \le max\).
rtri
will not generate either of the extreme values unless
max - min
is small compared to min
, and in particular not for
the default arguments.
The characteristics of output from pseudo-random number generators
(such as precision and periodicity) vary widely. See
.Random.seed
for more information on R's random number
generation algorithms.
RNG
about random number generation in R.
Distributions for other standard distributions.
# min, max, and mode with lengths equal to the length of x x <- c(0, 0.5, 1) d <- dtri(x, min = c(0, 0, 0), max = c(1, 1, 1), mode = c(0.5, 0.5, 0.5)) # min and max will be recycled to the length of x rec_d <- dtri(x, min = 0, max = 1, mode = c(0.5, 0.5, 0.5)) all.equal(d, rec_d)#> [1] TRUE# min, max, and mode with lengths equal to the length of x n <- 3 set.seed(1) r <- rtri(n, min = c(0, 0, 0), max = c(1, 1, 1), mode = c(0.5, 0.5, 0.5)) # min and max will be recycled to the length of n set.seed(1) rec_r <- rtri(n, min = 0, max = 1, mode = c(0.5, 0.5, 0.5)) all.equal(r, rec_r)#> [1] TRUE# Log quantiles x <- c(0, 0.5, 1) log_d <- dtri(x, log = TRUE) d <- dtri(x, log = FALSE) all.equal(log(d), log_d)#> [1] TRUE# Upper tail probabilities q <- c(0, 0.5, 1) upper_p <- ptri(q, lower_tail = FALSE) p <- ptri(q, lower_tail = TRUE) all.equal(upper_p, 1 - p)#> [1] TRUE# Log probabilities q <- c(0, 0.5, 1) log_p <- ptri(q, log_p = TRUE) p <- ptri(q, log_p = FALSE) all.equal(upper_p, 1 - p)#> [1] TRUE# The quantile function p <- c(0, 0.5, 1) upper_q <- ptri(1 - p, lower_tail = FALSE) q <- ptri(p, lower_tail = TRUE) all.equal(upper_q, q)#> [1] TRUEp <- c(0, 0.5, 1) log_q <- qtri(log(p), log_p = TRUE) q <- qtri(p, log_p = FALSE) all.equal(log_q, q)#> [1] TRUE#> [1] 1.683357 2.952492 5.387626#> [1] 0.1490712 0.3333333 0.5000000