Model 3: Inverse-Probability-Weighted Normal Niche (Horvitz--Thompson)
Source:vignettes/model_ip_weighted.Rmd
model_ip_weighted.Rmd1 Ecological Motivation
When the environmental conditions available in the accessible area are unevenly distributed, a naive maximum-likelihood estimate of the niche centroid is biased toward whatever environments happen to be common in . For example, if 70 % of has temperature near 15 °C, the presence-only MLE will be pulled toward 15 °C even if the species tolerates a wider or differently centred range.
The inverse-probability-weighted (IPW) model removes this environmental-availability confound by reweighting each background point by the inverse of its local environmental density . This converts the discrete sum over the heterogeneous background grid into a numerical approximation of a Lebesgue-measure integral, effectively projecting the niche onto a uniform environmental space.
This is a Horvitz–Thompson (HT) estimator (Horvitz and Thompson (1952)) applied to the restricted likelihood framework of Jimenez et al. (2019).
2 Data-Generating Process
2.1 The Jimenez DGP
The IPW model assumes the Jimenez et al. (2019) DGP: presences are drawn from the fundamental niche density restricted to the set of environments that exist in :
Under this DGP the observation probability at environment depends only on the species’ intrinsic tolerance, not on how common is in . This is appropriate when:
- Sampling effort is approximately uniform across (e.g. systematic surveys).
- The analyst explicitly wants to estimate the fundamental niche (Hutchinson 1957), not the realised niche shaped by .
2.2 Contrast with the Use-Availability DGP
The "weighted" model (Model 2) assumes instead that
presence intensity
.
The two DGPs yield different estimands:
| DGP | Weight | Estimand |
|---|---|---|
| Jimenez (this model) | Fundamental niche on uniform -space | |
| Use-availability (Model 2) | Niche under -biased observation |
Neither is universally “correct”; the choice depends on the ecological question and the data-collection protocol.
3 Mathematical Specification
3.2 Negative Log-Likelihood (Minimised Objective)
Substituting and dropping the constant (which cancels between numerator and denominator):
where (squared Mahalanobis distance), is the same quantity at background point , and is the Gaussian KDE evaluated at the point.
4 Implementation Call Chain
optimize_niche(likelihood = "ip_weighted")
└─ niche_obj.cpp::create_niche_obj_ptr()
└─ loglik_niche_math_ip_weighted_eigen() [C++, lines 101–154]
├─ build_L_cov() [theta → mu, sigma, L_cov]
├─ Mahalanobis q1 (occurrences), q2 (background)
├─ a_j = -0.5 * q2 - log_w_den [line 143]
├─ logsumexp(a) [lines 145–147]
├─ neg_log = 0.5*sum_q1 + log_w_occ + n*lse
└─ OPTIM_PENALTY guard [line 152]
4.1 Key Code (loglik_niche_math_cpp.cpp, lines 101–154)
The C++ kernel:
- Reconstructs
from
via
build_L_cov()(line 123). - Computes Mahalanobis distances for both occurrence and background points (lines 129–137).
- Clamps KDE weights:
w.max(MIN_KDE_WEIGHT).log()withMIN_KDE_WEIGHT = 1e-300to prevent (lines 141–142). - Computes the integrand (line 143).
- Evaluates via the max-shift trick (lines 145–147).
- Returns
0.5 * sum_q1 + log_w_occ.sum() + n * log_sum_exp(lines 149–151).
4.2 Analytic Gradient (lines 186–304)
The hybrid analytic/finite-difference gradient follows the same structure as the weighted gradient (see Model 2):
- : Closed-form via , with softmax weights on the background side (lines 263–271).
- : Closed-form via products (lines 273–278).
- : Central finite differences on the C-vine block (lines 280–298).
4.3 R Entry Point
optimize_niche(env_occ, env_m, likelihood = "ip_weighted")No ridge prior is applied by default because the IPW denominator provides natural self-regularisation (see Section 6).
5 KDE Computation
The KDE is computed identically to Model 2 (Scott’s rule bandwidth, Gaussian kernel, precomputed before optimisation). The only difference is that enters the likelihood with inverted sign:
- In
"weighted": the denominator uses (amplifying common environments). - In
"ip_weighted": the denominator uses (down-weighting common environments).
6 Self-Regularisation
Unlike the weighted model, the IPW model does not require a ridge prior on to prevent . The mechanism:
- As , for all .
- The denominator becomes , which is large because amplifies low-density tail points.
- Meanwhile the numerator also flattens, but the denominator grows faster due to the tail amplification.
- The net effect is that increases as , providing a natural penalty.
This self-regularisation is a property of the Horvitz–Thompson estimator, not an ad hoc fix.
7 Limitations
Variance amplification. When (environmental deserts), the weight can be extremely large, inflating the variance of the estimator. Diagnostic: check the effective sample size .
KDE bandwidth sensitivity. Scott’s rule may under-smooth in low dimensions or over-smooth in high dimensions. Users should inspect the KDE fit.
DGP mismatch. If presences are genuinely generated by the use-availability process (), then the IPW estimator targets the wrong quantity. Use
"weighted"(Model 2) instead.Normality assumption. Same as Model 1. For asymmetric niches, consider combining IPW with a skew-normal or skew-t kernel (not yet implemented in
xnicher).