Learn R Programming

logcondiscr (version 1.0.6)

Triangular: Functions to compute a and simulate from a triangular probability mass function

Description

In Balabdaoui et al (2012) the triangular density, defined as $$p_x^{a, b, c, d, e} = c(x - a) / (b - a)$$ for $x \in {a, \ldots, c}$ and $$p_x^{a, b, c, d, e} = (e - c)(x - b) / (d - b) + c$$ for $x \in {c, \ldots, d}$, was used to illustrate the limit process of the log-concave MLE. In order to provide the code to generate the limit process figure in Balabdaoui et al (2012, see the example in logConDiscrMLE for the code to generate that figure) the functions dTriangular and rTriangular are included in this package. Note that rTriangular uses the rejection sampling algorithm in Devroye (1987) which was specifically developed to generate random numbers from a log-concave PMF.

Usage

dTriangular(a, b, c, d, e)
rTriangular(n, a, b, c, d, e)

Arguments

a
Left endpoint of triangular pmf.
b
Mode of triangular pmf.
c
Height at mode.
d
Left endpoint.
e
Height at left endpoint.
n
Number of random numbers to generate.

Value

  • dTriangular returns a vector containing the value of the PMF at all values in $x \in {a, \ldots, d}$. rTriangular returns a list containing the elements:
  • randVector with generated random numbers of length $n$.
  • xVector $(a, \ldots, d)$.
  • densValue of the pmf at $x$.

References

Balabdaoui, F., Jankowski, H., Rufibach, K., and Pavlides, M. (2013). Maximum likelihood estimation and confidence bands for a discrete log-concave distribution. J. R. Stat. Soc. Ser. B Stat. Methodol., 75(4), 769--790. Devroye, L. (1987). A simple generator for discrete log-concave distributions. Computing, 39, 87-91.

Examples

Run this code
## -------------------------------------------------------------
## compute values of triangular density and simulate from it
## -------------------------------------------------------------
a <- 1
b <- 7
c <- 8
d <- 11
e <- 2
n <- 10 ^ 2

## support
x <- seq(a, d, by = 1)

## true density
dens <- dTriangular(a, b, c, d, e)
logdens <- log(dens)
rand <- rTriangular(n, a, b, c, d, e)$rand

## does the same as rTriangular()
rand2 <- sample(x = a:d, size = n, prob = dens, replace = TRUE)

Run the code above in your browser using DataLab