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.

Details

See the sections below for more information each of the functions.

List of all currently implemented distributions

Serialisation

Defining a distribution

In order to create a new distribution named xxx, you need to create three functions.

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.

See Also

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

[Package dynparam version 1.0.2 Index]