Description Usage Arguments Value Examples
Make an distribution
from a gamlss distribution
1 | make_distribution(family_function, ...)
|
family_function |
Either a character vector containing the name of a
function that produces a |
... |
Additional arguments, possibly including |
An distribution
object, consisting of the following
functions:
log_prob(x, mu)
: log probability of the distribution with
location parameter mu
evaluated at x
.
sample(n, mu)
: draw n
random samples from the distribution
with location parameter mu
.
Functions for calculating partial derivatives evaluated at x
with regard to mu (dldm
), sigma (dldd
), nu
(dldv
), and tau (dldt
). For a few distributions,
dldx
is also defined: these distributions can be used as
prior distributions on the model's weights. Users can add dldx
functions by creating their own distributions that include a function
called dldx
.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | distribution = make_distribution("NO", sigma = 1/3)
# Sample 10 random values with mean=2 (and sigma=1/3 as defined above)
samples = draw_samples(distribution, n = 10, mu = 2)
# find the log_prob of those samples under a distribution with mean=1
log_prob(distribution, x = samples, mu = 1)
# The gradient of the log_prob with respect to the mean indicates that
# the log_prob would be higher if mu were larger (more positive)
grad(distribution, "mu", y = samples, mu = 1)
# The gradient with respect to x shows that the log_prob would also be
# higher if we reduced the values of x (more negative)
grad(distribution, "x", x = samples, mu = 1)
# The gradient with respect to x isn't defined for all distributions,
# however. For example, this code would return an error that
# " gradient with respect to x (dldx) is not defined for the distribution PO"
## Not run:
another_distribution = make_distribution("PO")
another_distribution$dldx(x = 1:10, mu = 1)
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.