Compute msPAF for each sample in a per-feature data block
Source:R/mspaf.R
compute_mspaf_per_sample.RdInternal workhorse called by add_mspaf() for each site_id group. Runs
in three phases so the (relatively expensive) SSD evaluation is batched
across samples rather than called once per (sample × analyte):
chemistry normalisation + ARA shift, vectorised across all rows (
.mspaf_adjust());one vectorised
ssdtools::ssd_hp()call per analyte across every sample (.mspaf_add_paf());CA/IA mixture combination via grouped reductions over (sample, draw, MOA group).
Usage
compute_mspaf_per_sample(
sample_data,
ref_table,
ssd_params,
min_analytes,
method,
guideline_dir,
ara_enabled = TRUE
)Arguments
- sample_data
Per-feature long-format df (may include co-analyte rows such as pH, DOC alongside toxicant rows).
- ref_table
Tibble
(analyte, ref_norm)fromprep_ref$ref_table.- ssd_params
Tibble from
derive_ssd_params()(incl. thefitcolumn).- min_analytes
Minimum analytes required.
- method
SSD method (used only for the rare NULL-fit fallback).
- guideline_dir
Path to ANZG XLSX folder (NULL-fit fallback only).
- ara_enabled
Logical; whether the caller supplied a reference. Controls the
ref_sourcediagnostic (see.mspaf_adjust()).