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

In our previous tutorial we constructed a Normal distribution with a variety of parameterisations. Now we will look at how to access the parameters of the distribution and how to update them. Parameters are handled by param6, full documentation can be found at the package website.

Accessing Parameters

First we will construct the Standard Normal distribution, the default parameterisation

N <- Normal$new()

To view all parameters in the distribution we use the parameters method

N$parameters()

Notice how not only the parameters in the given parameterisation are displayed, but all the ones possible. Individual values can be obtained with getParameterValue, which is a wrapper around get_values.

N$getParameterValue("prec")

Updating Parameters

Any parameter can be updated in distr6 using the setParameterValue method and all others are updated accordingly. For example,

N$setParameterValue(var = 2)
N$parameters()

Not only has the variance been updated, but so too have the precision and standard deviation parameters. But be careful not to set conflicting parameterisations.

The wrong way:

N$setParameterValue(prec = 2)

The right way:

N$setParameterValue(prec = 2, var = NULL)

Internal checks ensure that only valid parameter values are allowed, for example setting the precision to a negative number will throw an error.

N$setParameterValue(prec = -1)

Finally, multiple parameters can be updated at the same time

N$setParameterValue(mean = 4, prec = 2)
N$parameters()

Summary

In this tutorial we looked at getting and setting parameters for the Normal distribution. In the next tutorial we look at accessing mathematical and statistical methods including the d/p/q/r functions.



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