Skip to contents

1 Ecological Motivation

The fundamental ecological niche of a species (sensu Hutchinson 1957) is the set of environmental conditions under which the species can maintain a viable population. When the niche is modelled as a multivariate normal density f(𝐱;μ,Σ)f(\mathbf{x};\mu,\Sigma) in pp-dimensional environmental space, the problem reduces to estimating the centroid μ\mu and the shape/orientation matrix Σ\Sigma from observed presence records.

The presence-only model is the simplest formulation: it treats the occurrence records {𝐱1,…,𝐱n}\{\mathbf{x}_1,\dots,\mathbf{x}_n\} as an i.i.d. sample from the normal density and estimates (μ,Σ)(\mu,\Sigma) by maximum likelihood.

2 Mathematical Specification

2.1 Density

The multivariate normal density in pp dimensions is

f(𝐱;μ,Σ)=(2π)−p/2|Σ|−1/2exp⁡[−12(𝐱−μ)⊤Σ−1(𝐱−μ)]. f(\mathbf{x};\mu,\Sigma) = (2\pi)^{-p/2}\,|\Sigma|^{-1/2}\, \exp\!\left[-\tfrac{1}{2} (\mathbf{x}-\mu)^\top\Sigma^{-1}(\mathbf{x}-\mu)\right]. \tag{1}

This is Equation 2 of Jimenez et al. (2019), written for a single observation.

2.2 Log-Likelihood

Given nn presence records, the log-likelihood is

$$ \ell(\mu,\Sigma) = -\frac{n}{2}\log|\Sigma| -\frac{1}{2}\sum_{i=1}^{n} (\mathbf{x}_i-\mu)^\top\Sigma^{-1}(\mathbf{x}_i-\mu) + \text{const.} \tag{2} $$

The constant −np2log⁡(2π)-\frac{np}{2}\log(2\pi) does not depend on (μ,Σ)(\mu,\Sigma) and is dropped in the implementation because it does not affect the optimum.

2.3 Negative Log-Likelihood (Minimised Objective)

The optimizer minimises the negative log-likelihood:

−ℓ(μ,Σ)=n2log⁡|Σ|+12∑i=1nqi,qi=∥L−1(𝐱i−μ)∥2, -\ell(\mu,\Sigma) = \frac{n}{2}\log|\Sigma| + \frac{1}{2}\sum_{i=1}^{n} q_i, \qquad q_i = \|L^{-1}(\mathbf{x}_i-\mu)\|^2, \tag{3}

where Σ=LL⊤\Sigma = LL^\top (Cholesky factorisation) and qiq_i is the squared Mahalanobis distance.

3 Parameterisation

3.1 Theta Layout

The unconstrained parameter vector θ\theta has length 2p+p(p−1)/22p + p(p-1)/2:

θ=[μ1,…,μp⏟p,log⁡σ1,…,log⁡σp⏟p,v1,…,vp(p−1)/2⏟C-vine]. \theta = \bigl[\underbrace{\mu_1,\dots,\mu_p}_{p},\; \underbrace{\log\sigma_1,\dots,\log\sigma_p}_{p},\; \underbrace{v_1,\dots,v_{p(p-1)/2}}_{\text{C-vine}}\bigr].

Block Length Constraint Meaning
μ\mu pp Unconstrained Niche centroid
log⁡σ\log\sigma pp σk>0\sigma_k > 0 via exp\exp Marginal standard deviations
vv p(p−1)/2p(p-1)/2 Unconstrained C-vine partial correlations

3.2 Covariance Reconstruction

The covariance matrix is reconstructed as Σ=LcovLcov⊤\Sigma = L_{\text{cov}}\,L_{\text{cov}}^\top, where

Lcov=diag⁡(σ)⋅Lcorr, L_{\text{cov}} = \operatorname{diag}(\sigma)\;\cdot\;L_{\text{corr}},

and LcorrL_{\text{corr}} is the lower-triangular Cholesky factor of the correlation matrix RR, built from the C-vine parameterisation of Lewandowski, Kurowicka & Joe (2009). The LKJ prior with shape η\eta penalises extreme correlations when η>1\eta > 1.

4 Implementation Call Chain

optimize_niche(likelihood = "presence_only")
  └─ niche_obj.cpp::create_niche_obj_ptr()
       └─ loglik_niche_math_presence_only_eigen()    [C++, lines 65–95]
            ├─ build_L_cov()                          [theta → mu, sigma, L_cov]
            ├─ L_cov.triangularView.solve(diff)       [Mahalanobis via forward solve]
            └─ 0.5 * n * log_det + 0.5 * sum_q       [Eq. 3]

4.1 Key Code (loglik_niche_math_cpp.cpp, lines 65–95)

The C++ kernel:

  1. Reconstructs LcovL_{\text{cov}} from θ\theta via build_L_cov() (lines 40–59).
  2. Computes Y=Lcov−1(X−μ)Y = L_{\text{cov}}^{-1}(X - \mu) by triangular forward solve (line 84).
  3. Sums squared column norms ∑i∥yi∥2\sum_i \|y_i\|^2 (line 85).
  4. Computes log⁡|Σ|=2∑klog⁡Lcov(k,k)\log|\Sigma| = 2\sum_k \log L_{\text{cov}}(k,k) (lines 87–89).
  5. Returns 0.5 * n * log_det + 0.5 * sum_q (line 92), guarded by OPTIM_PENALTY for NaN/Inf (line 93).

4.2 R Entry Point

loglik_niche_math_presence_only(theta, env_occ, eta = 1, neg = TRUE)

This function reconstructs LcovL_{\text{cov}} via cvine_cholesky() in R, then calls loglik_niche_presence_only_cpp() (the Rcpp-exported wrapper).

5 Analytical Properties

Property Value
MLE for μ\mu Sample mean 𝐱‾\bar{\mathbf{x}}
MLE for Σ\Sigma Sample covariance 1n∑i(𝐱i−𝐱‾)(𝐱i−𝐱‾)⊤\frac{1}{n}\sum_i(\mathbf{x}_i-\bar{\mathbf{x}})(\mathbf{x}_i-\bar{\mathbf{x}})^\top
Likelihood shape Unimodal (convex negative log-likelihood)
Identifiability Full: μ\mu and Σ\Sigma are both identifiable
Background data Not used
Dropped constants (2π)−np/2(2\pi)^{-np/2} — does not affect θ̂\hat\theta

6 When To Use

  • Sanity check: The MLE has a closed form, so numerical results should match the sample mean and covariance exactly (up to optimiser tolerance).
  • Warm start: optimize_niche(warm_start = TRUE) uses the presence-only MLE as the initial point for the more complex weighted models.
  • No background available: When the accessible area MM is unknown or the background sample is unreliable.

7 Limitations

  1. Ignores environmental availability. The estimate reflects the observed distribution of presences, which is confounded by the distribution of environments in MM. If MM over-represents certain environments, μ̂\hat\mu will be biased toward those environments.

  2. No background correction. Unlike the "weighted" and "ip_weighted" models, no KDE of g(𝐱)g(\mathbf{x}) is used. The resulting niche estimate is the realised niche (or a biased estimate of it), not the fundamental niche.

  3. Normality assumption. The niche is assumed to be ellipsoidal. For species with multi-modal or strongly skewed niches, consider "skew_normal" or "skew_t".

References

Jimenez, L., J. Soberón, J. A. Christen, and D. Soto. 2019. “On the Problem of Modeling a Fundamental Niche from Occurrence Data.” Ecological Modelling 397: 74–83. https://doi.org/10.1016/j.ecolmodel.2019.01.020.