View source: R/loglik_niche_math_cpp.R
| loglik_niche_math_cpp | R Documentation |
Computes the negative log-likelihood of the multivariate normal niche model
restricted to the set of existing environments \mathbf{E}(t;G)
(Jimenez et al. 2019, Eq. 3–5). The density at an occurrence point is
normalised by the sum of the density over all background points in M:
loglik_niche_math_cpp(theta, env_occ, env_m, eta = 1, neg = TRUE, ...)
theta |
Numeric vector of unconstrained parameters (math scale):
|
env_occ |
Data frame or matrix ( |
env_m |
Data frame or matrix ( |
eta |
Numeric scalar, shape parameter for the LKJ C-vine prior on the correlation matrix (default 1 = uniform over correlations). |
neg |
Logical. If |
... |
Additional arguments (ignored; for compatibility). |
-\log\mathcal{L} =
\frac{1}{2}\sum_{i=1}^{n}
(\mathbf{x}_i - \mu)^\top \Sigma^{-1}(\mathbf{x}_i - \mu)
+ n \cdot \log\!\left(
\sum_{\mathbf{y} \in M}
\exp\!\left[-\frac{1}{2}
(\mathbf{y} - \mu)^\top \Sigma^{-1}(\mathbf{y} - \mu)
\right]
\right)
The |\Sigma|^{-1/2} factor cancels between numerator and denominator
(Eq. 3), so it does not appear in the objective. The logsumexp is computed
with the max-shift trick for numerical stability.
A scalar numeric value: the (negative) log-likelihood.
Jimenez, L., Soberon, J., Christen, J. A., & Soto, D. (2019). On the problem of modeling a fundamental niche from occurrence data. Ecological Modelling, 397, 109823.
[optimize_niche()] for multi-start fitting, [loglik_niche_math_presence_only()] for the unconstrained (no M) version.
theta <- start_theta(example_env_occ_2d)
ll <- loglik_niche_math_cpp(theta,
env_occ = example_env_occ_2d,
env_m = example_env_m_2d,
eta = 1, neg = TRUE
)
print(ll)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.