| cv_xnicher | R Documentation |
Refits the same likelihood family + same penalty knobs as the
supplied xnicher object on each train fold of env_occ,
warm-started from the full-data \hat\theta, then scores the
held-out fold by evaluating the un-penalised log-likelihood at the
fold's converged \hat\theta_{train}. Returns the **summed**
held-out log-likelihood across folds, which is the standard
out-of-sample log-likelihood used to tune ridge regularisation.
cv_xnicher(
fit,
env_occ,
env_m = NULL,
type = c("kfold", "loo"),
k = 5L,
seed = NULL,
num_starts_cv = 1L,
verbose = FALSE,
ucminf_control = list(maxeval = 500L)
)
fit |
A |
env_occ |
A |
env_m |
A |
type |
Character. |
k |
Integer. Number of folds when |
seed |
Integer or |
num_starts_cv |
Integer. Number of starts per fold. Default
|
verbose |
Logical. Print per-fold progress. |
ucminf_control |
Optional list passed to |
For penalised fits the un-penalised log-likelihood at the converged
\hat\theta (what logLik.xnicher returns) is monotone
in the penalty strengths – the in-sample loglik is always best at
\lambda = 0. Cross-validation breaks that monotonicity by scoring
on data the optimiser did not see, so a properly tuned penalty
achieves higher out-of-sample loglik than the unpenalised MLE.
A list with class "xnicher_cv":
cv_loglikSummed held-out log-likelihood across folds.
cv_loglik_meanPer-occurrence average:
cv_loglik / nobs.
per_folddata.frame(fold, n_test, loglik_test,
convergence).
type"kfold" or "loo".
kNumber of folds (n_occ for LOO).
seedSeed used (or NA_integer_).
* Random k-fold CV assumes the occurrences are exchangeable. For
spatially autocorrelated data this can be optimistic; spatial-block
CV is left to a future release.
* LOO with n_occ large (e.g. Vicugna's 545) is feasible but
non-trivial: 545 ucminf refits at ~0.1-1 s each = ~1-10 minutes.
Consider type = "kfold", k = 10L as a faster proxy.
* Each fold's refit uses ucminfcpp::ucminf starting from
fit$best$theta. If the per-fold likelihood is not unimodal
(rare on dense data, common with skew families on sparse data),
bump num_starts_cv or use the original
optimize_niche() multistart machinery.
compare_xnicher for AIC/BIC-based comparisons.
fit_w <- optimize_niche(
env_occ = example_env_occ_2d, env_m = example_env_m_2d,
num_starts = 5L, breadth = 0.45, likelihood = "weighted",
prior_mu_lambda = 1.0
)
cv_xnicher(fit_w, example_env_occ_2d, example_env_m_2d,
type = "kfold", k = 5L, seed = 42L)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.