nitrification_al: determine action levels for nitrification

View source: R/nitrification-al.R

nitrification_alR Documentation

determine action levels for nitrification

Description

nitrification_al calculates proposed action levels for chlorine residual for nitrification control and response plans. These action levels can be calculated via the falling limb method or by plain percentiles of the overall data

Usage

nitrification_al(
  data,
  date_col,
  value_col,
  group_col = NULL,
  model = c("ss", "gam", "loess"),
  method = c("simple", "hmm", "cp"),
  percentiles = c(0.8, 0.5, 0.2),
  max_chlorine = 1.5,
  output_name = c("AL-C", "AL", "P")
)

Arguments

data

a data frame with chlorine residual results

date_col

the unquoted column name of a date or datetime column in data

value_col

the unquoted column name of the results in data

group_col

vector of unquoted column names of grouping variables

model

the model type to use to estimate total chlorine trend. One of "ss" (smooth spline), "gam" (generalized additive model), or "loess" (Local Polynomial Regression)

method

one of "hmm" (hidden markov model), "cp" (changepoints), or "simple". See Details

percentiles

a vector of the percentiles that you would like calculated either on the overall data ("P" method) or on the falling limb portion of the dataset ("FL" method). By default, 0.8, 0.5, and 0.1 are used for action levels 1, 2, and 3, respectively

max_chlorine

maximum chlorine residual value that can be included in falling limb. For example, if you are not concerned with sites when chlorine is greater than 1.5 (default) than no value greater than this threshold will be classified as either "Falling Limb" or "Nitrification Ongoing"

output_name

should the output column names be given as title action levels ("AL-C"), i.e. Action Level 1, Action Level 2, etc., as action levels better suited for R code ("AL"), i.e. action_level_1, etc., or as the percentile ("P"), i.e. 80%, 50%, etc.

Details

The method argument must be set to one of the following:

  • "simple" - A simple classification method that classifies any negative first derivative value as a part of the falling limb. Taking the first derivative of the moving average of the chlorine values is likely to reduce false classification rates when this model type is selected

  • "hmm" - This method uses the depmixS4 package to fit a hidden markov model using the time trend of the first derivative of the total chlorine trend

  • "cp" - This method uses the strucchange package to identify change points in the first derivative trned and classify values based on median first derivative values between change points

By default, there are three percentiles calculated (80%, 50%, 10%) corresponding to three distinct action levels (80% - Action Level 1, 50% - Action Level 2, 10% - Action Level 3). If more or less action levels are desired, then simply specify more or less values in the percentiles argument.

The output tibble will contain columns for each of the specified columns along with any grouping variables used. By default, the column names will be given as their corresponding action level. If you would like to display the percentiles as column names rather than action levels, then specify output_name = "P"

Both of these methods will struggle if samples are not collected regularly at a given location. Regular sampling allows for the overall trends to be identified and classified correctly.


tbradley1013/dwqr documentation built on Feb. 11, 2024, 10:03 a.m.