Density, distribution function, quantile function, and random generation for the discrete distribution described by a roll expression. See below for more details.

droll(x, roll)

proll(q, roll, lower.tail = TRUE)

qroll(p, roll, lower.tail = TRUE)

rroll(n, roll)

Arguments

x

A numeric vector of outcomes.

roll

A roll expression (e.g., 2 * d6 + 5) or a data frame returned by r().

q

A numeric vector of outcomes.

lower.tail

Whether to calculate P[X <= x] or P[X > x].

p

A numeric vector of probabilities.

n

Number of random deviates to return.

Source

The main algorithm for calculating dice probabilities comes from MathWorld.

Symbolic calculations are handled by Ryacas, and, by extension, by Yacas.

Value

A numeric vector.

Details

Given a roll expression (i.e., an arithmetic expression involving dice), r() calculates the complete distribution of the outcomes. This is possible because the distribution is discrete and has a finite number of outcomes.

From this distribution, droll() returns the density, proll() returns the distribution function, qroll() returns the quantile function, and rroll() generates random deviates. They mirror functions from the Distributions family.

For more details on roll expressions, see r() and the Dice S4 class.

See also

Examples

set.seed(42) # Density of 2d6 + 5 droll(12, 2 * d6 + 5)
#> [1] 0.1666667
# Distribution function of 2d6 + 5 proll(12, 2 * d6 + 5)
#> [1] 0.5833333
# Quantile function of 2d6 + 5 qroll(0.5, 2 * d6 + 5)
#> [1] 12
# Roll 2d6 + 5 (generate random deviate) rroll(1, 2 * d6 + 5)
#> [1] 14