Dist {hmmTMB} | R 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
Method new()
Create a Dist object
Usage
Dist$new( name, pdf, rng, cdf = NULL, link, invlink, npar, parnames, parapprox = NULL, fixed = NULL, name_long = name )
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.
Returns
A new Dist object
Method name()
Return name of Dist object
Usage
Dist$name()
Method pdf()
Return pdf of Dist object
Usage
Dist$pdf()
Method cdf()
Return cdf of Dist object
Usage
Dist$cdf()
Method rng()
Return random generator function of Dist object
Usage
Dist$rng()
Method link()
Return link function of Dist object
Usage
Dist$link()
Method invlink()
Return inverse link function of Dist object
Usage
Dist$invlink()
Method npar()
Return number of parameters of Dist object
Usage
Dist$npar()
Method parnames()
Return names of parameters
Usage
Dist$parnames()
Method parapprox()
Return function that approximates parameters
Usage
Dist$parapprox()
Method fixed()
Return which parameters are fixed
Usage
Dist$fixed()
Method code()
Return code of Dist object
Usage
Dist$code()
Method name_long()
Human-readable name of Dist object
Usage
Dist$name_long()
Method set_npar()
Set number of parameters this distribution has
Usage
Dist$set_npar(new_npar)
Arguments
new_npar
Number of parameters
Method set_parnames()
Set parameter names
Usage
Dist$set_parnames(new_parnames)
Arguments
new_parnames
Parameter names
Method set_code()
Set distribution code
Usage
Dist$set_code(new_code)
Arguments
new_code
Distribution code
Method 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
Method 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
Method 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
Method 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
Method clone()
The objects of this class are cloneable with this method.
Usage
Dist$clone(deep = FALSE)
Arguments
deep
Whether to make a deep clone.