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 functiong(.)
, 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::
Ξ· = ΞΈ
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''(π)) = π