Skip to contents

Computes IQA/WQI by combining parameter-specific sub-scores (Qi) via a weighted mean. Sub-scores are obtained by piecewise-linear interpolation over approximate curves (CETESB/NSF-like).

Usage

iqa(
  df,
  pesos = c(od = 0.17, coliformes = 0.15, dbo = 0.1, nt_total = 0.1, p_total = 0.1,
    turbidez = 0.08, tds = 0.08, pH = 0.12, temperatura = 0.1),
  method = c("CETESB_approx"),
  na_rm = FALSE
)

Arguments

df

Data frame (or tibble) with required parameter columns. Expected defaults (Portuguese names): od, coliformes, dbo, nt_total, p_total, turbidez, tds, ph (or pH), temperatura.

pesos

Named numeric weights for each parameter (sum not required). Defaults follow CETESB/NSF practice:

  • od = 0.17

  • coliformes = 0.15

  • dbo = 0.10

  • nt_total = 0.10

  • p_total = 0.10

  • turbidez = 0.08

  • tds = 0.08

  • pH = 0.12 (mapped to column ph if needed)

  • temperatura = 0.10

method

Character scalar; interpolation table set. Currently only "CETESB_approx".

na_rm

Logical; if FALSE (default), rows containing missing Qi values will trigger an error. If TRUE, the IQA is computed using only available parameters, with the denominator adjusted to the sum of the weights of present parameters.

Value

The input df with an added numeric column IQA. The attribute "iqa_method" is set on the returned data.frame/tibble.

Details

Column name compatibility:

  • The interpolation table uses the key "pH". If your data uses a ph column (lowercase), it is automatically mapped to the "pH" curve.

  • All other parameter names are used as-is.

Values are clipped into [0, 100] after aggregation.

Examples

# Minimal example using the demo data:
d <- wq_demo
d2 <- iqa(d, na_rm = TRUE)
head(d2$IQA)
#> [1] 8.169772 8.772986 7.195704 8.022852 8.789324 7.422467