Skip to content
Kesem Abramov edited this page Aug 19, 2026 · 1 revision

The code used to produce the results and figures presented in the paper.

How to run the code

Open the R project file (LP_corroborative_inference.Rproj) in the main repository folder. This sets the working directory so that all paths resolve. Scripts are written to be run from the project root.

The two parts of the analysis are independent. The Bayesian framework scripts are self-contained: they take no data and can be run in any order. The case study scripts form a chain and should be run in the order below, since each uses the previous one's output.

Only code/serra_marin_svd_prediction_loo.R uses code/common.R, which holds the two shared helpers it needs (sigmoid() and build_interaction_matrix()).

Scripts

Link prediction (code/serra_marin_svd_prediction_loo.R)

Description

Leave-one-out self-prediction for the Cabrera plant–pollinator networks used for the empirical demonstration. For each site and each sampling method, it builds the interaction matrix, withholds one link at a time, and predicts it by rank-2 SVD matrix completion (softImpute). Each network is predicted on its own, with no cross-site training, so local context is preserved.

Input

data/raw_data/serra_marin_pollination/cabrera_22_23_habitat.csv: flower-visit records from six sites under two sampling methods. See Data.

Output

results/serra_marin_loo_predictions.rds: raw leave-one-out output. Computed on first run and reloaded on subsequent runs, so re-running is cheap.

results/predictions/serra_marin_loo_prediction_results.csv: one row per candidate species pair at one focal site under one method, with its observed state, predicted probability and binary call. This is the input to everything downstream.


Link categorisation and figures (code/serra_marin_link_classification_clean.R)

Description

Assigns every predicted link to one of the eight categories, using the other five sites as contextual evidence and the second sampling method as cross-method evidence. Produces the alluvial diagrams and the site-level maps. It contains:

  1. Categorisation of each link–site record by contextual evidence
  2. Cross-method corroboration (have / no evidence)
  3. Diagnostics and sanity checks
  4. Alluvial (Sankey) diagrams, labelled and unlabelled
  5. Tile maps for the most species-rich site
  6. A text summary of the unobserved-link breakdown

The ggsave calls are commented out by default so the script can be run without overwriting saved figures. Uncomment the ones you need.

Input

results/predictions/serra_marin_loo_prediction_results.csv: from serra_marin_svd_prediction_loo.R.

Output

Plots (saved to results/figures/):

File Figure
gg_obs_sankey_clean.svg Fig. 4a (panel of main_sankey_map_labeled.pdf)
map_richest_site.pdf Fig. 4b (panel of main_sankey_map_labeled.pdf)

Interactive Sankey app (code/make_interactive_sankey_app.R)

Description

Builds a self-contained HTML version of the alluvial diagram, with controls for sampling method, classification threshold and cross-method splitting, and click-to-isolate highlighting.

This script writes the source build, not the published app. The live app, docs/interactive_sankey_explorer.html, carries edits made after generation and is never overwritten by this script. Promote a new build by hand once you are happy with it.

Input

results/predictions/serra_marin_loo_prediction_results.csv: from serra_marin_svd_prediction_loo.R.

Output

docs/interactive_sankey_explorer_source.html: the source build.


Bayesian framework figures (Bayesian_framework/)

Description

Nine self-contained scripts, one per figure. Each computes posteriors over the eight categories analytically for a stated set of error rates and writes its figure. They read no data, take no arguments, and can be run individually in any order.

Output

Plots (saved to Bayesian_framework/bayesian_figures/, as both .pdf and .png):

Main figure

Script File Figure
main_accumulation.R main_accumulation.pdf Fig. 3

Supplementary figures

Script File Figure
SI_kappa.R SI_kappa.pdf Fig. S2
SI_erep_tradeoff.R SI_erep_tradeoff.pdf Fig. S3
SI_accumulation.R SI_accumulation.pdf Fig. S4
SI_heterogeneity.R SI_heterogeneity.pdf Fig. S5
SI_correlation.R SI_correlation.pdf Fig. S6
SI_prior_l.R SI_prior_l.pdf Fig. S7
SI_prior_q.R SI_prior_q.pdf Fig. S8