Dist: R6 class for probability distribution

DistR Documentation

R6 class for probability distribution

Description

Contains the probability density/mass function, and the link and inverse link functions for a probability distribution.

Methods

Public methods


Dist$new()

Create a Dist object

Usage
Dist$new(
  name,
  pdf,
  rng,
  cdf = NULL,
  link,
  invlink,
  npar,
  parnames,
  parapprox = NULL,
  fixed = NULL,
  name_long = name,
  par_alt = NULL
)
Arguments
name

Name of distribution

pdf

Probability density/mass function of the distribution (e.g. dnorm for normal distribution).

rng

Random generator function of the distribution (e.g. rnorm for normal distribution).

cdf

Cumulative distribution function of the distribution (e.g., pnorm for normal distribution). This is used to compute pseudo-residuals.

link

Named list of link functions for distribution parameters

invlink

Named list of inverse link functions for distribution parameters

npar

Number of parameters of the distribution

parnames

Character vector with name of each parameter

parapprox

Function that takes a sample and produces approximate values for the unknown parameters

fixed

Vector with element for each parameter which is TRUE if parameter is fixed

name_long

Long version of the name of the distribution, possibly more user-readable than name.

par_alt

Function that takes a vector of the distribution parameters as input and returns them in a different format. Only relevant for some distributions (e.g., MVN, where the SDs and correlations can be reformatted into a covariance matrix)

Returns

A new Dist object


Dist$name()

Return name of Dist object

Usage
Dist$name()

Dist$pdf()

Return pdf of Dist object

Usage
Dist$pdf()

Dist$cdf()

Return cdf of Dist object

Usage
Dist$cdf()

Dist$rng()

Return random generator function of Dist object

Usage
Dist$rng()

Dist$link()

Return link function of Dist object

Usage
Dist$link()

Dist$invlink()

Return inverse link function of Dist object

Usage
Dist$invlink()

Dist$npar()

Return number of parameters of Dist object

Usage
Dist$npar()

Dist$parnames()

Return names of parameters

Usage
Dist$parnames()

Dist$parapprox()

Return function that approximates parameters

Usage
Dist$parapprox()

Dist$fixed()

Return which parameters are fixed

Usage
Dist$fixed()

Dist$code()

Return code of Dist object

Usage
Dist$code()

Dist$name_long()

Human-readable name of Dist object

Usage
Dist$name_long()

Dist$set_npar()

Set number of parameters this distribution has

Usage
Dist$set_npar(new_npar)
Arguments
new_npar

Number of parameters


Dist$set_parnames()

Set parameter names

Usage
Dist$set_parnames(new_parnames)
Arguments
new_parnames

Parameter names


Dist$set_code()

Set distribution code

Usage
Dist$set_code(new_code)
Arguments
new_code

Distribution code


Dist$pdf_apply()

Evaluate probability density/mass function

This method is used in the Dist$obs_probs() method. It is a wrapper around Dist$pdf(), which prepares the parameters and passes them to the function.

Usage
Dist$pdf_apply(x, par, log = FALSE)
Arguments
x

Value at which the function should be evaluated

par

Vector of parameters. The entries should be named if they are not in the same order as expected by the R function. (E.g. shape/scale rather than shape/rate for gamma distribution.)

log

Logical. If TRUE, the log-density is returned. Default: FALSE.

Returns

Probability density/mass function evaluated at x for parameters par


Dist$rng_apply()

Random number generator

This method is a wrapper around Dist$rng(), which prepares the parameters and passes them to the function.

Usage
Dist$rng_apply(n, par)
Arguments
n

Number of realisations to generate

par

Vector of parameters. The entries should be named if they are not in the same order as expected by the R function. (E.g. shape/scale rather than shape/rate for gamma distribution.)

Returns

Vector of n realisations of this distribution


Dist$par_alt()

Alternative parameter formatting

Usage
Dist$par_alt(par)
Arguments
par

Vector of distribution parameters

Returns

Formatted parameters


Dist$n2w()

Natural to working parameter transformation

This method transforms parameters from the natural scale (i.e., their domain of definition) to the "working" or "linear predictor" scale (i.e., the real line). It is a wrapper for Dist$link().

Usage
Dist$n2w(par)
Arguments
par

List of parameters

Returns

Vector of parameters on the working scale


Dist$w2n()

Working to natural parameter transformation

This method transforms parameters from the "working" or "linear predictor" scale (i.e., the real line) to the natural scale (i.e., their domain of definition). It is a wrapper for Dist$invlink().

Usage
Dist$w2n(wpar, as_matrix = FALSE)
Arguments
wpar

Vector of working parameters

as_matrix

Logical. If TRUE, the natural parameters are returned as a matrix with one row for each state and one column for each parameter. If FALSE, the natural parameters are returned as a list (default).

Returns

List or matrix of parameters on natural scale


Dist$clone()

The objects of this class are cloneable with this method.

Usage
Dist$clone(deep = FALSE)
Arguments
deep

Whether to make a deep clone.


hmmTMB documentation built on Nov. 10, 2026, 5:09 p.m.