The Triangle Distribution
triangleUC.RdDensity, distribution function, quantile function and random
generation for the Triangle distribution with parameter
theta.
Usage
dtriangle(x, theta, lower = 0, upper = 1, log = FALSE)
ptriangle(q, theta, lower = 0, upper = 1, lower.tail = TRUE, log.p = FALSE)
qtriangle(p, theta, lower = 0, upper = 1, lower.tail = TRUE, log.p = FALSE)
rtriangle(n, theta, lower = 0, upper = 1)Arguments
- x, q
vector of quantiles.
- p
vector of probabilities.
- n
number of observations. Same as
runif.- theta
the theta parameter which lies between
lowerandupper.- lower, upper
lower and upper limits of the distribution. Must be finite.
- log
Logical. If
log = TRUEthen the logarithm of the density is returned.- lower.tail, log.p
Value
dtriangle gives the density,
ptriangle gives the distribution function,
qtriangle gives the quantile function, and
rtriangle generates random deviates.
Details
See triangle,
the VGAM family function
for estimating the parameter \(\theta\) by
maximum likelihood estimation, however the regular
conditions do not hold so the algorithm crawls
to the solution if lucky.
See also
triangle,
topple.
Examples
if (FALSE) x <- seq(-0.1, 1.1, by = 0.01); theta <- 0.75
plot(x, dtriangle(x, theta = theta), type = "l", col = "blue", las = 1,
main = "Blue is density, orange is the CDF",
sub = "Purple lines are the 10,20,...,90 percentiles",
ylim = c(0,2), ylab = "")
#> Error in h(simpleError(msg, call)): error in evaluating the argument 'x' in selecting a method for function 'plot': object 'x' not found
abline(h = 0, col = "blue", lty = 2)
#> Error in int_abline(a = a, b = b, h = h, v = v, untf = untf, ...): plot.new has not been called yet
lines(x, ptriangle(x, theta = theta), col = "orange")
#> Error: object 'x' not found
probs <- seq(0.1, 0.9, by = 0.1)
Q <- qtriangle(probs, theta = theta)
lines(Q, dtriangle(Q, theta = theta), col = "purple", lty = 3, type = "h")
#> Error in plot.xy(xy.coords(x, y), type = type, ...): plot.new has not been called yet
ptriangle(Q, theta = theta) - probs # Should be all zero
#> [1] 2.775558e-17 2.775558e-17 0.000000e+00 1.110223e-16 -5.551115e-17
#> [6] 0.000000e+00 0.000000e+00 0.000000e+00 -1.110223e-16
abline(h = probs, col = "purple", lty = 3) # \dontrun{}
#> Error in int_abline(a = a, b = b, h = h, v = v, untf = untf, ...): plot.new has not been called yet