Computes a prototype NSF WQI as a weighted arithmetic mean of parameter sub-scores (Qi) using simple piecewise rules. This is intended for quick demonstrations and is not a full replication of the original NSF curves.
Usage
nsfwqi(
df,
pesos = c(do = 0.17, fc = 0.16, ph = 0.11, bod = 0.11, temp_change = 0.1, po4 = 0.1,
no3 = 0.1, turbidez = 0.08, sst = 0.07),
na_rm = FALSE
)Arguments
- df
Data frame containing columns compatible with the mapping above.
- pesos
Named numeric vector with parameter weights. Defaults follow a common NSF WQI variant:
do=.17,fc=.16,ph=.11,bod=.11,temp_change=.10,po4=.10,no3=.10,turbidez=.08,sst=.07.- na_rm
Logical; allow NA per row and rescale weights to available parameters (
TRUE) or error on missing inputs (FALSE).
Details
The function accepts both NSF-style column names and common Brazilian aliases. The mapping tried (if present) is:
do<-odfc<-coliformesph<-pHorphbod<-dboturbidezstaysturbidezsst<-solidos_suspensospo4<-po4orp_ortofosfatono3<-no3orn_nitratotemp_changemust be supplied as-is (delta T to reference)
If na_rm = TRUE, weights are rescaled per row to the parameters
available in that row. If na_rm = FALSE (default), any missing
required input leads to an error.
Examples
d <- wq_demo
# create minimal aliases so the prototype can run
d$do <- d$od
d$fc <- d$coliformes
d$ph <- d$ph
d$bod <- d$dbo
# others are missing; use na_rm = TRUE to rescale weights by row
out <- nsfwqi(d, na_rm = TRUE)
#> Warning: 'drop' argument will be ignored
head(out$NSFWQI)
#> [1] 68.33333 87.46032 61.42857 79.60317 84.92063 63.88889