distribution {dynparam} R Documentation

## Defining, serialising and printing distributions

### Description

Distributions are used to define the domain of an integer_parameter() or a numeric_parameter().

### Usage

distribution(lower, upper, ...)

distribution_function(dist)

quantile_function(dist)

## S3 method for class 'distribution'
as.list(x, ...)

as_distribution(li)

is_distribution(x)


### Arguments

 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.

### List of all currently implemented distributions

• expuniform_distribution()

• normal_distribution()

• uniform_distribution()

### Serialisation

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

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

### Examples

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)
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)