Skip to content

mattreusswig/rpcalc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

rpcalc

An R package implementing the EPA Reasonable Potential (RP) Calculator for environmental compliance analysis. Given effluent monitoring data, the package determines whether a wastewater discharge has "reasonable potential" to cause or contribute to water quality standard exceedances.

Installation

# Install from source using devtools
devtools::install("path/to/rpcalc-master")

Overview

The RP analysis follows a 12-step EPA decision tree and produces one of three endpoints:

Endpoint Meaning Action Required
1 Definitive RP Develop effluent limitations
2 No RP Effluent limitations not required
3 Ambiguous Retain existing limits; monitoring required

Decision Flow

Effluent data + mixing adjustment
        │
        ▼
Step 5: Naked exceedance? ──YES──► Endpoint 1
        │ NO
        ▼
Step 6: ≥ 3 detects AND c/n ≤ 80%?
        │ NO ──────────────────────────────────────► Step 11
        │ YES
        ▼
Steps 7–10: Parametric RPA (log-normal UCB)
   - All detects: use actual log data
   - Some non-detects (c/n ≤ 80%): use ROS-modeled data
        │
        ├── UCB > criteria ──► Endpoint 1
        └── UCB ≤ criteria ──► Endpoint 2
        
Step 11–12: Non-parametric RPA (> 80% non-detects)
   - Compute adjusted n (n minus ties above criteria)
        ├── adj n > 15 ──► Endpoint 2
        └── adj n ≤ 15 ──► Endpoint 3

Mixing Formula

Effluent concentrations are adjusted for receiving water dilution before comparison to criteria:

X = (Ce + Dm × Cs) / (Dm + 1)
  • Ce = effluent concentration
  • Dm = dilution factor
  • Cs = background (receiving water) concentration

Statistical Methods

  • Parametric (complete data): log-normal distribution; UCB = exp(mean_ln + SD_ln × g') where g' is the 95th-percentile/95%-confidence tolerance factor.
  • ROS (some non-detects, c/n ≤ 80%): Regression on Order Statistics via the NADA package to model non-detect values before computing the UCB.
  • Non-parametric (> 80% non-detects): adjusted sample size method.

Usage

Core function: rpcalc()

Runs the full RP analysis for a single parameter.

library(rpcalc)

result <- rpcalc(
  qual       = c("<", "", "", "<", ""),   # qualifier flags
  results    = c(5, 12, 8, 3, 15),        # effluent concentrations
  criteria   = 10,                         # water quality criterion
  dilution   = 10,                         # dilution factor (Dm)
  background = 1                           # background concentration (Cs)
)

result$endpoint     # 1, 2, or 3
result$test_value   # UCB or MEC used in the decision
result$reason       # which step produced the endpoint

The returned list contains:

Field Description
endpoint 1, 2, or 3
reason "Step 5", "Step 10", or "Step 12"
step_decision Logical — whether RP was found
data_used "Actual Data", "Inferred ROS Data"
results Sorted mixed concentrations
test_value MEC (Step 5) or UCB (Step 10)
criteria The criterion used
censored_frac Fraction of non-detects (c/n)
ML Log mean (parametric only)
g_sharp Tolerance factor g' (parametric only)
SD Log standard deviation (parametric only)
adjusted_n Adjusted n (non-parametric only)

Multi-parameter pipeline: run_rpa() and make_rpa_summary_table()

For analyzing multiple parameters at once using a combined data frame:

# 1. Prepare cleaned, merged data
data <- make_clean_data(
  effluent   = effluent_df,    # data frame with columns: parameter, qualifier, result
  criteria   = criteria_df,    # data frame with columns: parameter, criteria
  background = background_df,  # data frame with columns: parameter, background
  dilution   = 10
)

# 2. Apply mixing adjustment
data <- adjust_data(data)

# 3. Run the full RP analysis
data <- run_rpa(data)

# 4. Summarize results
summary_table <- make_rpa_summary_table(data)

Built-in datasets

data(background)   # Reference background concentrations
data(criteria)     # Regulatory water quality criteria
test_eff <- readRDS(system.file("data/test_eff.RDS", package = "rpcalc"))

Development

devtools::load_all()   # Load for interactive development
devtools::test()       # Run tests (Ctrl+Shift+T in RStudio)
devtools::check()      # Check package validity (Ctrl+Shift+E)
devtools::install()    # Install package (Ctrl+Shift+B)

Dependencies

  • NADA — Regression on Order Statistics for censored data
  • dplyr — Data manipulation
  • readxl — Reading Excel input files
  • janitor — Data cleaning
  • here — Project-relative paths

References

  • U.S. EPA (1991). Technical Support Document for Water Quality-based Toxics Control. EPA/505/2-90-001.
  • Helsel, D.R. & Cohn, T.A. (1988). Estimation of descriptive statistics for multiply censored water quality data. Water Resources Research, 24(12), 1997–2004.

About

Reasonable Potential Analysis procedures from California's Ocean Plan (2019)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages