First and foremost, distr6 is a package for probability distributions in R. Currently there are 36 distributions implemented in distr6 and another 11 kernels. These tutorials try to follow the journey for using, editing and analysing a probability distribution. Don’t worry if you’ve never used R6 before, these tutorials assume no prior knowledge of R6. If you’re interested in learning the basics of R6, see the tutorial “Introduction to R6”, this tutorial is particularly useful for understanding how to copy (or clone) distributions in R.

We will use the Normal probability distribution as a running example.

Constructing a Distribution

All distributions are constructed using the distribution name, followed by $new(...) where ... are arguments to the constructor. This is different from base R in which a function is called directly. To construct a Standard Normal distribution,

N <- Normal$new()

Printing the distribution shows the distribution name and parameterisation. Notice how printing works the same as always in R, i.e. with print().

print(N)
#> Norm(mean = 0, var = 1)

To access useful statistics, distr6 includes a summary method

N$summary()
#> Normal Probability Distribution. 
#> Parameterised with:
#> 
#>        Id Support  Value            Tags
#>    <char>  <char> <list>          <list>
#> 1:   mean       ℝ      0        required
#> 2:   prec      ℝ+        linked,required
#> 3:     sd      ℝ+        linked,required
#> 4:    var      ℝ+      1 linked,required
#> 
#> 
#> Quick Statistics
#>  Mean:       0
#>  Variance:   1
#>  Skewness:   0
#>  Ex. Kurtosis:   0
#> 
#> Support: ℝ   Scientific Type: ℝ 
#> 
#> Traits:      continuous; univariate
#> Properties:  symmetric; mesokurtic; no skew

Alternative Parameterisations

The distribution parameterisation refers to the parameters that are used to define the distribution. The choice of parameterisation often depends on how you want to the distribution to be interpreted and if fitting procedures will be utilised.

In the case of the Normal distribution, several parameterisations are possible. These include with mean and variance, standard deviation or precision. The parameterisation is specified in construction by naming the parameters, for example mean and standard deviation:

Normal$new(mean = 2, sd = 2)
#> Norm(mean = 2, sd = 2)

Or mean and precision:

Normal$new(mean = 2, prec = 2)
#> Norm(mean = 2, prec = 2)

Finally be careful not to construct a distribution using conflicting parameterisations. For example:

Normal$new(mean = 2, var = 2, sd = 3, prec = 4)
#> Error in .return_fail(msg = "Multiple linked parameters are set.", error_on_fail): Multiple linked parameters are set.

Summary

In this tutorial we looked at constructing a distribution with different parameterisations. In the next tutorial we look at getting and setting parameters and how this functions with your chosen parameterisation.