Skip to contents

Computes a composite Allostatic Load (AL) score by flagging biomarkers that exceed user-specified high-risk thresholds (strict > when multiple biomarkers; inclusive >= when only one biomarker). Aligned with HM-CS v3: structured validation, diagnostic control, verbose reporting, and optional summary output.

Usage

allostatic_load(
  data,
  thresholds,
  col_map = NULL,
  na_action = c("keep", "omit", "error"),
  return_summary = FALSE,
  verbose = TRUE
)

Arguments

data

data.frame or tibble of numeric biomarker columns.

thresholds

named list of scalar numeric cutoffs (names must match columns).

col_map

optional named list mapping keys in thresholds to column names in data.

na_action

one of c("keep","omit","error") ("keep" treats NA as zero contribution).

return_summary

logical; TRUE returns list(data, summary, warnings).

verbose

logical; print progress messages via hm_inform() (also gated by options(healthmarkers.verbose)).

Value

tibble with AllostaticLoad or list when return_summary = TRUE.

Details

API pattern note: Unlike most HealthMarkers functions which follow the standard (data, col_map, ...) signature, allostatic_load() uses (data, thresholds, col_map = NULL, ...) because thresholds is a domain-specific required argument that cannot be inferred from column names alone. As a result, this function is not directly dispatchable through the standard all_health_markers() registry; a custom wrapper that supplies thresholds explicitly would be required.

References

Seeman TE, Singer BH, Rowe JW, Horwitz RI, McEwen BS (1997). “Price of Adaptation—Allostatic Load and Its Health Consequences.” Archives of Internal Medicine, 157(19), 2259–2268. doi:10.1001/archinte.1997.00440400111013 .

Examples

df <- tibble::tibble(
  SBP = c(118, 142, 130),
  DBP = c(76, 92, 85),
  CRP = c(1.2, 4.8, 2.1)
)
thr <- list(SBP = 130, DBP = 85, CRP = 3)
allostatic_load(df, thresholds = thr, na_action = "keep", verbose = FALSE)
#> # A tibble: 3 × 1
#>   AllostaticLoad
#>            <int>
#> 1              0
#> 2              3
#> 3              0

# Single biomarker uses inclusive >= rule
allostatic_load(df, thresholds = list(CRP = 3))
#> allostatic_load(): reading input 'df' — 3 rows × 3 variables
#> allostatic_load(): col_map (1 column — 1 inferred from data)
#>   CRP               ->  'CRP'    (inferred)
#> allostatic_load(): computing markers:
#>   AllostaticLoad [CRP]
#> allostatic_load(): results: AllostaticLoad 3/3
#> # A tibble: 3 × 1
#>   AllostaticLoad
#>            <int>
#> 1              0
#> 2              1
#> 3              0