Description Usage Arguments Details List of all currently implemented distributions Serialisation Defining a distribution See Also Examples
Distributions are used to define the domain of an
integer_parameter()
or a numeric_parameter()
.
1 2 3 4 5 6 7 8 9 10 11 12 | distribution(lower, upper, ...)
distribution_function(dist)
quantile_function(dist)
## S3 method for class 'distribution'
as.list(x, ...)
as_distribution(li)
is_distribution(x)
|
lower |
Lower limit of the distribution. |
upper |
Upper limit of the distribution. |
... |
Fields to be saved in the distribution. |
dist |
A distribution object. |
x |
An object which might be a distribution. |
li |
A list to be converted into a distribution. |
See the sections below for more information each of the functions.
expuniform_distribution()
normal_distribution()
uniform_distribution()
as.list(dist)
: Converting a distribution to a list.
as_distribution(li)
: Converting a list back to a distribution.
is_distribution(x)
: Checking whether something is a distribution.
In order to create a new distribution named xxx
, you need to create three functions.
A xxx()
function that calls distribution(...) %>% add_class("xxx")
at the end.
quantile_function.xxx()
: The quantile function for converting between a uniform distribution and the xxx
distribution.
distribution_function.xxx()
: The distribution function for converting between a uniform distribution and the xxx
distribution.
Check the implementations of normal_distribution()
, quantile_function.normal_distribution()
and distribution_function.normal_distribution()
for an example
on how to do define these functions. Alternatively, check the examples below.
dynparam for an overview of all dynparam functionality.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | di <- uniform_distribution(lower = 1, upper = 10)
print(di)
li <- as.list(di)
di2 <- as_distribution(li)
print(di2)
# Defining a custom distribution, using the pbeta and qbeta functions
beta_distribution <- function(
shape1,
shape2,
ncp,
lower = -Inf,
upper = Inf
) {
di <- distribution(lower = lower, upper = upper, shape1, shape2, ncp)
add_class(di, beta_distribution)
}
distribution_function.beta_distribution <- function(dist) {
function(q) {
stats::pbeta(q, shape1 = dist$shape1, shape2 = dist$shape2, ncp = dist$ncp)
}
}
quantile_function.beta_distribution <- function(dist) {
function(p) {
stats::qbeta(p, shape1 = dist$shape1, shape2 = dist$shape2, ncp = dist$ncp)
}
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.