| 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
nameName of distribution
pdfProbability density/mass function of the distribution (e.g.
dnormfor normal distribution).rngRandom generator function of the distribution (e.g.
rnormfor normal distribution).cdfCumulative distribution function of the distribution (e.g.,
pnormfor normal distribution). This is used to compute pseudo-residuals.linkNamed list of link functions for distribution parameters
invlinkNamed list of inverse link functions for distribution parameters
nparNumber of parameters of the distribution
parnamesCharacter vector with name of each parameter
parapproxFunction that takes a sample and produces approximate values for the unknown parameters
fixedVector with element for each parameter which is TRUE if parameter is fixed
name_longLong 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_nparNumber of parameters
Method set_parnames()
Set parameter names
Usage
Dist$set_parnames(new_parnames)
Arguments
new_parnamesParameter names
Method set_code()
Set distribution code
Usage
Dist$set_code(new_code)
Arguments
new_codeDistribution 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
xValue at which the function should be evaluated
parVector 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.)
logLogical. 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
nNumber of realisations to generate
parVector 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
parList 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
wparVector of working parameters
as_matrixLogical. 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
deepWhether to make a deep clone.