Simulate random errors of a water quality time series by modelling the statistical properties of an observed dataset
lnres_err(dat_in, yr =NULL, comps =FALSE, seed =NULL)
Arguments
dat_in: input data.frame that must include discharge and decimal time columns, see example dataset daydat
yr: numeric year value to use for the stationary model, defaults to the median year
comps: logical indicating if the WRTDS model used to get response error measures is also returned, see value.
seed: optional numeric value for random generation seed
Returns
The original data frame with additional columns for the random errors (errs) and the standard error estimates for each residual (scls). If comps = TRUE, a two-element list is returned that also includes the WRTDS model used as a basis for errors and scale values.
Details
Random errors for a stationary seasonal water quality time series on a daily time step are generated by modelling residuals from an observed dataset. First, a stationary seasonal model is created by fitting a wrtds model and estimating an error distribution the residuals using the auto.arima function. Accumulated standard errors from the regression are also retained for each residual. Random errors using the estimated auto-regressive structures are simulated using arima.sim for the entire year and multiplied by the corresponding standard error estimate from the regression. The entire year is then repeated for every year in the observed time series. The final simulated errors are rescaled to the range of the original residuals that were used to estimate the distribution.
Examples
## Not run:## example datadata(daydat)## get errorslnres_err(daydat)## End(Not run)