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.

## 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()
#>      id value support                                 description
#> 1: mean     0       ℝ                   Mean - Location Parameter
#> 2:  var     1      ℝ+          Variance - Squared Scale Parameter
#> 3:   sd     1      ℝ+        Standard Deviation - Scale Parameter
#> 4: prec     1      ℝ+ Precision - Inverse Squared Scale Parameter

Notice how not only the parameters in the given parameterisation are displayed, but all the ones possible. To filter this table for a specific parameter, add the parameter name as an argument

N$parameters("var") #> id value support settable description updateFunc #> 1: var 1 <PosReals> TRUE Variance - Squared Scale Parameter NA Or to only see the value of the parameter N$getParameterValue("prec")
#> [1] 1

## 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()
#>      id    value support                                 description
#> 1: mean 0.000000       ℝ                   Mean - Location Parameter
#> 2:  var 2.000000      ℝ+          Variance - Squared Scale Parameter
#> 3:   sd 1.414214      ℝ+        Standard Deviation - Scale Parameter
#> 4: prec 0.500000      ℝ+ Precision - Inverse Squared Scale Parameter

Not only has the variance been updated, but so too have the precision and standard deviation parameters. To see the function used for updating you can run N$parameters("prec", update = TRUE) but the output is given in a form that your computer can read, so it may not be straightforward to follow for more complicated functions. See the distribution help page, ?Normal for a more readable version. Internal checks ensure that only valid parameter values are allowed, for example setting the variance to a negative number will throw an error. Finally, multiple parameters can be updated at the same time N$setParameterValue(mean = 4, sd = 2)
N$parameters() #> id value support description #> 1: mean 4.00 ℝ Mean - Location Parameter #> 2: var 4.00 ℝ+ Variance - Squared Scale Parameter #> 3: sd 2.00 ℝ+ Standard Deviation - Scale Parameter #> 4: prec 0.25 ℝ+ Precision - Inverse Squared Scale Parameter But be careful not to try and update conflicting parameters, for example trying to update the variance and precision in the Normal distribution will lead to the variance argument being ignored: N$setParameterValue(var = 2, prec = 3)
N\$parameters()
#>      id     value support                                 description
#> 1: mean 4.0000000       ℝ                   Mean - Location Parameter
#> 2:  var 0.3333333      ℝ+          Variance - Squared Scale Parameter
#> 3:   sd 0.5773503      ℝ+        Standard Deviation - Scale Parameter
#> 4: prec 3.0000000      ℝ+ Precision - Inverse Squared Scale Parameter

## 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.