-
Notifications
You must be signed in to change notification settings - Fork 0
Code
The code used to produce the results and figures presented in the paper.
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()).
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.
data/raw_data/serra_marin_pollination/cabrera_22_23_habitat.csv: flower-visit records from six
sites under two sampling methods. See Data.
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.
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:
- Categorisation of each link–site record by contextual evidence
- Cross-method corroboration (have / no evidence)
- Diagnostics and sanity checks
- Alluvial (Sankey) diagrams, labelled and unlabelled
- Tile maps for the most species-rich site
- 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.
results/predictions/serra_marin_loo_prediction_results.csv: from
serra_marin_svd_prediction_loo.R.
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) |
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.
results/predictions/serra_marin_loo_prediction_results.csv: from
serra_marin_svd_prediction_loo.R.
docs/interactive_sankey_explorer_source.html: the source build.
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.
Plots (saved to Bayesian_framework/bayesian_figures/, as both .pdf and .png):
| Script | File | Figure |
|---|---|---|
main_accumulation.R |
main_accumulation.pdf |
Fig. 3 |
| 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 |