Model 5: Skew-Normal Weighted Niche
Source:vignettes/model_skew_normal_weighted.Rmd
model_skew_normal_weighted.Rmd1 Ecological Motivation
This model combines two extensions:
- Skewness (from Model 4): the niche can be asymmetric along each environmental axis.
- Background weighting (from Model 2): the non-uniform distribution of environments in is modelled via a KDE .
The result is a model that estimates an asymmetric fundamental niche while accounting for the fact that presence records are more likely in environments that are common in (the use-availability DGP).
2 Data-Generating Process
The DGP is the same as Model 2, but with a skew-normal kernel replacing the Gaussian:
where is the skew-normal density (Model 4, Eq. 1).
3 Mathematical Specification
3.1 Negative Log-Likelihood
where:
- (squared Mahalanobis distance at presence point ),
- is the same at background point ,
- is the skew score at presence point ,
- is the skew score at background point ,
- is the Gaussian KDE of the background,
- the penalty term is as in Model 4, Eq. (4).
4 Implementation Call Chain
optimize_niche(likelihood = "skew_normal_weighted")
└─ niche_obj.cpp::create_niche_obj_ptr()
└─ loglik_niche_math_skew_normal_weighted_eigen() [C++, lines 590–656]
├─ build_L_cov() [theta → mu, sigma, L_cov]
├─ alpha = Map(theta + 2*p + n_v, p) [line 615]
├─ Mahalanobis q1 (occ), q2 (background)
├─ sum_log_phi_occ = sum_log_pnorm(occ) [line 624]
├─ z_den = skew_z(diff_den, sigma, alpha) [line 632]
├─ log_phi_den = log_pnorm(z_den) [lines 633–634]
├─ a_j = log_w_den + log_phi_den - 0.5*q2 [line 640]
├─ logsumexp(a) [lines 642–644]
├─ prior_penalty_value(has_alpha=true) [lines 646–647]
└─ neg_log = 0.5*sum_q1 - sum_log_phi_occ
- log_w_occ + n*lse + penalty [lines 649–653]
4.1 Key Code (loglik_niche_math_cpp.cpp, lines 590–656)
The C++ kernel:
- Reconstructs and maps (lines 611–615).
- Computes occurrence-side Mahalanobis distances and (lines 620–624).
- Computes background-side Mahalanobis distances and skew scores (lines 626–634).
- Evaluates the denominator integrand (line 640).
- Applies the logsumexp trick (lines 642–644).
- Adds the ridge + alpha penalty (lines 646–647).
- Returns the guarded negative log-likelihood (lines 649–655).
4.2 R Entry Point
optimize_niche(env_occ, env_m, likelihood = "skew_normal_weighted",
prior_log_sigma_lambda = 1.0,
prior_alpha_lambda = 1.0)5 When To Use
- When both asymmetric tolerances and non-uniform environmental availability are expected.
- As a model-selection alternative to
"weighted"(Model 2): fit both and compare via AIC/BIC. If the skewness parameters are close to zero, the simpler Model 2 is preferred. - For species with known thermal or precipitation asymmetries in regions where the accessible area has heterogeneous environments.
6 Limitations
Parameter count. Adds skewness parameters over Model 2. Requires larger sample sizes for reliable estimation.
Patil & Ord drift (shared with Model 2). The ridge prior on is essential; do not set .
Unimodal. The skew-normal is still unimodal. For bimodal niches, mixture extensions are needed (not implemented).
Numerical stability. The product can be very small for background points far from the niche centre. The logsumexp trick (lines 642–644) handles this by working entirely in log space.