TMB Documentation  v1.9.11
R style probability distributions

Probability distributions (discrete and continuous) for use in the likelihood function. More...

## Files

file  dnorm.hpp
Univariate normal density.

## Functions

template<class Type >
Type dbeta (Type x, Type shape1, Type shape2, int give_log)
Probability density function of the beta distribution. More...

template<class Type >
Type dbinom (Type k, Type size, Type prob, int give_log=0)
Probability mass function of the binomial distribution. More...

template<class Type >
Type dbinom_robust (Type k, Type size, Type logit_p, int give_log=0)
Density of binomial distribution parameterized via logit(prob) More...

template<class T1 , class T2 , class T3 >
T1 dcompois (T1 x, T2 mode, T3 nu, int give_log=0)
Conway-Maxwell-Poisson. Calculate density. More...

template<class T1 , class T2 , class T3 >
T1 dcompois2 (T1 x, T2 mean, T3 nu, int give_log=0)
Conway-Maxwell-Poisson. Calculate density parameterized via the mean. More...

template<class Type >
Type df (Type x, Type df1, Type df2, int give_log)
Probability density function of the Fisher distribution. More...

template<class Type >
Type dgamma (Type y, Type shape, Type scale, int give_log=0)
Density of X where X~gamma distributed.

template<class Type >
Type dlgamma (Type y, Type shape, Type scale, int give_log=0)
Density of log(X) where X~gamma distributed.

template<class Type >
Type dlogis (Type x, Type location, Type scale, int give_log)
Probability density function of the logistic distribution. More...

template<class Type >
Type dmultinom (vector< Type > x, vector< Type > p, int give_log=0)
Probability mass function of the multinomial distribution. More...

template<class Type >
Type dnbinom (const Type &x, const Type &size, const Type &prob, int give_log=0)
Negative binomial probability function.Parameterized through size and prob parameters, following R-convention.

template<class Type >
Type dnbinom2 (const Type &x, const Type &mu, const Type &var, int give_log=0)
Negative binomial probability function.Alternative parameterization through mean and variance parameters.

template<class Type >
Type dnbinom_robust (const Type &x, const Type &log_mu, const Type &log_var_minus_mu, int give_log=0)
Negative binomial probability function. More...

template<class Type >
Type dnorm (Type x, Type mean, Type sd, int give_log=0)
Probability density function of the normal distribution. More...

template<class Type >
Type dpois (const Type &x, const Type &lambda, int give_log=0)
Poisson probability function.

template<class Type >
Type dsn (Type x, Type alpha, int give_log=0)
Probability density function of the skew-normal distribution. More...

template<class Type >
Type dt (Type x, Type df, int give_log)
Probability density function of the Student t-distribution. More...

template<class Type >
Type dtweedie (Type y, Type mu, Type phi, Type p, int give_log=0)
dtweedie function (same as dtweedie.series from R package 'tweedie'). More...

template<class Type >
Type dzinbinom (const Type &x, const Type &size, const Type &p, const Type &zip, int give_log=0)
Zero-Inflated negative binomial probability function. More...

template<class Type >
Type dzinbinom2 (const Type &x, const Type &mu, const Type &var, const Type &zip, int give_log=0)
Zero-Inflated negative binomial probability function. More...

template<class Type >
Type dzipois (const Type &x, const Type &lambda, const Type &zip, int give_log=0)
Zero-Inflated Poisson probability function. More...

template<class Type >
Type pbeta (Type q, Type shape1, Type shape2)
Distribution function of the beta distribution (following R argument convention). More...

template<class Type >
Type pgamma (Type q, Type shape, Type scale=1.)
Distribution function of the gamma distribution (following R argument convention).

template<class Type >
Type pnorm (Type q, Type mean=0., Type sd=1.)
Distribution function of the normal distribution (following R argument convention).

template<class Type >
Type ppois (Type q, Type lambda)
Distribution function of the poisson distribution (following R argument convention).

template<class Type >
Type qbeta (Type p, Type shape1, Type shape2)
Quantile function of the beta distribution (following R argument convention). More...

template<class Type >
Type qgamma (Type q, Type shape, Type scale=1.)
Quantile function of the gamma distribution (following R argument convention).

template<class Type >
Type qnorm (Type p, Type mean=0., Type sd=1.)
Quantile function of the normal distribution (following R argument convention).

## Exponential distribution.

Functions relative to the exponential distribution.

template<class Type >
Type pexp (Type x, Type rate)
Cumulative distribution function of the exponential distribution. More...

template<class Type >
Type dexp (Type x, Type rate, int give_log=0)
Probability density function of the exponential distribution. More...

template<class Type >
Type qexp (Type p, Type rate)
Inverse cumulative distribution function of the exponential distribution. More...

## Weibull distribution.

Functions relative to the Weibull distribution.

template<class Type >
Type pweibull (Type x, Type shape, Type scale)
Cumulative distribution function of the Weibull distribution. More...

template<class Type >
Type dweibull (Type x, Type shape, Type scale, int give_log=0)
Probability density function of the Weibull distribution. More...

template<class Type >
Type qweibull (Type p, Type shape, Type scale)
Inverse cumulative distribution function of the Weibull distribution. More...

## Sinh-asinh distribution.

Functions relative to the sinh-asinh distribution.

template<class Type >
Type dSHASHo (Type x, Type mu, Type sigma, Type nu, Type tau, int give_log=0)
Probability density function of the sinh-asinh distribution. More...

template<class Type >
Type pSHASHo (Type q, Type mu, Type sigma, Type nu, Type tau, int give_log=0)
Cumulative distribution function of the sinh-asinh distribution. More...

template<class Type >
Type qSHASHo (Type p, Type mu, Type sigma, Type nu, Type tau, int log_p=0)
Quantile function of the sinh-asinh distribution. More...

template<class Type >
Type norm2SHASHo (Type x, Type mu, Type sigma, Type nu, Type tau, int log_p=0)
Transforms a normal variable into a sinh-asinh variable. More...

## Detailed Description

Probability distributions (discrete and continuous) for use in the likelihood function.

## § dbeta()

template<class Type >
 Type dbeta ( Type x, Type shape1, Type shape2, int give_log )

Probability density function of the beta distribution.

Parameters
 shape1 First shape parameter. Must be strictly positive. shape2 Second shape parameter. Must be strictly positive. give_log true if one wants the log-probability, false otherwise.

Definition at line 227 of file distributions_R.hpp.

## § dbinom()

template<class Type >
 Type dbinom ( Type k, Type size, Type prob, int give_log = 0 )

Probability mass function of the binomial distribution.

Parameters
 k Number of successes. size Number of trials. prob Probability of success. give_log true if one wants the log-probability, false otherwise.

Definition at line 183 of file distributions_R.hpp.

## § dbinom_robust()

template<class Type >
 Type dbinom_robust ( Type k, Type size, Type logit_p, int give_log = 0 )

Density of binomial distribution parameterized via logit(prob)

This version should be preferred when working on the logit scale as it is numerically stable for probabilities close to 0 or 1.

Definition at line 205 of file distributions_R.hpp.

## § dcompois()

template<class T1 , class T2 , class T3 >
 T1 dcompois ( T1 x, T2 mode, T3 nu, int give_log = 0 )

Conway-Maxwell-Poisson. Calculate density.

$P(X=x) \propto \frac{\lambda^x}{(x!)^\nu}\:,x=0,1,\ldots$

Silently returns NaN if not within the valid parameter range:

$(0 \leq x) \land (0 < \lambda) \land (0 < \nu)$

.

Parameters
 x Observation mode Approximate mode $$\lambda^\frac{1}{\nu}$$ nu $$\nu$$
Examples:
compois.cpp.

Definition at line 627 of file distributions_R.hpp.

## § dcompois2()

template<class T1 , class T2 , class T3 >
 T1 dcompois2 ( T1 x, T2 mean, T3 nu, int give_log = 0 )

Conway-Maxwell-Poisson. Calculate density parameterized via the mean.

Silently returns NaN if not within the valid parameter range:

$(0 \leq x) \land (0 < E[X]) \land (0 < \nu)$

.

Parameters
 x Observation mean $$E[X]$$ nu $$\nu$$
Examples:
compois.cpp.

Definition at line 647 of file distributions_R.hpp.

## § dexp()

template<class Type >
 Type dexp ( Type x, Type rate, int give_log = 0 )

Probability density function of the exponential distribution.

Parameters
 rate Rate parameter. Must be strictly positive. give_log true if one wants the log-probability, false otherwise.

Definition at line 94 of file distributions_R.hpp.

## § df()

template<class Type >
 Type df ( Type x, Type df1, Type df2, int give_log )

Probability density function of the Fisher distribution.

Parameters
 df1 Degrees of freedom 1. df2 Degrees of freedom 2. give_log true if one wants the log-probability, false otherwise.

Definition at line 246 of file distributions_R.hpp.

## § dlogis()

template<class Type >
 Type dlogis ( Type x, Type location, Type scale, int give_log )

Probability density function of the logistic distribution.

Parameters
 location Location parameter. scale Scale parameter. Must be strictly positive. give_log true if one wants the log-probability, false otherwise.

Definition at line 263 of file distributions_R.hpp.

## § dmultinom()

template<class Type >
 Type dmultinom ( vector< Type > x, vector< Type > p, int give_log = 0 )

Probability mass function of the multinomial distribution.

Parameters
 x Vector of length K of integers. p Vector of length K, specifying the probability for the K classes (note, unlike in R these must sum to 1). give_log true if one wants the log-probability, false otherwise.

Definition at line 312 of file distributions_R.hpp.

## § dnbinom_robust()

template<class Type >
 Type dnbinom_robust ( const Type & x, const Type & log_mu, const Type & log_var_minus_mu, int give_log = 0 )
inline

Negative binomial probability function.

More robust parameterization through $$log(\mu)$$ and $$log(\sigma^2-\mu)$$ parameters.

Definition at line 103 of file lgamma.hpp.

## § dnorm()

template<class Type >
 Type dnorm ( Type x, Type mean, Type sd, int give_log = 0 )

Probability density function of the normal distribution.

Parameters
 x vector of observations mean mean of the normal distribution sd standard deviation of the normal distribution. must be strictly positive. give_log true if one wants the log-probability, false otherwise.
Examples:
adaptive_integration.cpp, fft.cpp, linreg.cpp, linreg_parallel.cpp, longlinreg.cpp, lr_test.cpp, mvrw.cpp, mvrw_sparse.cpp, register_atomic.cpp, register_atomic_parallel.cpp, sam.cpp, sde_linear.cpp, sdv_multi.cpp, socatt.cpp, thetalog.cpp, TMBad/sam.cpp, TMBad/thetalog.cpp, transform.cpp, transform2.cpp, transform_parallel.cpp, validation/MVRandomWalkValidation.cpp, validation/randomwalkvalidation.cpp, and validation/rickervalidation.cpp.

Definition at line 17 of file dnorm.hpp.

Referenced by density::ARk_t< scalartype_ >::operator()().

## § dSHASHo()

template<class Type >
 Type dSHASHo ( Type x, Type mu, Type sigma, Type nu, Type tau, int give_log = 0 )

Probability density function of the sinh-asinh distribution.

Parameters
 mu Location. sigma Scale. nu Skewness. tau Kurtosis. give_log true if one wants the log-probability, false otherwise.

Notation adopted from R package "gamlss.dist".

Probability density given in (2) in Jones and Pewsey (2009) Biometrika (2009) 96 (4): 761-780.

It is not possible to call this function with nu a vector or tau a vector.

Definition at line 339 of file distributions_R.hpp.

## § dsn()

template<class Type >
 Type dsn ( Type x, Type alpha, int give_log = 0 )

Probability density function of the skew-normal distribution.

Parameters
 alpha Slant parameter. give_log true if one wants the log-probability, false otherwise.

Definition at line 279 of file distributions_R.hpp.

## § dt()

template<class Type >
 Type dt ( Type x, Type df, int give_log )

Probability density function of the Student t-distribution.

Parameters
 df Degree of freedom. give_log true if one wants the log-probability, false otherwise.
Examples:
hmm.cpp, and sde_linear.cpp.

Definition at line 295 of file distributions_R.hpp.

## § dtweedie()

template<class Type >
 Type dtweedie ( Type y, Type mu, Type phi, Type p, int give_log = 0 )

dtweedie function (same as dtweedie.series from R package 'tweedie').

Silently returns NaN if not within the valid parameter range:

$(0 \leq y) \land (0 < \mu) \land (0 < \phi) \land (1 < p) \land (p < 2)$

.

This implementation can be used for both constant and variable y. However, note that the derivative wrt. y is hardcoded to return zero (!).

Note
Parameter order differs from the R version.
Warning
The derivative wrt. the y argument is disabled (zero). Hence the tweedie distribution can only be used for data (not random effects).
Examples:
tweedie.cpp.

Definition at line 554 of file distributions_R.hpp.

## § dweibull()

template<class Type >
 Type dweibull ( Type x, Type shape, Type scale, int give_log = 0 )

Probability density function of the Weibull distribution.

Parameters
 shape Shape parameter. Must be strictly positive. scale Scale parameter. Must be strictly positive. give_log true if one wants the log-probability, false otherwise.

Definition at line 145 of file distributions_R.hpp.

## § dzinbinom()

template<class Type >
 Type dzinbinom ( const Type & x, const Type & size, const Type & p, const Type & zip, int give_log = 0 )
inline

Zero-Inflated negative binomial probability function.

Parameterized through size and prob parameters, following R-convention. No vectorized version is currently available.

Parameters
 zip is the probaility of having extra zeros

Definition at line 175 of file lgamma.hpp.

## § dzinbinom2()

template<class Type >
 Type dzinbinom2 ( const Type & x, const Type & mu, const Type & var, const Type & zip, int give_log = 0 )
inline

Zero-Inflated negative binomial probability function.

Alternative parameterization through mean and variance parameters (conditional on not being an extra zero). No vectorized version is currently available.

Parameters
 zip is the probaility of having extra zeros

Definition at line 192 of file lgamma.hpp.

## § dzipois()

template<class Type >
 Type dzipois ( const Type & x, const Type & lambda, const Type & zip, int give_log = 0 )
inline

Zero-Inflated Poisson probability function.

Parameters
 zip is the probaility of having extra zeros

Definition at line 158 of file lgamma.hpp.

## § norm2SHASHo()

template<class Type >
 Type norm2SHASHo ( Type x, Type mu, Type sigma, Type nu, Type tau, int log_p = 0 )

Transforms a normal variable into a sinh-asinh variable.

Parameters
 mu Location parameter of the result sinh-asinh distribution. sigma Scale parameter of the result sinh-asinh distribution. nu Skewness parameter of the result sinh-asinh distribution. tau Kurtosis parameter of the result sinh-asinh distribution. log_p true if p is log-probability, false otherwise.

It is not possible to call this function with nu a vector or tau a vector.

Definition at line 417 of file distributions_R.hpp.

## § pbeta()

template<class Type >
 Type pbeta ( Type q, Type shape1, Type shape2 )

Distribution function of the beta distribution (following R argument convention).

Note
Non-centrality parameter (ncp) not implemented.

Definition at line 433 of file distributions_R.hpp.

## § pexp()

template<class Type >
 Type pexp ( Type x, Type rate )

Cumulative distribution function of the exponential distribution.

Parameters
 rate Rate parameter. Must be strictly positive.

Definition at line 80 of file distributions_R.hpp.

## § pSHASHo()

template<class Type >
 Type pSHASHo ( Type q, Type mu, Type sigma, Type nu, Type tau, int give_log = 0 )

Cumulative distribution function of the sinh-asinh distribution.

Parameters
 mu Location. sigma Scale. nu Skewness. tau Kurtosis. give_log true if one wants the log-probability, false otherwise.

Notation adopted from R package "gamlss.dist".

It is not possible to call this function with nu a vector or tau a vector.

Definition at line 368 of file distributions_R.hpp.

## § pweibull()

template<class Type >
 Type pweibull ( Type x, Type shape, Type scale )

Cumulative distribution function of the Weibull distribution.

Parameters
 shape Shape parameter. Must be strictly positive. scale Scale parameter. Must be strictly positive.

Definition at line 130 of file distributions_R.hpp.

## § qbeta()

template<class Type >
 Type qbeta ( Type p, Type shape1, Type shape2 )

Quantile function of the beta distribution (following R argument convention).

Note
Non-centrality parameter (ncp) not implemented.
Examples:
transform2.cpp.

Definition at line 450 of file distributions_R.hpp.

## § qexp()

template<class Type >
 Type qexp ( Type p, Type rate )

Inverse cumulative distribution function of the exponential distribution.

Parameters
 rate Rate parameter. Must be strictly positive.

Definition at line 110 of file distributions_R.hpp.

## § qSHASHo()

template<class Type >
 Type qSHASHo ( Type p, Type mu, Type sigma, Type nu, Type tau, int log_p = 0 )

Quantile function of the sinh-asinh distribution.

Parameters
 mu Location. sigma Scale. nu Skewness. tau Kurtosis. log_p true if p is log-probability, false otherwise.

Notation adopted from R package "gamlss.dist".

It is not possible to call this function with nu a vector or tau a vector.

Definition at line 396 of file distributions_R.hpp.

## § qweibull()

template<class Type >
 Type qweibull ( Type p, Type shape, Type scale )

Inverse cumulative distribution function of the Weibull distribution.

Parameters
 p Probability ; must be between 0 and 1. shape Shape parameter. Must be strictly positive. scale Scale parameter. Must be strictly positive.

Definition at line 163 of file distributions_R.hpp.