make_distribution: Make an 'distribution' from a gamlss distribution

Description Usage Arguments Value Examples

Description

Make an distribution from a gamlss distribution

Usage

1
make_distribution(family_function, ...)

Arguments

family_function

Either a character vector containing the name of a function that produces a gamlss.family (e.g. family_function = "NO" for the normal distribution), or a user-created function that returns an object with the same structure. [[Add explanation of how to do this: see dEXAMPLE in test-distributions.R]] gamlss.family.

...

Additional arguments, possibly including bd (binomial denominator), sigma (scale), nu (shape), or tau (shape), depending on the distribution. These must be named, and partial matching is not allowed.

Value

An distribution object, consisting of the following functions:

Examples

 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)

davharris/mistnet2 documentation built on May 14, 2019, 9:28 p.m.