ImplementationΒΆ

ExpFamΒΆ

struct ExpFamΒΆ

Exponential family of distributions.

We adopt the following representation::

f(y; ΞΈ, πœ™) = exp{(yΞΈ - b(ΞΈ))/a(πœ™) + c(y,πœ™)},

for which::

y     : random variable value.
ΞΈ     : canonical parameter.
πœ™     : nuisance parameter.
a(πœ™)  :
b(ΞΈ)  : log-partition function.
c(y,πœ™): normaliser.

The mean and variance are given by::

E[y]   = b'(ΞΈ)
Var[y] = b''(ΞΈ)a(πœ™)

In order to define a generalised linear mixed model (GLMM) we use the so-called natural parameter Ξ·. Given a link function g(.), the natural parameter relates to the canonical parameter as follows::

Ξ· = g(E[y]) = g(b'(ΞΈ)).

Every member of the exponential family has a canonical link function, which greatly simplifies the relationship::

Ξ· = ΞΈ

Public Members

double yΒΆ

Random variable value

double aΒΆ

a(πœ™)

double logaΒΆ

log(a(πœ™))

double cΒΆ

c(y,πœ™)

log_partition *lpΒΆ

b(ΞΈ)

log_partition_fderivative *lpfdΒΆ

log(b'(ΞΈ))

log_partition_derivatives *lpdΒΆ

log(b''(ΞΈ))

LikelihoodΒΆ

We assume the canonical link function for every likelihood.

BernoulliΒΆ

y assumes 1 or 0 for failure. We make use of the Binomial implementation. So, please, refer to the next section for details.

static double bernoulli_log_partition(const double theta)ΒΆ

Bernoulli log-partition function.

Please, refer to the binomial_log_partition() function.

static double bernoulli_log_partition_fderivative(const double theta)ΒΆ

First derivative of the Bernoulli log-partition function.

Please, refer to the binomial_log_partition_fderivative() function.

static void bernoulli_log_partition_derivatives(const double theta, double *b0, double *logb1, double *logb2)ΒΆ

Zeroth, first, and second derivatives of the Bernoulli log-partition function.

Please, refer to the bernoulli_log_partition_fderivative() function.

BinomialΒΆ

The random variable is given by y = k/n. The support is therefore y Ο΅ {0/n, 1/n, ..., r/n}. The exponential family functions are:

πœ™      = n
a(πœ™)   = 1/πœ™
b(ΞΈ)   = log(1 + exp(ΞΈ))
c(y,πœ™) = log(binom(n, yπœ™))

Let us define:

πœ‡ = E[y] = p.

The canonical link function and its inverse are given by:

canonical(πœ‡)     = log(πœ‡/(1+πœ‡)) = Ξ·
canonical_inv(Ξ·) = 1/(1 + exp(-Ξ·))
double binomial_log_partition(const double theta)ΒΆ

Binomial log-partition function.

Definition:

b(πœƒ) = log(1 + exp(πœƒ)).

double binomial_log_partition_fderivative(const double theta)ΒΆ

First derivative of the Binomial log-partition function.

Definition:

log(b'(πœƒ)) = πœƒ - log(1 + exp(πœƒ))

void binomial_log_partition_derivatives(const double theta, double *b0, double *logb1, double *logb2)ΒΆ

Zeroth, first, and second derivatives of the Binomial log-partition function.

Implements b(πœƒ), log(b'(πœƒ)), and:

log(b''(πœƒ)) = πœƒ - 2log(1 + exp(πœƒ))

Negative BinomialΒΆ

The random variable is given by y = k/r. The support is therefore y Ο΅ {0/r, 1/r, ..., r/r}. The exponential family functions are:

πœ™ = r
a(πœ™) = 1/πœ™
b(ΞΈ) = -log(1 - exp(ΞΈ))
c(y,πœ™) = log(binom(yπœ™ + πœ™ - 1, yπœ™))

Let us define:

πœ‡ = E[y] = p / (1 - p)

The canonical link function and its inverse are given by:

canonical(πœ‡)     = log(πœ‡ / (1 + πœ‡)) = Ξ·
canonical_inv(Ξ·) = exp(Ξ·) / (1 - exp(Ξ·))
double nbinomial_log_partition(const double theta)ΒΆ

Negative binomial log-partition function.

Definition:

b(πœƒ) = -log(1 - exp(πœƒ)).

double nbinomial_log_partition_fderivative(const double theta)ΒΆ

First derivative of the Negative Binomial log-partition function.

Definition:

log(b'(πœƒ)) = πœƒ - log(1 - exp(πœƒ)).

void nbinomial_log_partition_derivatives(const double theta, double *b0, double *logb1, double *logb2)ΒΆ

Zeroth, first, and second derivatives of the Negative Binomial log-partition func.

Implements b(πœƒ), log(b'(πœƒ)), and:

log(b''(πœƒ)) = πœƒ - 2log(1 - exp(πœƒ))

PoissonΒΆ

The support is y Ο΅ {0, 1, ...}. The exponential family functions are:

πœ™      = 1
a(πœ™)   = πœ™
b(πœƒ)   = exp(πœƒ)
b'(πœƒ)  = exp(πœƒ)
b'(πœƒ)  = exp(πœƒ)
c(y,πœ™) = -log(y!)

Let us define:

πœ‡ = E[y] = Ξ»,

for which Ξ» is the Poisson distribution parameter. The canonical link function and its inverse are given by:

canonical(πœ‡)     = log(πœ‡ / (1 + πœ‡)) = Ξ·
canonical_inv(Ξ·) = exp(Ξ·) / (1 - exp(Ξ·))
double poisson_log_partition(const double theta)ΒΆ

Poisson log-partition function.

Definition:

b(πœƒ) = exp(πœƒ)

double poisson_log_partition_fderivative(const double theta)ΒΆ

Log of the first derivative of the Poisson log-partition function.

Definition:

log(b'(πœƒ)) = πœƒ

void poisson_log_partition_derivatives(const double theta, double *b0, double *logb1, double *logb2)ΒΆ

Log of the derivatives of the Poisson log-partition function.

Implements b(πœƒ), log(b'(πœƒ)), and:

log(b''(πœƒ)) = πœƒ