Calculates the approved "short" or "long"-term or the "long-daily"
upper water quality thresholds for freshwater life in British Columbia.
The water quality data is automatically cleaned using clean_wqdata
prior to calculating the limits to ensure: all variables are recognised,
all values are non-negative and in the standard units, divergent replicates
are filtered and all remaining replicates are averaged. Only limits whose
conditions are met are returned.
A data.frame of water quality readings to calculate the limits for.
A optional character vector of the columns in x to calculate the limits by.
A string indicating whether to calculate the "long" or "short"-term or "long-daily" limits.
A optional date vector indicating the start of 30 day long-term periods.
A flag indicating whether to keep values with user supplied upper or lower limits.
A flag indicating whether to delete outliers or merely flag them.
A flag indicating whether to estimate total hardness, total chloride and pH for all dates.
Should the data be run through clean_wqdata
before calculating limits? Default TRUE
A data frame of the limits table to use.
A flag indicating whether to print messages.
A string indicating the Use.
If a limit depends on another variable
such as pH, Total Chloride, or Total Hardness and no value was recorded for the date of interest
then the pH, Total Chloride or Total Hardness value is assumed to be the
average recorded value over the 30 day period.
The one exception is if estimate_variables = TRUE
in which case a parametric model
is used to predict the pH, Total Chloride and Total Hardness for all dates with a value of any variable.
Existing values are replaced.
If, in every year, there are less then 12 pH/Total Chloride/Total Hardness then an average value is taken.
Otherwise, if there is only one year with 12 or more values a simple seasonal smoother is used.
If there is two years with 12 or more values then a seasonal smoother with a trend is fitted.
Otherwise a model with trend and a dynamic seasonal component is fitted.
When considering long-term limits there must be at least 5 values spanning 21 days. As replicates are averaged prior to calculating the limits each of the 5 values must be on a separate day. The first 30 day period begin at the date of the first reading while the next 30 day period starts at the date of the first reading after the previous period and so on. The only exception to this is if the user provides dates in which case each period extends for 30 days or until a provided date is reached. It is important to note that the averaging of conditional variables, the 5 in 30 rule and the assignment of 30 day periods occurs independently for all combination of factor levels in the columns specified by by.
If the user wishes to consider the long-term thresholds without the above requirements that
there are at least 5 values spanning 21 days etc then they should set
term = "long-daily"
if (FALSE) {
demo(fraser)
}