Skip to contents

Create a ddf object for the discrete uniform distribution on the first \(n\) natural numbers (including or excluding 0).

Usage

unif(n, start_at_one = TRUE)

Arguments

n

An integer, the upper end of the support.

start_at_one

Logical, whether to start the support at 0 or 1. (default: TRUE)

Value

A ddf distribution as described above.

Details

The discrete uniform distribution describes models in which a finite number of possible outcomes are equally likely to happen. In general, it has an arbitrary finite set, say of cardinality \(N\in\mathbb{N}\), as its support with every element of the support having the same probability \(\frac{1}{N}\).

This function, however, only generates the uniform distribution on support \(\{1, \dots, n\}\) or \(\{0, \dots, n\}\). For more complicated supports, it's expected to be much easier to simply use ddf() without specifying probabilities, rather than using a custom function like this one. For a demonstration of this, see also the ‘Examples’ below.

See also

Examples

# Probability distribution for modelling a
# six-sided dice (uniform on {1, ..., 6})
unif(6)
#> Discrete uniform distribution on {1, ..., 6} 
#> 
#> Support:
#> [1] 1 2 3 4 5 6
#> 
#> Probabilities:
#> [1] 0.1666667 0.1666667 0.1666667 0.1666667 0.1666667 0.1666667

# For more complicated supports, use ddf
# Same distribution as above (except for description):
ddf(1:6)
#> A discrete distribution with finite support 
#> 
#> Support:
#> [1] 1 2 3 4 5 6
#> 
#> Probabilities:
#> [1] 0.1666667 0.1666667 0.1666667 0.1666667 0.1666667 0.1666667
# Not possible using unif:
ddf(seq(3, 12, 3))
#> A discrete distribution with finite support 
#> 
#> Support:
#> [1]  3  6  9 12
#> 
#> Probabilities:
#> [1] 0.25 0.25 0.25 0.25