Skip to contents

Use this function to create a new ddf object by passing the support and the corresponding probabilities as vectors to it.

Usage

ddf(
  supp,
  probs = rep(1/length(supp), length(supp)),
  desc = "A discrete distribution with finite support"
)

Arguments

supp

A numeric vector, support.

probs

A numeric vector, the corresponding probabilities

desc

A character, a short description of the discrete distribution.

Value

A ddf object with the specified attributes.

Details

This function makes sure that your ddf objects are "clean" by ensuring the following two conditions:

  • The passed support is ordered in ascending order.

  • Duplicates within the support are removed and the probabilities of the affected elements are simply summed up.

  • Elements of the passed "support" that have probability 0 are removed as they then, by definition, are not contained in the support.

If the probabilities aren't supplied, they are distributed uniformly over the specified support.

Examples

# Create ddf object for an ordinary six-sided dice
dice <- ddf(1:6, desc = "Distribution modelling a six-sided dice")
dice
#> Distribution modelling a six-sided dice 
#> 
#> Support:
#> [1] 1 2 3 4 5 6
#> 
#> Probabilities:
#> [1] 0.1666667 0.1666667 0.1666667 0.1666667 0.1666667 0.1666667
# Create ddf object for an unfair coin toss without custom description
coin_toss <- ddf(c(1, 2), c(1 / 4, 3 / 4))
coin_toss
#> A discrete distribution with finite support 
#> 
#> Support:
#> [1] 1 2
#> 
#> Probabilities:
#> [1] 0.25 0.75