Skip to contents

1 Ecological Motivation

The presence-only model (Model 1) ignores the distribution of environments in the accessible area MM. When some environments are more common than others, the uncorrected MLE is biased toward those common environments.

The weighted-normal model corrects for this by incorporating a kernel density estimate (KDE) gΜ‚(𝐱)\hat{g}(\mathbf{x}) of the environmental density in MM. The weight function w(𝐱)=gΜ‚(𝐱)w(\mathbf{x}) = \hat{g}(\mathbf{x}) enters both the numerator and denominator of the restricted likelihood, modelling an observation process where the probability of recording a presence at 𝐱\mathbf{x} is proportional to the product of the species’ suitability f(𝐱)f(\mathbf{x}) and the environmental availability g(𝐱)g(\mathbf{x}).

This is the default model in xnicher and implements Equation 5 (or equivalently Equation 8 with w=gΜ‚w = \hat{g}) of Jimenez and SoberΓ³n (2022).

2 Data-Generating Process

The weighted model assumes the use-availability DGP:

p(𝐱i∣presence in M)=f(𝐱i;ΞΌ,Ξ£)gΜ‚(𝐱i)∫Mf(𝐱;ΞΌ,Ξ£)gΜ‚(𝐱)d𝐱. p(\mathbf{x}_i \mid \text{presence in } M) = \frac{f(\mathbf{x}_i;\mu,\Sigma)\;\hat{g}(\mathbf{x}_i)} {\int_M f(\mathbf{x};\mu,\Sigma)\;\hat{g}(\mathbf{x})\,d\mathbf{x}}. \tag{1}

This assumes that the intensity of presence records at environment 𝐱\mathbf{x} is proportional to both the species’ fundamental niche density ff and the environmental density gg in MM. This is appropriate when:

  • Observation probability correlates with environmental density (e.g. opportunistic citizen-science records where more observers visit common habitats).
  • The analyst wants to model the realised niche as shaped by both intrinsic tolerances and environmental availability.

3 Mathematical Specification

3.1 Restricted Log-Likelihood (Paper Eq. 5)

β„“(ΞΌ,Ξ£)=βˆ‘i=1nlog⁑f(𝐱i)+βˆ‘i=1nlog⁑gΜ‚(𝐱i)βˆ’nlogβ‘βˆ‘j=1KgΜ‚(𝐲j)f(𝐲j), \ell(\mu,\Sigma) = \sum_{i=1}^{n}\log f(\mathbf{x}_i) + \sum_{i=1}^{n}\log \hat{g}(\mathbf{x}_i) - n\,\log\!\sum_{j=1}^{K}\hat{g}(\mathbf{y}_j)\,f(\mathbf{y}_j), \tag{2}

where {𝐲j}j=1K\{\mathbf{y}_j\}_{j=1}^K are background points sampled from MM.

3.2 Negative Log-Likelihood (Minimised Objective)

Dropping the log⁑f\log f normalisation constant (2Ο€)βˆ’p/2|Ξ£|βˆ’1/2(2\pi)^{-p/2}|\Sigma|^{-1/2} from the denominator (it cancels between numerator and denominator up to a factor that does not affect the optimum), the minimised objective is:

βˆ’β„“*(ΞΈ)=12βˆ‘i=1nqiβˆ’βˆ‘i=1nlog⁑gΜ‚(𝐱i)+nβ‹…logsumexp⁑j[loggΜ‚(𝐲j)βˆ’12qj]+Ξ»βˆ‘k=1p(log⁑σkβˆ’ck)2, -\ell^*(\theta) = \frac{1}{2}\sum_{i=1}^{n} q_i - \sum_{i=1}^{n}\log\hat{g}(\mathbf{x}_i) + n\cdot\operatorname{logsumexp}_j\!\left[ \log\hat{g}(\mathbf{y}_j) - \tfrac{1}{2}q_j \right] + \lambda\sum_{k=1}^{p}(\log\sigma_k - c_k)^2, \tag{3}

where:

  • qi=βˆ₯Lβˆ’1(𝐱iβˆ’ΞΌ)βˆ₯2q_i = \|L^{-1}(\mathbf{x}_i - \mu)\|^2 is the squared Mahalanobis distance at presence point ii,
  • qj=βˆ₯Lβˆ’1(𝐲jβˆ’ΞΌ)βˆ₯2q_j = \|L^{-1}(\mathbf{y}_j - \mu)\|^2 at background point jj,
  • gΜ‚(β‹…)\hat{g}(\cdot) is the Gaussian KDE of the background evaluated at the point,
  • ck=log⁑σ̂k(env_occ)c_k = \log\hat\sigma_k(\text{env\_occ}) centres the ridge prior at the sample standard deviation of each variable,
  • Ξ»\lambda controls the ridge strength (default 1.0; set to 0 for pure paper Eq. 5).

3.3 The Ridge Prior

The pure MLE of the weighted-normal model is susceptible to the Patil & Ord (1976) drift: as Οƒkβ†’βˆž\sigma_k \to \infty, the numerator density f(𝐱i)f(\mathbf{x}_i) flattens, the denominator approaches βˆ‘jgΜ‚(𝐲j)\sum_j \hat{g}(\mathbf{y}_j) (a constant), and the likelihood increases without bound.

The ridge term Ξ»βˆ‘k(log⁑σkβˆ’ck)2\lambda\sum_k(\log\sigma_k - c_k)^2 is a weakly informative prior that penalises log-standard-deviations far from the empirical scale, preventing this drift while having negligible influence near the optimum. Users can set Ξ»=0\lambda = 0 to recover the exact paper formula, but this is not recommended for multimodal MM.

3.4 Sign Convention (vs.Β ip_weighted)

Note the signs on the KDE terms:

Term "weighted" (this model) "ip_weighted" (Model 3)
Denominator integrand +log⁑gΜ‚(𝐲j)βˆ’12qj+\log\hat{g}(\mathbf{y}_j) - \frac{1}{2}q_j βˆ’12qjβˆ’log⁑gΜ‚(𝐲j)-\frac{1}{2}q_j - \log\hat{g}(\mathbf{y}_j)
Numerator KDE βˆ’βˆ‘ilog⁑gΜ‚(𝐱i)-\sum_i\log\hat{g}(\mathbf{x}_i) +βˆ‘ilog⁑gΜ‚(𝐱i)+\sum_i\log\hat{g}(\mathbf{x}_i)

These sign differences correspond to w=gΜ‚w = \hat{g} (weighted) vs. w=1/gΜ‚w = 1/\hat{g} (ip_weighted). Both are instances of Equation 8 with different weight functions.

4 Implementation Call Chain

optimize_niche(likelihood = "weighted")
  └─ niche_obj.cpp::create_niche_obj_ptr()
       └─ loglik_niche_math_weighted_eigen()       [C++, lines 324–381]
            β”œβ”€ build_L_cov()                        [theta β†’ mu, sigma, L_cov]
            β”œβ”€ Mahalanobis q1 (occurrences), q2 (background)
            β”œβ”€ a_j = log_w_den - 0.5 * q2           [line 366]
            β”œβ”€ logsumexp(a)                          [lines 368–370]
            β”œβ”€ neg_log = 0.5*sum_q1 - log_w_occ + n*lse + penalty
            └─ prior_penalty_value()                 [ridge on log_sigma]

4.1 Key Code (loglik_niche_math_cpp.cpp, lines 324–381)

The C++ kernel:

  1. Reconstructs LcovL_{\text{cov}} from ΞΈ\theta via build_L_cov().
  2. Computes Mahalanobis distances for both presence and background points.
  3. Clamps KDE weights: w.max(MIN_KDE_WEIGHT).log() with MIN_KDE_WEIGHT = 1e-300 to prevent log⁑(0)=βˆ’βˆž\log(0) = -\infty.
  4. Computes the logsumexp of aj=log⁑gΜ‚(𝐲j)βˆ’12qja_j = \log\hat{g}(\mathbf{y}_j) - \frac{1}{2}q_j (line 366).
  5. Adds the ridge penalty via prior_penalty_value() (line 372–373).
  6. Returns the guarded negative log-likelihood (line 379).

4.2 Analytic Gradient (lines 383–499)

The gradient is computed analytically for ΞΌ\mu and log⁑σ\log\sigma, and by central finite differences for the C-vine partial-correlation block vv:

  • βˆ‡ΞΌ\nabla_\mu: Closed-form via Ξ£βˆ’1[weighted mean shift]\Sigma^{-1}[\text{weighted mean shift}] (lines 449–457).
  • βˆ‡log⁑σk\nabla_{\log\sigma_k}: Closed-form via UβŠ™VU \odot V products with softmax weights Ο€j\pi_j (lines 459–464).
  • βˆ‡vk\nabla_{v_k}: Central FD with step Ξ”=|vk|β‹…hrel+habs\Delta = |v_k| \cdot h_{\text{rel}} + h_{\text{abs}} (lines 466–484).
  • Ridge gradient: Added by prior_penalty_grad_add() (line 493).

4.3 R Entry Point

optimize_niche(env_occ, env_m, likelihood = "weighted",
               prior_log_sigma_lambda = 1.0)

5 KDE Computation

The background KDE gΜ‚\hat{g} is computed once before optimisation begins (it depends only on the data, not on ΞΈ\theta). The KDE uses a Gaussian kernel with Scott’s rule bandwidth:

hk=ΟƒΜ‚kβ‹…Kβˆ’1/(p+4), h_k = \hat\sigma_k \cdot K^{-1/(p+4)},

where KK is the number of reference points and ΟƒΜ‚k\hat\sigma_k is the sample standard deviation of the kk-th environmental variable in the background. For p=2p = 2, a specialised kde_2d() kernel is used; for pβ‰₯3p \geq 3, the general kde_eigen() kernel handles arbitrary dimensions.

6 Analytical Properties

Property Value
MLE for ΞΌ\mu No closed form (implicit through the weighted denominator)
Likelihood shape Can be multimodal for complex MM
Identifiability Full for finite MM with ridge (Ξ»>0\lambda > 0)
Background data Required (𝐲j\mathbf{y}_j from MM)
KDE weights Precomputed, fixed during optimisation
Regularisation Ridge prior on log⁑σ\log\sigma (default Ξ»=1\lambda = 1)

7 When To Use

  • Default choice for most species distribution modelling workflows.
  • When observation probability correlates with environmental density (opportunistic records, citizen-science data).
  • When the goal is to estimate the niche as observed through M’s lens (realised niche under the use-availability DGP).
  • When MM is unimodal or mildly multimodal (the ridge prior handles moderate non-convexity).

8 Limitations

  1. DGP assumption. Assumes presence intensity ∝fβ‹…g\propto f \cdot g. If sampling effort is uniform across MM and the goal is the fundamental niche on Lebesgue measure, consider "ip_weighted" (Model 3) instead.

  2. Patil & Ord drift (without ridge). Setting Ξ»=0\lambda = 0 recovers the exact paper Eq. 5 but the MLE may not exist (Οƒβ†’βˆž\sigma \to \infty). Always use Ξ»>0\lambda > 0 in practice.

  3. KDE bandwidth sensitivity. Scott’s rule may over- or under-smooth. Diagnostic plots of gΜ‚\hat{g} are recommended.

  4. Normality assumption. The niche is ellipsoidal. For asymmetric niches, consider "skew_normal_weighted" (Model 5) or "skew_t_weighted" (Model 7).

References

Jimenez, L., and J. SoberΓ³n. 2022. β€œWeighted Likelihood Estimation of the Fundamental Niche.” Ecological Modelling 470: 110009. https://doi.org/10.1016/j.ecolmodel.2022.110009.