library(distr6)
set.seed(42)
knitr::opts_chunk$set(collapse = TRUE, comment = "#>")

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)

To access useful statistics, distr6 includes a summary method

N$summary()

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)

Or mean and precision:

Normal$new(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)

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.



RaphaelS1/distr6 documentation built on Feb. 24, 2024, 9:14 p.m.