Learn R Programming

tikatuwq (version 0.8.2)

nsfwqi: NSF Water Quality Index (NSF WQI, prototype)

Description

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
)

Value

The input df with an added numeric column NSFWQI.

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 <- od

  • fc <- coliformes

  • ph <- pH or ph

  • bod <- dbo

  • turbidez stays turbidez

  • sst <- solidos_suspensos

  • po4 <- po4 or p_ortofosfato

  • no3 <- no3 or n_nitrato

  • temp_change must 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

Run this code
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)
head(out$NSFWQI)

Run the code above in your browser using DataLab