This vignette shows how to use the ECDFniche package
to reproduce the simulations from the original
ECDF_MahalDist.R script, comparing Mahalanobis
distance-based suitability transformations using the chi-squared
distribution and the empirical cumulative distribution function
(ECDF).
ecdf_theoretical_niche()The function ecdf_theoretical_niche() simulates a
multivariate normal “environmental space”, computes Mahalanobis
distances for a sample of points, and then maps those distances to
suitability using:
The returned list contains:
corplot: correlation vs sample size between the “true”
niche and both suitability transformationssample_data: matrix with the last sample of
environmental predictorssample_niche, chisq_suits,
ecdf_suits: suitability valuesmahal_dists: Mahalanobis distances for the last
sampleYou can directly plot the correlation object:
The convenience function run_ecdf_mahal_analysis() wraps
the original workflow: it runs ecdf_theoretical_niche() for
several dimensions (by default 1 to 5) and produces three figures
analogous to those in the script.
Figure 1 shows the 2D environmental space (two predictor variables) with color representing different suitability definitions: the simulated “true” niche, the chi-squared-based suitability, and the ECDF-based suitability.
Figure 2 presents, for each dimensionality, how the correlation between the true niche and each distance-to-suitability transformation changes with sample size.
You can customize key aspects of the simulation by passing arguments
to ecdf_theoretical_niche():
res_custom <- ecdf_theoretical_niche(
n = 3,
n_population = 20000,
sample_sizes = seq(50, 1000, 50),
seed = 123
)
res_custom$corplotThese arguments control the dimensionality, the size of the environmental “background”, and the grid of sample sizes used to compute correlations.