Skip to contents

Use this function to create a new ddf object based on absolute frequencies by passing the occurred observations and corresponding absolute frequencies as vectors to it.

Usage

ddf_from_frequencies(
  events,
  frequencies = rep(1/length(events), length(events)),
  desc = paste("A discrete distribution with finite support,",
    "generated from frequencies")
)

Arguments

events

A numeric vector, the event space.

frequencies

A numeric vector, the corresponding absolute frequencies.

desc

A character, a short description of the discrete distribution.

Value

A ddf object as described above.

Details

Although the purpose of this package is to work with discrete distributions with finite support, it might still be helpful to use some of its functions for working with frequency counts. For example, one might want to calculate an interquartile range or the excess kurtosis.

The purpose of this function is to make this possible in a convenient way. A new ddf object is created by dividing all frequency counts by the total number of observations such that the resulting vector sums up to 1.

This function furthermore ensures the same quality checks as ddf() (see the ‘Details.’ section) and has the same behaviour when no frequencies are passed, i.e. the probabilities are distributed uniformly over the specified observations.

Examples

# Create ddf object from (hypothetical) frequencies
# of tossing a fair coin 10 times
coin_tosses <- ddf_from_frequencies(c(1, 2), c(3, 7))
coin_tosses
#> A discrete distribution with finite support, generated from frequencies 
#> 
#> Support:
#> [1] 1 2
#> 
#> Probabilities:
#> [1] 0.3 0.7