roll: The roll distribution

Description Usage Arguments Details Value Source See Also Examples

Description

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

Usage

1
2
3
4
5
6
7
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.

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.

Value

A numeric vector.

Source

The main algorithm for calculating dice probabilities comes from MathWorld.

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

See Also

r(), Dice, roll-plot.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
set.seed(42)

# Density of 2d6 + 5
droll(12, 2 * d6 + 5)

# Distribution function of 2d6 + 5
proll(12, 2 * d6 + 5)

# Quantile function of 2d6 + 5
qroll(0.5, 2 * d6 + 5)

# Roll 2d6 + 5 (generate random deviate)
rroll(1, 2 * d6 + 5)

droll documentation built on Aug. 7, 2021, 1:05 a.m.