EcoMetriQReference Book

9. Validation (Validation)

Tab: ✅ Validation · Code: ui/main_dialog.py:2217-2705 (interface and R templates), modules/validation.py (ValidationEngine, RImportComparator, BetaRComparator, GammaRComparator, ValidationReporter)

9.1 What this tab does

To trust a number produced by a program, two questions are asked: (1) does the program apply the formulas correctly, and (2) does it give the same result on my data as another, well-known implementation? This tab answers both questions in four parts:

Part What it does Data
Part 1 - Built-in Test Suite Tests the program on 10 small data sets whose expected values can be derived by hand shipped with the program
Part 2 - Compare with Your R Output Compares the alpha indices with R on your own data Data Input
Part 3 - Beta Diversity: Compare with R Compares pairwise and multiple-site beta values with R Beta Diversity tab
Part 4 - Gamma Diversity: Compare with R Compares gamma and partitioning values with R Gamma Diversity tab

Results are written to the shared Validation Results box and can be saved as TXT or as CSV (for a supplementary table in a paper).

Figure 9.1. The whole Validation tab: four parts, R template boxes and the results area.
Figure 9.1. The whole Validation tab: four parts, R template boxes and the results area.

9.2 Built-in test suite (Part 1)

The ▶ Run Built-in Validation button runs ValidationEngine.run_all() (modules/validation.py:495-515). For each data set, the EcoMetriQ value is compared with the expected value and the relative difference |\hat\theta - \theta| / |\theta| is classified (modules/validation.py:52-56, 761-766):

Status Relative difference
✅ PASS ≤ 0.1%
⚠️ WARN 0.1% - 1.0%
❌ FAIL > 1.0%

9.2.1 Origin of the expected value

Each data set states where its expected values come from with a provenance label:

Label Meaning Evidential value
analytical The expected value is obtained from a closed-form formula; the calculation is written in the source code distinguishes a correct formula from a wrong one
external_R A value produced by an independent R package; the code is stored with it agreement with an independent implementation
regression A value produced by EcoMetriQ itself only catches changes between versions; not evidence of correctness

The report groups the results by label. In 1.1.2 all 10 data sets are analytical.

9.2.2 Data sets

Data set Comparisons What it tests
Synthetic (hand-calculated) 10 H', 1-D, J', S, N, Margalef, Berger-Parker, D_0, D_1, D_2 for p = (0.5;\,0.3;\,0.1;\,0.1)
BCI (30-entry synthetic reduction) 3 H', 1-D, N; a reduced 30-entry version of BCI plot 1
Coverage & Chao1 analytical test 6 Sample coverage and Chao1 with f_1 = 5, f_2 = 2
Dune Vegetation Beta - 5-plot subset 4 Jaccard, Sørensen and Baselga on a 5-plot subset
Baselga (2010) Table 1 example 11 Pairwise and multiple-site values in Baselga's example (\beta_{SNE} = 0)
Gamma Diversity - 4-site symmetric 10 Four symmetric sites: \beta_W = 1, \beta_H = \ln 2, all \beta_q = 2
Bray-Curtis & Multi-site Beta 4 Bray-Curtis and a multiple-site beta in which one species occurs at three sites
Jost (2007) q=2 alpha 5 Two equal-weight communities with no shared species: \beta = 2 for every q
Chao1 variance and 95% log-normal CI 5 Chao (1987) variance and the log-normal interval
Rarefaction expectation E(S_n) 5 Hurlbert expectation, including the "must be present" case
Total 63

Three data sets were chosen to separate a correct formula from a wrong one: the Jost q = 2 test gives 1.88 in an implementation that uses the arithmetic mean (the correct value is 2); the Chao1 variance test catches a variance with wrongly scaled coefficients; in the multiple-site beta test, one species occurs at three sites, so a wrong denominator gives a different result.

Why a provenance label?

A test whose expected value is produced by the program itself passes even when the program is wrong. The validation suite of EcoMetriQ 1.0.0 reported "34/34 PASS" while six calculations were wrong, because some expected values were the program's own output. In 1.1.0 the origin of every expected value is written down, and the repository contains mutation tests: each corrected bug is reinserted into the code and the suite is checked to fail.

BCI and dune names

The BCI and dune data sets are reduced versions of the vegan::BCI and vegan::dune data; their expected values were re-derived for these short vectors and are not the same as the published BCI or dune values. The report states this in the provenance description of each data set. Do not present them as evidence of "agreement with vegan". The Part 1 description in the tab also introduces the suite as "10 datasets, 63 comparisons" and states that the expected values were derived in closed form (analytical) (ui/main_dialog.py:2232-2243).

9.2.3 Output

  EcoMetriQ — BUILT-IN VALIDATION REPORT
  Tolerance: PASS <=0.1%  |  WARN <=1.0%  |  FAIL >1.0%
  ...
  ── Synthetic (hand-calculated) ──
  Ref type   : analytical
  Provenance : All ten values follow directly from the definitions with p = [0.5, 0.3, 0.1, 0.1]:
               H' = -sum p ln p = 1.1683; unbiased 1-D = 1 - sum n(n-1)/(N(N-1)) = 1 - 26/90 = 0.7111; ...
  Result : ALL PASS  (Pass:10  Warn:0  Fail:0)
  Metric                          Reference    EcoMetriQ      Δ abs      Δ %  Status
  Shannon_H                          1.1683       1.1683   0.00e+00   0.0000  ✅ PASS
  Simpson_1D                         0.7111       0.7111   0.00e+00   0.0000  ✅ PASS
  ...

In the example run, 63 of 63 comparisons passed. The built-in suite does not test your data; it tests the program's formulas. For an independent comparison on your own data, use Parts 2-4.

Figure 9.2. The results box after running the built-in validation.
Figure 9.2. The results box after running the built-in validation.

9.3 Comparing alpha indices with R (Part 2)

9.3.1 Workflow

  1. Load your CSV in Data Input.
  2. Press 📂 Fill from Data Input: the setwd(...) and read.csv(...) lines in the template are replaced with the folder and name of your file (ui/main_dialog.py:2559-2572).
  3. Copy the template and run it in R (the vegan package is required). R writes the file r_validation.csv to the data folder.
  4. Select the source in the Compare using box (Loaded CSV data or Manual table).
  5. Select r_validation.csv in the path box and press 🔍 Compare with R.

The core of the template (ui/main_dialog.py:2274-2314):

library(vegan)
setwd('.../ornek')
df <- read.csv('antalya_basin_species.csv')
df$Species <- trimws(df$Species)
x  <- as.integer(table(df$Species)); N <- sum(x); S <- sum(x > 0)
f1 <- sum(x == 1); f2 <- sum(x == 2)
Shannon_H     <- diversity(x, 'shannon')
# Simpson in BOTH conventions, each under its own name:
Simpson_Gini     <- diversity(x, 'simpson')      # plug-in 1 - sum(p^2)
InvSimpson       <- diversity(x, 'invsimpson')   # plug-in 1 / sum(p^2) = Hill D2
Simpson_D        <- sum(x*(x-1)) / (N*(N-1))     # unbiased dominance
Simpson_unbiased <- 1 - Simpson_D
Chao1_bc      <- estimateR(x)['S.chao1']          # bias-corrected (vegan)
...
write.csv(results, 'r_validation.csv', row.names=FALSE, quote=FALSE)

In the R output, metric names are linked to EcoMetriQ values through a case-insensitive mapping table (modules/validation.py:801-886). Example: shannon → Shannon; simpson_gini → Gini-Simpson (plug-in); simpson_unbiased → unbiased Gini-Simpson; simpson_d → unbiased dominance; invsimpson → plug-in inverse Simpson; chao1_bc → bias-corrected Chao1; chao1 → classic Chao1. Because the template writes the two forms of Simpson under separate names, each R value is compared with the EcoMetriQ value of the same definition. The comparison uses EcoMetriQ's unrounded (full-precision) values; the values shown on screen with four decimals are not used (modules/alpha_beta_indices.py:66-90).

9.3.2 Result on the example data

  Metric                  EcoMetriQ      R value      Δ abs      Δ %  Status
  Shannon_H                 6.19127      6.19127   0.00e+00   0.0000  ✅ PASS
  Simpson_Gini             0.996968     0.996968   0.00e+00   0.0000  ✅ PASS
  Simpson_unbiased         0.997517     0.997517   0.00e+00   0.0000  ✅ PASS
  Simpson_D              0.00248297   0.00248297   0.00e+00   0.0000  ✅ PASS
  InvSimpson                329.853      329.853   0.00e+00   0.0000  ✅ PASS
  Pielou_J                 0.946319     0.946319   0.00e+00   0.0000  ✅ PASS
  Fisher_Alpha              409.991      409.991   0.00e+00   0.0000  ✅ PASS
  Chao1                     992.081      992.081   0.00e+00   0.0000  ✅ PASS
  Chao1_bc                  989.181      989.181   0.00e+00   0.0000  ✅ PASS
  ACE                       1019.48      1019.48   0.00e+00   0.0000  ✅ PASS
  Goods_Coverage           0.833333     0.833333   0.00e+00   0.0000  ✅ PASS
  ...
  SUMMARY: ALL MATCH
  Pass 18  Warn 0  Fail 0  Not in CSV 0
Figure 9.3. Part 2 comparison report, example data.
Figure 9.3. Part 2 comparison report, example data.

In the example data, all 18 of 18 measures are identical. When you adapt the template to your own data, if you change a line or add a value computed with another R function and then see a FAIL or WARN, first check that both sides use the same definition: the plug-in and unbiased forms of Simpson, and the classic and bias-corrected forms of Chao1, give different numbers on the same data (§4.5).

9.4 Comparing beta diversity with R (Part 3)

The beta template uses the vegan and betapart packages. The EcoMetriQ side takes the community data from the manual site box in the Beta Diversity tab; the R side reads the CSV file directly and expects the column names to be exactly Species and site (R is case-sensitive). If your column names differ, correct the df$Species and df$site expressions in the template. The same rule applies to the gamma template. The workflow is the same as in Part 2: 📂 Fill from Data Input → run the template in R (output r_beta_validation.csv) → select the file → 📐 Compare Beta with R.

On the example data, 53 values are compared (10 pairs × 5 measures + 3 multiple-site measures):

  SUMMARY: ALL MATCH
  Pass 53  Warn 0  Fail 0  Not in CSV 0

All 53 values are identical. The beta and gamma comparators also use EcoMetriQ's unrounded values; therefore even nestedness-resultant components with values below 0.03 do not receive a WARN due to rounding.

9.5 Comparing gamma diversity with R (Part 4)

The gamma template uses vegan and takes the community data from the Gamma Diversity table. The output file is r_gamma_validation.csv, and the button is 🌍 Compare Gamma with R.

  Gamma_S                                 694          694   0.00e+00   0.0000  ✅ PASS
  Mean_Alpha_S                            209          209   0.00e+00   0.0000  ✅ PASS
  Whittaker_Beta                      2.32057      2.32057   0.00e+00   0.0000  ✅ PASS
  Gamma_H                             6.13852      6.13852   0.00e+00   0.0000  ✅ PASS
  Gamma_H_pooled                      6.19127            —          —        —  —  (not in R CSV)
  Mean_Alpha_H                         5.0903       5.0903   0.00e+00   0.0000  ✅ PASS
  Beta_H_additive                     1.04822      1.04822   0.00e+00   0.0000  ✅ PASS
  Gamma_D2                            329.853      329.853   0.00e+00   0.0000  ✅ PASS
  MultBeta_q0                         3.32057      3.32057   0.00e+00   0.0000  ✅ PASS
  MultBeta_q1                         2.85258      2.85258   0.00e+00   0.0000  ✅ PASS
  MultBeta_q2                         2.54178      2.54178   0.00e+00   0.0000  ✅ PASS
  SUMMARY: ALL MATCH
  Pass 10  Warn 0  Fail 0  Not in CSV 1
Figure 9.4. Part 4 comparison report.
Figure 9.4. Part 4 comparison report.

The Gamma_H row is the equal-weight gamma Shannon that enters the partitioning (6.1385), and the R template uses the same definition (§7.3.1). The pooled gamma (6.1913) is shown for information under the name Gamma_H_pooled; since it has no counterpart in the template, "not in R CSV" is written and it does not enter the summary (modules/validation.py:1247-1248, 1255-1265).

9.6 Export

9.7 Expert questions

Q1. Does passing the built-in tests show that my results are correct? It shows that the formulas are applied correctly; it does not show that your data were read correctly, that name cleaning (taxonomic curation) was done, or that the record data meet the assumptions. For publication, run the Part 2-4 comparison on your own data and present it as a supplementary table.

Q2. Why are the spatial analyses not in the validation tab? In 1.1.2 there is no built-in test or R template for KDE, Gi*, EOO and AOO. For an independent comparison, you can recalculate Gi* with spdep::localG, and EOO/AOO with sf using a convex hull and a cell count in an equal-area projection; on the cleaned Antalya data, these comparisons gave the same results as EcoMetriQ (Section 8.9; the cleaned file is not distributed with this book).

Q3. Why the 1% limit between WARN and FAIL? It is a rule chosen so that 0.1% separates floating-point and rounding differences, and 1% separates small differences in definition (e.g. the (N-1)/N correction) (modules/validation.py:52-56). A FAIL always points to a difference in definition or data and should be investigated.