Title: | The Trapezoidal Distribution |
---|---|
Description: | The trapezoid package provides 'dtrapezoid', 'ptrapezoid', 'qtrapezoid', and 'rtrapezoid' functions for the trapezoidal distribution. |
Authors: | Jeremy Thoms Hetzel [aut, cre] |
Maintainer: | Jeremy Thoms Hetzel <[email protected]> |
License: | GPL-3 |
Version: | 2.0-2 |
Built: | 2025-02-03 05:40:01 UTC |
Source: | https://github.com/jthetzel/trapezoid |
Density function, distribution function, quantile function, and random generation for the trapezoidal distribution with minimum equal to ‘min’, lower mode equal to ‘mode1’, upper mode equal to ‘mode2’, and maximum equal to ‘max’. For the generalized trapezoidal distribution, ‘n1’, ‘n3’, and ‘alpha’ may optionally be specified.
dtrapezoid(x, min = 0, mode1 = 1/3, mode2 = 2/3, max = 1, n1 = 2, n3 = 2, alpha = 1, log = FALSE) ptrapezoid(q, min = 0, mode1 = 1/3, mode2 = 2/3, max = 1, n1 = 2, n3 = 2, alpha = 1, lower.tail = TRUE, log.p = FALSE) qtrapezoid(p, min = 0, mode1 = 1/3, mode2 = 2/3, max = 1, n1 = 2, n3 = 2, alpha = 1, lower.tail = TRUE, log.p = FALSE) rtrapezoid(n, min = 0, mode1 = 1/3, mode2 = 2/3, max = 1, n1 = 2, n3 = 2, alpha = 1)
dtrapezoid(x, min = 0, mode1 = 1/3, mode2 = 2/3, max = 1, n1 = 2, n3 = 2, alpha = 1, log = FALSE) ptrapezoid(q, min = 0, mode1 = 1/3, mode2 = 2/3, max = 1, n1 = 2, n3 = 2, alpha = 1, lower.tail = TRUE, log.p = FALSE) qtrapezoid(p, min = 0, mode1 = 1/3, mode2 = 2/3, max = 1, n1 = 2, n3 = 2, alpha = 1, lower.tail = TRUE, log.p = FALSE) rtrapezoid(n, min = 0, mode1 = 1/3, mode2 = 2/3, max = 1, n1 = 2, n3 = 2, alpha = 1)
x , q
|
vector of quantiles. |
p |
vector of probabilities. |
n |
number of observations. If length(n) |
min |
vector of minima. |
mode1 |
vector of lower modes. |
mode2 |
vector of upper modes. |
max |
vector of maxima. |
n1 |
vector of growth parameters. |
n3 |
vector of decay parameters. |
alpha |
vector of boundary ratio parameters. |
log , log.p
|
logical; if ‘TRUE’, probabilities ‘p’ are given as ‘log(p)’. |
lower.tail |
logical; if ‘TRUE’ (default), probabilities are ‘P[X <= x]’, otherwise, ‘P[X > x]’. |
The generalized trapezoidal distribution is described by van Dorp and Kotz (2003) and van Dorp and colleagues (2007). With ‘n1’, ‘n3’, and ‘alpha’ equal to the default values of 2, 2, and 1, respectively, the distribution shape is of a quadrilateral trapezoid. Altering ‘n1’, ‘n3’, or ‘alpha’ changes the growth rate, decay rate, and boundary ratio parameters, respectively, as demonstrated in the examples below.
‘dtrapezoid’ gives the density function, ‘ptrapezoid’ gives the distribution function, ‘qtrapezoid’ gives the quantile function, and ‘rtrapezoid’ generates random deviates.
Jeremy Thoms Hetzel [email protected]
van Dorp, J. R. and Kotz, S. (2003) Generalized trapezoidal distributions. Metrika. 58(1):85–97. Preprint available: http://www.seas.gwu.edu/~dorpjr/Publications/JournalPapers/Metrika2003VanDorp.pdf
van Dorp, J. R., Rambaud, S.C., Perez, J. G., and Pleguezuelo, R. H. (2007) An elicitation procedure for the generalized trapezoidal distribution with a uniform central stage. Decision Analysis Journal. 4:156–166. Preprint available: http://www.seas.gwu.edu/~dorpjr/Publications/JournalPapers/DA2007.pdf
Distributions for standard distributions.
## Plot default trapezoid distribution curve(dtrapezoid(x, min = 0, mode1 = 1/3, mode2 = 2/3, max = 1, n1 = 2, n3 = 2, alpha = 1), from = 0, to = 1) ## Plot triangular trapezoid distribution curve(dtrapezoid(x, min = 0, mode1 = 1/2, mode2 = 1/2, max = 1, n1 = 2, n3 = 2, alpha = 1), from = 0, to = 1) ## Explore effects of n1, n3, and alpha parameters # plyr and ggplot2 are required for this example require(plyr) require(ggplot2) x <- seq(from = 0, to = 1, by = 0.01) # Create a list of arguments, varying n1, n3, and alpha arguments <- list() arguments[['A']] <- list(x = x, n1 = 2, n3 = 2, alpha = 0.8) arguments[['B']] <- list(x = x, n1 = 1.5, n3 = 1.5, alpha = 1) arguments[['C']] <- list(x = x, n1 = 2.5, n3 = 2.5, alpha = 1.5) arguments[['D']] <- list(x = x, n1 = 1.5, n3 = 2.5, alpha = 0.5) arguments[['E']] <- list(x = x, n1 = 2.5, n3 = 1.5, alpha = 1) arguments[['F']] <- list(x = x, n1 = 0.5, n3 = 0.5, alpha = 1.5) arguments[['G']] <- list(x = x, n1 = 1.5, n3 = 0.5, alpha = 0.5) arguments[['H']] <- list(x = x, n1 = 2.5, n3 = 0.5, alpha = 1) arguments[['I']] <- list(x = x, n1 = 0.5, n3 = 1.5, alpha = 1.5) arguments[['J']] <- list(x = x, n1 = 0.5, n3 = 2.5, alpha = 0.5) # Calculate the distributions plot.data <- ldply(arguments, function(z) { x <- z$x density <- dtrapezoid(x = z$x, min = 0, mode1 = 0.2, mode2 = 0.8, max = 1, n1 = z$n1, n3 = z$n3, alpha = z$alpha) args <- paste("n1 = ", z$n1, ", n3 = ", z$n3, ", alpha = ", z$alpha, sep="", collapse="") out <- data.frame(x, density, args) }) # Create labels for later use in displaying the arguments on the plots plot.data$label <- paste(plot.data$.id, ": ", plot.data$args, sep="") # Create plots generalizedTrapezoids <- ggplot(data = plot.data, aes(x = x, y = density)) + geom_line() + theme_bw() + facet_wrap(~label, ncol = 2, scales = "free_y") print(generalizedTrapezoids)
## Plot default trapezoid distribution curve(dtrapezoid(x, min = 0, mode1 = 1/3, mode2 = 2/3, max = 1, n1 = 2, n3 = 2, alpha = 1), from = 0, to = 1) ## Plot triangular trapezoid distribution curve(dtrapezoid(x, min = 0, mode1 = 1/2, mode2 = 1/2, max = 1, n1 = 2, n3 = 2, alpha = 1), from = 0, to = 1) ## Explore effects of n1, n3, and alpha parameters # plyr and ggplot2 are required for this example require(plyr) require(ggplot2) x <- seq(from = 0, to = 1, by = 0.01) # Create a list of arguments, varying n1, n3, and alpha arguments <- list() arguments[['A']] <- list(x = x, n1 = 2, n3 = 2, alpha = 0.8) arguments[['B']] <- list(x = x, n1 = 1.5, n3 = 1.5, alpha = 1) arguments[['C']] <- list(x = x, n1 = 2.5, n3 = 2.5, alpha = 1.5) arguments[['D']] <- list(x = x, n1 = 1.5, n3 = 2.5, alpha = 0.5) arguments[['E']] <- list(x = x, n1 = 2.5, n3 = 1.5, alpha = 1) arguments[['F']] <- list(x = x, n1 = 0.5, n3 = 0.5, alpha = 1.5) arguments[['G']] <- list(x = x, n1 = 1.5, n3 = 0.5, alpha = 0.5) arguments[['H']] <- list(x = x, n1 = 2.5, n3 = 0.5, alpha = 1) arguments[['I']] <- list(x = x, n1 = 0.5, n3 = 1.5, alpha = 1.5) arguments[['J']] <- list(x = x, n1 = 0.5, n3 = 2.5, alpha = 0.5) # Calculate the distributions plot.data <- ldply(arguments, function(z) { x <- z$x density <- dtrapezoid(x = z$x, min = 0, mode1 = 0.2, mode2 = 0.8, max = 1, n1 = z$n1, n3 = z$n3, alpha = z$alpha) args <- paste("n1 = ", z$n1, ", n3 = ", z$n3, ", alpha = ", z$alpha, sep="", collapse="") out <- data.frame(x, density, args) }) # Create labels for later use in displaying the arguments on the plots plot.data$label <- paste(plot.data$.id, ": ", plot.data$args, sep="") # Create plots generalizedTrapezoids <- ggplot(data = plot.data, aes(x = x, y = density)) + geom_line() + theme_bw() + facet_wrap(~label, ncol = 2, scales = "free_y") print(generalizedTrapezoids)