Model 2: Weighted-Normal Niche (Paper Eq. 5/8)
Source:vignettes/model_weighted.Rmd
model_weighted.Rmd1 Ecological Motivation
The presence-only model (Model 1) ignores the distribution of environments in the accessible area . 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) of the environmental density in . The weight function enters both the numerator and denominator of the restricted likelihood, modelling an observation process where the probability of recording a presence at is proportional to the product of the speciesβ suitability and the environmental availability .
This is the default model in xnicher
and implements Equation 5 (or equivalently Equation 8 with
)
of Jimenez and SoberΓ³n (2022).
2 Data-Generating Process
The weighted model assumes the use-availability DGP:
This assumes that the intensity of presence records at environment is proportional to both the speciesβ fundamental niche density and the environmental density in . 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.2 Negative Log-Likelihood (Minimised Objective)
Dropping the normalisation constant from the denominator (it cancels between numerator and denominator up to a factor that does not affect the optimum), the minimised objective is:
where:
- is the squared Mahalanobis distance at presence point ,
- at background point ,
- is the Gaussian KDE of the background evaluated at the point,
- centres the ridge prior at the sample standard deviation of each variable,
- 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 , the numerator density flattens, the denominator approaches (a constant), and the likelihood increases without bound.
The ridge term 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 to recover the exact paper formula, but this is not recommended for multimodal .
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:
- Reconstructs
from
via
build_L_cov(). - Computes Mahalanobis distances for both presence and background points.
- Clamps KDE weights:
w.max(MIN_KDE_WEIGHT).log()withMIN_KDE_WEIGHT = 1e-300to prevent . - Computes the logsumexp of (line 366).
- Adds the ridge penalty via
prior_penalty_value()(line 372β373). - Returns the guarded negative log-likelihood (line 379).
4.2 Analytic Gradient (lines 383β499)
The gradient is computed analytically for and , and by central finite differences for the C-vine partial-correlation block :
- : Closed-form via (lines 449β457).
- : Closed-form via products with softmax weights (lines 459β464).
- : Central FD with step (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 is computed once before optimisation begins (it depends only on the data, not on ). The KDE uses a Gaussian kernel with Scottβs rule bandwidth:
where
is the number of reference points and
is the sample standard deviation of the
-th
environmental variable in the background. For
,
a specialised kde_2d() kernel is used; for
,
the general kde_eigen() kernel handles arbitrary
dimensions.
6 Analytical Properties
| Property | Value |
|---|---|
| MLE for | No closed form (implicit through the weighted denominator) |
| Likelihood shape | Can be multimodal for complex |
| Identifiability | Full for finite with ridge () |
| Background data | Required ( from ) |
| KDE weights | Precomputed, fixed during optimisation |
| Regularisation | Ridge prior on (default ) |
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 is unimodal or mildly multimodal (the ridge prior handles moderate non-convexity).
8 Limitations
DGP assumption. Assumes presence intensity . If sampling effort is uniform across and the goal is the fundamental niche on Lebesgue measure, consider
"ip_weighted"(Model 3) instead.Patil & Ord drift (without ridge). Setting recovers the exact paper Eq. 5 but the MLE may not exist (). Always use in practice.
KDE bandwidth sensitivity. Scottβs rule may over- or under-smooth. Diagnostic plots of are recommended.
Normality assumption. The niche is ellipsoidal. For asymmetric niches, consider
"skew_normal_weighted"(Model 5) or"skew_t_weighted"(Model 7).