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).
Arguments
- df
Data frame (or tibble) with required parameter columns. Expected defaults (Portuguese names):
od,coliformes,dbo,nt_total,p_total,turbidez,tds,ph(orpH),temperatura.- pesos
Named numeric weights for each parameter (sum not required). Defaults follow CETESB/NSF practice:
od = 0.17coliformes = 0.15dbo = 0.10nt_total = 0.10p_total = 0.10turbidez = 0.08tds = 0.08pH = 0.12(mapped to columnphif 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. IfTRUE, 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 aphcolumn (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