├── .Rbuildignore ├── .gitignore ├── .travis.yml ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── DESCRIPTION ├── DISCLAIMER.md ├── LICENSE.md ├── NAMESPACE ├── NEWS.md ├── R ├── aaa_onLoad.R ├── aggregateSolute.R ├── convertToEGRET.R ├── covariance.R ├── deprecated.R ├── diagnostics.R ├── examples.R ├── getResiduals.R ├── interpolations.R ├── loadComp.R ├── loadInterp.R ├── loadLm.R ├── loadModel.R ├── loadModelInterface.R ├── loadReg.R ├── loadReg2.R ├── loadflex.R ├── match.arg.loadflex.R ├── metadata.R ├── plotEGRET.R ├── plots.R ├── predictors.R ├── summarizeData.R ├── sysdata.rda ├── text.R ├── uncertainty.R └── unit.conversions.R ├── README.Rmd ├── README.md ├── appveyor.yml ├── code.json ├── data-raw ├── createExamples.R └── createUnitsData.R ├── data ├── eg_estdat.rda ├── eg_fitdat.rda ├── eg_loadComp.rda ├── eg_loadInterp.rda ├── eg_loadLm.rda ├── eg_loadReg2.rda ├── eg_metadata.rda ├── freeform.unit.translations.rda ├── lamprey_discharge.RData ├── lamprey_nitrate.RData ├── unit.conversions.rda └── valid.metadata.units.rda ├── images └── update.png ├── inst ├── CITATION └── doc │ ├── intro_to_loadflex.R │ ├── intro_to_loadflex.Rmd │ └── intro_to_loadflex.html ├── loadflex.Rproj ├── man ├── aggregateSolute.Rd ├── as.data.frame.metadata.Rd ├── checkRloadestStatus.Rd ├── compModel-class.Rd ├── convertToEGRET.Rd ├── convertToEGRETDaily.Rd ├── convertToEGRETInfo.Rd ├── convertToEGRETSample.Rd ├── convertUnits.Rd ├── correlations-1D.Rd ├── correlations-2D.Rd ├── correlations.Rd ├── dimInfo.Rd ├── eg_loadflex.Rd ├── equals.metadata.Rd ├── estimateMSE.Rd ├── estimateMSE.loadComp.Rd ├── estimateMSE.loadInterp.Rd ├── estimateRho.Rd ├── expandFlowForEGRET.Rd ├── flowconcToFluxConversion.Rd ├── formatPreds.Rd ├── genericDistanceWeightedInterpolation.Rd ├── genericSmoothSplineInterpolation.Rd ├── genericTriangularInterpolation.Rd ├── getCormatCustom.Rd ├── getCormatFirstOrder.Rd ├── getCormatTaoBand.Rd ├── getCorrectionFraction.Rd ├── getDistanceWeightedInterpolation.Rd ├── getFittedModel.Rd ├── getFittedModel.loadModel.Rd ├── getFittingData.Rd ├── getFittingData.loadModel.Rd ├── getFittingFunction.Rd ├── getFittingFunction.loadModel.Rd ├── getMetadata.Rd ├── getMetadata.loadModel.Rd ├── getMetadata.loadReg.Rd ├── getPred_baseflow.Rd ├── getPred_isBaseflow.Rd ├── getResiduals.Rd ├── getRhoFirstOrderFun.Rd ├── getSmoothSplineInterpolation.Rd ├── getTriangularInterpolation.Rd ├── interpModel-class.Rd ├── interpolations.Rd ├── isTimestepRegular.Rd ├── loadComp-class.Rd ├── loadComp.Rd ├── loadInterp-class.Rd ├── loadInterp.Rd ├── loadLm-class.Rd ├── loadLm.Rd ├── loadModel-class.Rd ├── loadModel.Rd ├── loadModelInterface.Rd ├── loadReg2-class.Rd ├── loadReg2.Rd ├── loadflex-deprecated-data.Rd ├── loadflex-deprecated-internal.Rd ├── loadflex-deprecated.Rd ├── loadflex.Rd ├── lognormal-moments.Rd ├── match.arg.loadflex.Rd ├── meltDates.Rd ├── metadata-class.Rd ├── metadata-getters.Rd ├── metadata.Rd ├── observeSolute.Rd ├── onBuild.Rd ├── plotCM.Rd ├── plotConcCM.Rd ├── plotConcResidualsCM.Rd ├── plotEGRET.Rd ├── plotLoadResidualsCM.Rd ├── plotLoadsCM.Rd ├── plotObservationsCM.Rd ├── plotResidualsCM.Rd ├── predictSolute.Rd ├── predictSolute.loadComp.Rd ├── predictSolute.loadInterp.Rd ├── predictSolute.loadLm.Rd ├── predictSolute.loadModel.Rd ├── predictSolute.loadReg2.Rd ├── reSpace.Rd ├── resampleCoefficients.lm.Rd ├── resampleCoefficients.loadReg.Rd ├── residDurbinWatson.Rd ├── rlmetricPPCC.Rd ├── rlmetricPVal.Rd ├── rlmetricRsq.Rd ├── sentenceCase.Rd ├── show.loadModel.Rd ├── show.metadata.Rd ├── simulateSolute.Rd ├── simulateSolute.loadLm.Rd ├── simulateSolute.loadModel.Rd ├── simulateSolute.loadReg2.Rd ├── summarizeInputs.Rd ├── summarizeModel.Rd ├── summarizeModel.loadComp.Rd ├── summarizeModel.loadInterp.Rd ├── summarizeModel.loadLm.Rd ├── summarizeModel.loadModel.Rd ├── summarizeModel.loadReg.Rd ├── summarizeModel.loadReg2.Rd ├── summarizeTimeseries.Rd ├── transformDates.Rd ├── translateFreeformToUnitted.Rd ├── unitType.Rd ├── units_loadflex.Rd ├── validDim.Rd ├── validLoadModelInterface.Rd └── validMetadataUnits.Rd ├── tests ├── testthat.R └── testthat │ ├── helpers.R │ ├── test-01-match.arg.loadflex.R │ ├── test-02-text.R │ ├── test-03-unit.conversions.R │ ├── test-04-uncertainty.R │ ├── test-05-diagnostics.R │ ├── test-06-covariance.R │ ├── test-11-metadata.R │ ├── test-21-loadModel.R │ ├── test-22-loadLm.R │ ├── test-23-1-interpolations.R │ ├── test-23-2-loadInterp.R │ ├── test-24-1-loadReg.R │ ├── test-24-2-loadReg2.R │ ├── test-25-loadComp.R │ ├── test-31-loadModelInterface.R │ ├── test-32-getResiduals.R │ ├── test-33-aggregateSolute.R │ ├── test-41-predictors.R │ ├── test-42-outliers.R │ ├── test-44-plots.R │ └── test-51-EGRET.R └── vignettes └── intro_to_loadflex.Rmd /.Rbuildignore: -------------------------------------------------------------------------------- 1 | ^.*\.Rproj$ 2 | ^\.Rproj\.user$ 3 | ^\.travis\.yml$ 4 | ^appveyor\.yml$ 5 | ^data-raw$ 6 | CODE_OF_CONDUCT.md 7 | images 8 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .Rproj.user 2 | .Rhistory 3 | .RData 4 | temp 5 | tests/testthat/Rplots.pdf 6 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | # Defines the options for building the project on linux with Travis-CI 2 | # For more configuration options, see the wiki: 3 | # https://github.com/craigcitro/r-travis/wiki/Porting-to-native-R-support-in-Travis 4 | 5 | language: r 6 | cache: packages 7 | sudo: false 8 | warnings_are_errors: true 9 | 10 | r_build_args: --no-build-vignettes --no-manual --no-multiarch 11 | r_check_args: --no-build-vignettes --no-manual 12 | 13 | repos: 14 | CRAN: https://cran.rstudio.com 15 | GRAN: https://owi.usgs.gov/R 16 | 17 | before_script: 18 | - Rscript -e "install.packages('knitr')" 19 | - Rscript -e "install.packages('rmarkdown')" 20 | 21 | r_github_packages: 22 | - jimhester/covr 23 | 24 | after_success: 25 | - Rscript -e 'covr::coveralls()' 26 | 27 | after_failure: 28 | - ./travis-tool.sh dump_logs 29 | 30 | notifications: 31 | email: 32 | on_success: change 33 | on_failure: change 34 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | ## Code of Conduct 2 | 3 | ### Contributor Code of Conduct 4 | 5 | As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities. 6 | 7 | We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion. 8 | 9 | Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct. 10 | 11 | Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team. 12 | 13 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers. 14 | 15 | This Code of Conduct is adapted from the 16 | [Contributor Covenant, version 1.0.0](https://www.contributor-covenant.org/version/1/0/0/code-of-conduct.html). 17 | 18 | 19 | ### USGS Code of Scientific Conduct 20 | 21 | Additionally, all contributions to -- and interactions surrounding -- this project will abide by 22 | the 23 | [USGS Code of Scientific Conduct](https://www.usgs.gov/office-of-science-quality-and-integrity/fundamental-science-practices) 24 | and the 25 | [DOI Code of Development Conduct](https://github.com/DOI-BLM/01-guidance/blob/master/CODE_OF_CONDUCT.md). 26 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | ## Contributing 2 | 3 | Contributions are welcome from the community. Questions can be asked on the 4 | [issues page](https://github.com/USGS-R/loadflex/issues). 5 | Before creating a new issue, please take a moment to search 6 | and make sure a similar issue does not already exist. If one does exist, you 7 | can comment (most simply even with just a `:+1:`) to show your support for that 8 | issue. 9 | 10 | If you have direct contributions you would like considered for incorporation 11 | into the project, you can 12 | [fork this repository](https://help.github.com/articles/fork-a-repo/) and 13 | [submit a pull request](https://help.github.com/articles/about-pull-requests/) 14 | for review. 15 | -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: loadflex 2 | Type: Package 3 | Title: Models and Tools for Watershed Flux Estimates 4 | Version: 1.9.2 5 | Date: 2023-07-02 6 | Authors@R: c( 7 | person("Alison P.", "Appling", , "aappling@usgs.gov", c("aut", "cre")), 8 | person("Miguel C.", "Leon", , , "aut"), 9 | person("Lindsay R.", "Carr", , , "ctb"), 10 | person("W. David", "Watkins", , , "ctb") 11 | ) 12 | Author: Alison Appling, Miguel Leon 13 | Maintainer: Alison Appling 14 | Description: loadflex implements several of the most common methods for 15 | modeling and predicting watershed solute fluxes and concentrations, 16 | including interpolation and regression models, period-weighted averaging, 17 | and the composite method. Integrates seamlessly with the USGS's 18 | rloadest package and with native R regression models. Offers a uniform 19 | interface for any model type, with which you can quickly fit models, 20 | generate predictions, and aggregate to monthly or annual values. 21 | VignetteBuilder: knitr 22 | Encoding: UTF-8 23 | Depends: 24 | R(>= 3.0), 25 | methods, 26 | rloadest (>= 0.4.4) 27 | Imports: 28 | smwrBase (>= 1.1.2), 29 | smwrStats, 30 | smwrQW, 31 | unitted (>= 0.2.8), 32 | car, 33 | dplyr, 34 | EGRET, 35 | ggplot2, 36 | lubridate, 37 | MASS, 38 | Matrix, 39 | splines, 40 | stats 41 | Suggests: 42 | knitr, 43 | testthat 44 | LazyData: true 45 | License: CC0 46 | URL: https://github.com/USGS-R/loadflex 47 | Collate: 48 | 'aaa_onLoad.R' 49 | 'aggregateSolute.R' 50 | 'convertToEGRET.R' 51 | 'covariance.R' 52 | 'deprecated.R' 53 | 'diagnostics.R' 54 | 'examples.R' 55 | 'getResiduals.R' 56 | 'interpolations.R' 57 | 'loadModelInterface.R' 58 | 'metadata.R' 59 | 'loadModel.R' 60 | 'loadComp.R' 61 | 'loadInterp.R' 62 | 'loadLm.R' 63 | 'loadReg.R' 64 | 'loadReg2.R' 65 | 'loadflex.R' 66 | 'match.arg.loadflex.R' 67 | 'plotEGRET.R' 68 | 'plots.R' 69 | 'predictors.R' 70 | 'summarizeData.R' 71 | 'text.R' 72 | 'uncertainty.R' 73 | 'unit.conversions.R' 74 | RoxygenNote: 6.1.1 75 | -------------------------------------------------------------------------------- /DISCLAIMER.md: -------------------------------------------------------------------------------- 1 | ## Disclaimer 2 | 3 | This software is preliminary or provisional and is subject to revision. It is 4 | being provided to meet the need for timely best science. The software has not 5 | received final approval by the U.S. Geological Survey (USGS). No warranty, 6 | expressed or implied, is made by the USGS or the U.S. Government as to the 7 | functionality of the software and related material nor shall the fact of release 8 | constitute any such warranty. The software is provided on the condition that 9 | neither the USGS nor the U.S. Government shall be held liable for any damages 10 | resulting from the authorized or unauthorized use of the software. 11 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | ## License 2 | 3 | Unless otherwise noted, This project is in the public domain in the United 4 | States because it contains materials that originally came from the United 5 | States Geological Survey, an agency of the United States Department of 6 | Interior. For more information, see the official USGS copyright policy at 7 | https://www.usgs.gov/information-policies-and-instructions/copyrights-and-credits 8 | 9 | Additionally, we waive copyright and related rights in the work 10 | worldwide through the CC0 1.0 Universal public domain dedication. 11 | 12 | 13 | ### CC0 1.0 Universal Summary 14 | 15 | This is a human-readable summary of the 16 | [Legal Code (read the full text)][1]. 17 | 18 | 19 | #### No Copyright 20 | 21 | The person who associated a work with this deed has dedicated the work to 22 | the public domain by waiving all of his or her rights to the work worldwide 23 | under copyright law, including all related and neighboring rights, to the 24 | extent allowed by law. 25 | 26 | You can copy, modify, distribute and perform the work, even for commercial 27 | purposes, all without asking permission. 28 | 29 | 30 | #### Other Information 31 | 32 | In no way are the patent or trademark rights of any person affected by CC0, 33 | nor are the rights that other persons may have in the work or in how the 34 | work is used, such as publicity or privacy rights. 35 | 36 | Unless expressly stated otherwise, the person who associated a work with 37 | this deed makes no warranties about the work, and disclaims liability for 38 | all uses of the work, to the fullest extent permitted by applicable law. 39 | When using or citing the work, you should not imply endorsement by the 40 | author or the affirmer. 41 | 42 | 43 | [1]: https://creativecommons.org/publicdomain/zero/1.0/legalcode 44 | -------------------------------------------------------------------------------- /NEWS.md: -------------------------------------------------------------------------------- 1 | # 1.1.0 - 1.1.20 or so 2 | 3 | * New function: `plotEGRET`. Generates plots of loadflex inputs and outputs 4 | using code already written and refined in the EGRET load estimation package. 5 | 6 | * New function: `summarizeModel`. Available for all loadModel classes. 7 | 8 | * Expanded list of fields available in `metadata` class, for improved plotting 9 | and summarization. 10 | 11 | * Lightly altered the arguments and features of `getUnits` and `getInfo`. 12 | 13 | 14 | # 1.0.1 15 | 16 | * This version is consistent with the description in Appling, A. P., M. C. Leon, 17 | and W. H. McDowell. 2015. Reducing bias and quantifying uncertainty in watershed 18 | flux estimates: the R package loadflex. Ecosphere 6(12):269. 19 | https://doi.org/10.1890/ES14-00517.1. 20 | -------------------------------------------------------------------------------- /R/aaa_onLoad.R: -------------------------------------------------------------------------------- 1 | #' On package load, create a private environment in the namespace. 2 | #' 3 | #' Should not be run except on building the package. 4 | #' 5 | #' @keywords internal 6 | onBuild <- function() { 7 | pkg_env <- new.env() 8 | 9 | # persistent variable to make sure we only notify the user once per session 10 | # about citing rloadest 11 | pkg_env$rloadest_msg_given <- FALSE 12 | 13 | return(pkg_env) 14 | } 15 | # assign the output of onLoad to the namespace 16 | pkg_env <- onBuild() 17 | -------------------------------------------------------------------------------- /R/deprecated.R: -------------------------------------------------------------------------------- 1 | #' Deprecated functions in the \pkg{loadflex} package 2 | #' 3 | #' These functions were formerly part of loadflex but are now deprecated and may 4 | #' be removed in the future. See the Details section for suggestion on where to 5 | #' look instead. 6 | #' 7 | #' @name loadflex-deprecated 8 | #' @seealso loadflex-deprecated-data 9 | NULL 10 | 11 | #' Deprecated internal functions in the \pkg{loadflex} package 12 | #' 13 | #' These functions were formerly private functions in loadflex but are now 14 | #' deprecated and may be removed in the future. See the Details section for 15 | #' suggestion on where to look instead. 16 | #' 17 | #' @name loadflex-deprecated-internal 18 | NULL 19 | 20 | #' Renamed or deprecated datasets for the \pkg{loadflex} package 21 | #' 22 | #' These datasets have been renamed or removed from the package. 23 | #' 24 | #' @name loadflex-deprecated-data 25 | #' @section Datasets: 26 | #' 27 | #' \itemize{ 28 | #' 29 | #' \item There aren't any deprecated or defunct datasets yet. 30 | #' 31 | #' } 32 | #' @seealso loadflex-deprecated 33 | NULL -------------------------------------------------------------------------------- /R/examples.R: -------------------------------------------------------------------------------- 1 | #### Documentation #### 2 | 3 | #' @name eg_loadflex 4 | #' @aliases lamprey_discharge lamprey_nitrate eg_fitdat eg_estdat eg_metadata 5 | #' eg_loadInterp eg_loadLm eg_loadReg2 eg_loadComp 6 | #' @title Example datasets and objects for the \pkg{loadflex} package 7 | #' @description These datasets and pre-created objects are provided for 8 | #' exploring and testing the \pkg{loadflex} package. 9 | #' @section Datasets: 10 | #' 11 | #' \describe{ 12 | #' 13 | #' \item{\code{eg_fitdat}}{Example dataset for fitting (calibrating) a model. 14 | #' These data are a lightweight subset of \code{lamprey_nitrate}, below.} 15 | #' 16 | #' \item{\code{eg_estdat}}{Example dataset for generating predictions from a 17 | #' fitted model. These data are a lightweight subset of 18 | #' \code{lamprey_discharge}, below.} 19 | #' 20 | #' \item{\code{lamprey_discharge}}{Discharge data for the Lamprey River from 21 | #' 10/1/1999 to 11/16/2014. Discharge in CFS measured every 15 minutes and 22 | #' collected by the US Geological Survey, site 01073500, waterdata.usgs.gov. 23 | #' The Lamprey River is an 81-km river flowing through southeastern New 24 | #' Hampshire. Its 548-km2 watershed empties into the Great Bay estuary.} 25 | #' 26 | #' \item{\code{lamprey_nitrate}}{Nitrate data for the Lamprey River from 27 | #' 10/1/1999 to 11/16/2014. Nitrate is in mg/L and is collected weekly. The 28 | #' Lamprey River is an 81-km river flowing through southeastern New Hampshire. 29 | #' Its 548-km2 watershed empties into the Great Bay estuary. Nitrate 30 | #' concentrations have been monitored with weekly and event-based grab samples 31 | #' at Packers Falls on the Lamprey since 10 September 1999 and are measured by 32 | #' SmartChem discrete analyzer (Westco, Brookfield, CT).} 33 | #' 34 | #' } 35 | #' 36 | #' @section Objects: 37 | #' 38 | #' \describe{ 39 | #' 40 | #' \item{\code{eg_metadata}}{Example metadata object.} 41 | #' 42 | #' \item{\code{eg_loadInterp}}{Example interpolation model object.} 43 | #' 44 | #' \item{\code{eg_loadLm}}{Example linear regression model object.} 45 | #' 46 | #' \item{\code{eg_loadReg2}}{Example model object containing an inner 47 | #' \pkg{rloadest} model.} 48 | #' 49 | #' \item{\code{eg_loadComp}}{Example composite method model object.} 50 | #' 51 | #' } 52 | #' 53 | #' @docType data 54 | NULL 55 | 56 | #### Example creation functions #### 57 | 58 | # See data-raw/createExamples.R for most example creation code 59 | 60 | #' @rdname loadflex-deprecated 61 | #' @details `exampleMetadata` has been replaced by `data(eg_metadata)` 62 | #' @md 63 | #' @importFrom utils data 64 | #' @export 65 | exampleMetadata <- function() { 66 | .Deprecated('eg_metadata', package='loadflex', 67 | 'exampleMetadata() takes too long; use data(eg_metadata) instead') 68 | eg_metadata_name <- data("eg_metadata", envir=environment()) 69 | return(get(eg_metadata_name)) 70 | } 71 | 72 | -------------------------------------------------------------------------------- /R/getResiduals.R: -------------------------------------------------------------------------------- 1 | #' getResiduals return the residuals of the load.model 2 | #' 3 | #' @param load.model a loadModel descendant 4 | #' @param flux.or.conc The format in which residuals should be calculated 5 | #' @param abs.or.rel.resids Should residuals be computed as the difference 6 | #' ("absolute") or the ratio ("relative") of the observed and predicted 7 | #' values? 8 | #' @param use.log logical. Should residuals be computed in log space (TRUE) or 9 | #' linear space (FALSE)? 10 | #' @param newdata New data for prediction and calculation of residuals 11 | #' @param raw logical. [not yet implemented] If TRUE, the residuals are 12 | #' calculated for predictions as they emerge from the inner model. If FALSE, 13 | #' those outputs are retransformed if appropriate (e.g., from log to linear 14 | #' space) and converted to the specified format (flux or conc). 15 | #' @return return The residuals between model predictions and the observations 16 | #' in newdata 17 | #' @export 18 | getResiduals <- function(load.model, flux.or.conc=c("flux","conc"), 19 | abs.or.rel.resids=c("absolute","relative"), use.log=FALSE, 20 | newdata=NULL, raw=FALSE) { 21 | 22 | # Validate arguments 23 | flux.or.conc <- match.arg.loadflex(flux.or.conc) 24 | abs.or.rel.resids <- match.arg.loadflex(abs.or.rel.resids) 25 | 26 | # Get newdata from the model if not provided as an argument 27 | if(is.null(newdata)) newdata <- getFittingData(load.model) 28 | 29 | # Make sure newdata is ordered by date 30 | newdata <- newdata[order(getCol(getMetadata(load.model), newdata, "date")),] 31 | 32 | # Compute residuals as requested 33 | preds <- predictSolute( 34 | load.model=load.model, flux.or.conc=flux.or.conc, newdata=newdata, 35 | date=FALSE, count=FALSE, attach.units=FALSE) 36 | obs <- observeSolute( 37 | data=newdata, flux.or.conc=flux.or.conc, 38 | metadata=getMetadata(load.model), attach.units=FALSE) 39 | if(use.log) { 40 | preds <- log(preds) 41 | obs <- log(obs) 42 | } 43 | resids <- switch( 44 | abs.or.rel.resids, 45 | "absolute" = obs - preds, 46 | "relative" = obs / preds) 47 | 48 | # Return residuals packaged with their dates 49 | data.frame(Date=getCol(getMetadata(load.model), newdata, "date"), Resid=resids) 50 | } 51 | -------------------------------------------------------------------------------- /R/loadflex.R: -------------------------------------------------------------------------------- 1 | #' Models and Tools for Watershed Flux Estimates 2 | #' 3 | #' @section Models: 4 | #' 5 | #' \itemize{ 6 | #' 7 | #' \item Linear and period-weighted interpolations: \code{\link{loadInterp}} 8 | #' 9 | #' \item Generic regression-based models: \code{\link{loadModel}} 10 | #' 11 | #' \item Regression-based models with rloadest (USGS, from LOADEST): 12 | #' \code{\link{loadReg2}} 13 | #' 14 | #' \item Composite-method-based models: \code{\link{loadComp}} 15 | #' 16 | #' } 17 | #' 18 | #' @section Predictions: 19 | #' 20 | #' \itemize{ 21 | #' 22 | #' \item Make predictions at the resolution of the predictor data: 23 | #' \code{\link{predictSolute}} 24 | #' 25 | #' \item Collect predictions into means or totals over longer time periods: 26 | #' \code{\link{aggregateSolute}} 27 | #' 28 | #' } 29 | #' 30 | #' @name loadflex 31 | #' @docType package 32 | NULL 33 | 34 | #' @keywords internal 35 | .onAttach <- function(libname, pkgname) { 36 | packageStartupMessage(paste(c( 37 | strwrap(paste( 38 | "loadflex is a USGS Archive Research Package:", 39 | "https://owi.usgs.gov/R/packages.html#research")), 40 | '', 41 | strwrap(paste( 42 | "Project funding has ended and our maintenance time is limited,", 43 | "but we do attempt to provide bug fixes and lightweight support as we are able.", 44 | "Submit questions or suggestions to https://github.com/USGS-R/loadflex/issues.")), 45 | '', 46 | c("In summer or fall 2023, this package will move from", 47 | "https://github.com/USGS-R/loadflex to", 48 | "https://github.com/DOI-USGS/loadflex", 49 | "Please update your links accordingly.")), 50 | collapse='\n')) 51 | } 52 | 53 | -------------------------------------------------------------------------------- /R/sysdata.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DOI-USGS/loadflex/bfcd8f767efc5298852be0883ec5b12fb3525972/R/sysdata.rda -------------------------------------------------------------------------------- /R/text.R: -------------------------------------------------------------------------------- 1 | ### Some basic text handling helper functions 2 | 3 | #' Capitalize first letter of words. 4 | #' 5 | #' Convert each word in x to have an upper-case first letter and lower-case 6 | #' subsequent letters. Doesn't make exceptions for articles like "the" or "a". A 7 | #' word is defined as continuous alpha characters, so "bill's" becomes "Bill'S" 8 | #' and "u.s.a." becomes "U.S.A". 9 | #' 10 | #' @name sentenceCase 11 | #' @param x a character vector to convert 12 | #' @return a character vector with each word having its first letter capitalized 13 | #' and all others lowercase 14 | #' @keywords internal 15 | #' @examples 16 | #' loadflex:::.sentenceCase("the QUICK brown Fox jumped oVer the LaZY doG") 17 | #' loadflex:::.sentenceCase(c("QUICK brown Fox","LaZY doG")) 18 | #' loadflex:::.sentenceCase(c("u.s.a.", "u_s_a", "bill's", "3 bears", "2 be or not 2be")) 19 | .sentenceCase <- function(x) { 20 | # Convert x to lower case 21 | x <- tolower(x) 22 | 23 | # Replace the pattern (interruptor)(letter) with (interruptor)(LETTER) where 24 | # interruptor is punctuation, space, or the string beginning and LETTER is the 25 | # capitalized version of letter 26 | gsub("(^|[[:punct:]|[:blank:]])([[:alpha:]])", "\\1\\U\\2", x, perl=TRUE) 27 | 28 | # If there are possessives (e.g., "Bill's"), we could make the s lowercase 29 | # again. But this may be unnecessary flexibility for this package. 30 | #gsub("([[:alpha:]])'S([[:punct:]|[:blank:]]|$)", "\\1's\\2", x, perl=TRUE) 31 | } 32 | 33 | #' Replace any space or spaces with a single new.space character apiece 34 | #' 35 | #' @name reSpace 36 | #' @param x string[s] to be respaced 37 | #' @param new.space character[s] with which to replace spaces 38 | #' @param reduce.spaces logical. Reduce multiple consecutive spaces to a single one? 39 | #' @param old.space regular expression defining space; default includes punctuation, space, and tab 40 | #' @return The respaced character string 41 | #' @keywords internal 42 | #' @examples 43 | #' loadflex:::.reSpace("this \t old *!$?# mandolin", reduce.spaces=TRUE) # returns "this_old_mandolin" 44 | .reSpace <- function(x, new.space="_", reduce.spaces=FALSE, old.space="[[:punct:]|[:blank:]]") { 45 | ss <- sapply(x, function(onex) { 46 | s <- strsplit(onex, old.space)[[1]] 47 | space_at_end <- grepl(old.space, substr(onex,nchar(onex),nchar(onex))) 48 | if(reduce.spaces) { 49 | s <- s[s != ""] 50 | } 51 | paste(c(s, if(space_at_end) "" else NULL), collapse=new.space) 52 | }) 53 | unname(ss) 54 | } -------------------------------------------------------------------------------- /appveyor.yml: -------------------------------------------------------------------------------- 1 | # Defines the options for building the project on Windows with ci.appveyor.com 2 | # For more configuration options, see https://www.appveyor.com/docs/build-configuration. 3 | # Note that we're calling a customized version of appveyor-tool.ps1 to get R-stable 4 | # and to call a customized version of travis-tool.sh which uses GRAN+CRAN by default. 5 | 6 | # DO NOT CHANGE the "init" and "install" sections below 7 | 8 | # Download script file from GitHub 9 | init: 10 | ps: | 11 | $ErrorActionPreference = "Stop" 12 | Invoke-WebRequest http://raw.github.com/krlmlr/r-appveyor/master/scripts/appveyor-tool.ps1 -OutFile "..\appveyor-tool.ps1" 13 | Import-Module '..\appveyor-tool.ps1' 14 | 15 | install: 16 | ps: Bootstrap 17 | 18 | # Adapt as necessary starting from here 19 | 20 | environment: 21 | R_VERSION: stable 22 | USE_RTOOLS: true 23 | R_CHECK_ARGS: --no-build-vignettes --no-manual --no-multiarch 24 | R_BUILD_ARGS: --no-build-vignettes --no-manual 25 | R_INSTALL_ARGS: --no-multiarch 26 | GITHUB_PAT: 27 | secure: 03KIbW8uRiLt7B5/qFLzuKKx2t1ElXoZeFxuwVftpkzL4+A2cGPe4wTkKAwOOEb1 28 | global: 29 | WARNINGS_ARE_ERRORS: 1 30 | 31 | build_script: 32 | - R --version 33 | - Rscript -e "install.packages(c('smwrData', 'smwrBase', 'smwrGraphs', 'smwrStats', 'smwrQW', 'rloadest', 'unitted'), repos=c('https://owi.usgs.gov/R', 'https://cran.rstudio.com'))" 34 | - travis-tool.sh install_deps 35 | 36 | test_script: 37 | - travis-tool.sh run_tests 38 | 39 | on_failure: 40 | - 7z a failure.zip *.Rcheck\* 41 | - appveyor PushArtifact failure.zip 42 | 43 | artifacts: 44 | - path: '*.Rcheck\**\*.log' 45 | name: Logs 46 | 47 | - path: '*.Rcheck\**\*.out' 48 | name: Logs 49 | 50 | - path: '*.Rcheck\**\*.fail' 51 | name: Logs 52 | 53 | - path: '*.Rcheck\**\*.Rout' 54 | name: Logs 55 | 56 | - path: '\*_*.tar.gz' 57 | name: Bits 58 | 59 | - path: '\*_*.zip' 60 | name: Bits 61 | -------------------------------------------------------------------------------- /code.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "name": "loadflex", 4 | "organization": "U.S. Geological Survey", 5 | "description": "loadflex implements several of the most common methods for modeling and predicting watershed solute fluxes and concentrations, including interpolation and regression models, period-weighted averaging, and the composite method.", 6 | "version": "main", 7 | "status": "Development", 8 | "permissions": { 9 | "usageType": "openSource", 10 | "licenses": [ 11 | { 12 | "name": "Public Domain, CC0-1.0", 13 | "URL": "https://raw.githubusercontent.com/DOI-USGS/loadflex/main/LICENSE.md" 14 | } 15 | ] 16 | }, 17 | "homepageURL": "https://github.com/DOI-USGS/loadflex/", 18 | "downloadURL": "https://github.com/DOI-USGS/loadflex/archive/refs/heads/main.zip", 19 | "disclaimerURL": "https://raw.githubusercontent.com/DOI-USGS/loadflex/main/DISCLAIMER.md", 20 | "repositoryURL": "https://github.com/DOI-USGS/loadflex.git", 21 | "vcs": "git", 22 | "laborHours": 2000, 23 | "tags": [ 24 | "R", 25 | "USGS", 26 | "River", 27 | "Water Quality", 28 | "doi|https://doi.org/10.1890/ES14-00517.1" 29 | ], 30 | "languages": [ 31 | "R" 32 | ], 33 | "contact": { 34 | "name": "Alison Appling", 35 | "email": "aappling@usgs.gov" 36 | }, 37 | "date": { 38 | "metadataLastUpdated": "2023-07-05" 39 | } 40 | } 41 | ] 42 | -------------------------------------------------------------------------------- /data-raw/createExamples.R: -------------------------------------------------------------------------------- 1 | # Create example datasets and R objects for use in exploring and testing 2 | # loadflex. Only needs to be run when re-creating the .rda objects 3 | library(dplyr) 4 | data(lamprey_nitrate) 5 | data(lamprey_discharge) 6 | date_range <- as.POSIXct(c("2008-10-01 00:00:00", "2012-10-01 00:00:00"), tz="EST5EDT") 7 | set.seed('6509') 8 | 9 | eg_fitdat <- lamprey_nitrate %>% 10 | dplyr::filter(between(DATE, date_range[1], date_range[2])) %>% 11 | dplyr::filter(REGR==TRUE) %>% 12 | slice(sort(sample.int(n(), size=50))) %>% 13 | select(-REGR) 14 | 15 | eg_estdat <- lamprey_discharge %>% 16 | dplyr::filter(between(DATE, date_range[1], date_range[2])) %>% 17 | slice(seq(1, n(), 16)) 18 | 19 | eg_metadata <- metadata( 20 | constituent="NO3", flow="DISCHARGE", load.rate='NO3_FLUX', 21 | dates="DATE", conc.units="mg L^-1", flow.units="cfs", load.units="kg", 22 | load.rate.units="kg d^-1", site.name="Lamprey River, NH", 23 | consti.name="Nitrate", site.id='01073500', lat=43.10259, lon=-70.95256) 24 | 25 | eg_loadInterp <- loadInterp( 26 | interp.format="conc", interp.fun=rectangularInterpolation, 27 | data=eg_fitdat, metadata=eg_metadata) 28 | 29 | eg_loadLm <- loadLm( 30 | formula=log(NO3) ~ log(DISCHARGE), pred.format="conc", 31 | data=eg_fitdat, metadata=eg_metadata, retrans=exp) 32 | 33 | eg_loadReg2 <- loadReg2( 34 | loadReg(NO3 ~ model(9), data=eg_fitdat, 35 | flow="DISCHARGE", dates="DATE", time.step="instantaneous", 36 | flow.units="cfs", conc.units="mg/L", load.units="kg", 37 | station='Lamprey River, NH')) 38 | 39 | eg_loadComp <- loadComp( 40 | reg.model=eg_loadReg2, interp.format="conc", 41 | interp.data=eg_fitdat) 42 | 43 | devtools::use_data( 44 | eg_fitdat, eg_estdat, eg_metadata, 45 | eg_loadInterp, eg_loadLm, eg_loadReg2, eg_loadComp, 46 | overwrite=TRUE, compress='xz') 47 | 48 | tools::checkRdaFiles('data') 49 | -------------------------------------------------------------------------------- /data/eg_estdat.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DOI-USGS/loadflex/bfcd8f767efc5298852be0883ec5b12fb3525972/data/eg_estdat.rda -------------------------------------------------------------------------------- /data/eg_fitdat.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DOI-USGS/loadflex/bfcd8f767efc5298852be0883ec5b12fb3525972/data/eg_fitdat.rda -------------------------------------------------------------------------------- /data/eg_loadComp.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DOI-USGS/loadflex/bfcd8f767efc5298852be0883ec5b12fb3525972/data/eg_loadComp.rda -------------------------------------------------------------------------------- /data/eg_loadInterp.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DOI-USGS/loadflex/bfcd8f767efc5298852be0883ec5b12fb3525972/data/eg_loadInterp.rda -------------------------------------------------------------------------------- /data/eg_loadLm.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DOI-USGS/loadflex/bfcd8f767efc5298852be0883ec5b12fb3525972/data/eg_loadLm.rda -------------------------------------------------------------------------------- /data/eg_loadReg2.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DOI-USGS/loadflex/bfcd8f767efc5298852be0883ec5b12fb3525972/data/eg_loadReg2.rda -------------------------------------------------------------------------------- /data/eg_metadata.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DOI-USGS/loadflex/bfcd8f767efc5298852be0883ec5b12fb3525972/data/eg_metadata.rda -------------------------------------------------------------------------------- /data/freeform.unit.translations.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DOI-USGS/loadflex/bfcd8f767efc5298852be0883ec5b12fb3525972/data/freeform.unit.translations.rda -------------------------------------------------------------------------------- /data/lamprey_discharge.RData: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DOI-USGS/loadflex/bfcd8f767efc5298852be0883ec5b12fb3525972/data/lamprey_discharge.RData -------------------------------------------------------------------------------- /data/lamprey_nitrate.RData: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DOI-USGS/loadflex/bfcd8f767efc5298852be0883ec5b12fb3525972/data/lamprey_nitrate.RData -------------------------------------------------------------------------------- /data/unit.conversions.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DOI-USGS/loadflex/bfcd8f767efc5298852be0883ec5b12fb3525972/data/unit.conversions.rda -------------------------------------------------------------------------------- /data/valid.metadata.units.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DOI-USGS/loadflex/bfcd8f767efc5298852be0883ec5b12fb3525972/data/valid.metadata.units.rda -------------------------------------------------------------------------------- /images/update.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DOI-USGS/loadflex/bfcd8f767efc5298852be0883ec5b12fb3525972/images/update.png -------------------------------------------------------------------------------- /inst/CITATION: -------------------------------------------------------------------------------- 1 | # CITATION 2 | 3 | citHeader("To cite package 'loadflex' in publications use:") 4 | 5 | ## R >= 2.8.0 passes package metadata to citation(). 6 | if(!exists("meta") || is.null(meta)) meta <- packageDescription("heplots") 7 | year <- sub("-.*", "", meta$Date) 8 | note <- sprintf("R package version %s", meta$Version) 9 | 10 | citEntry(entry = "Article", 11 | title = "Reducing bias and quantifying uncertainty in watershed flux estimates: the R package loadflex", 12 | author = personList(as.person("Alison P. Appling"), 13 | as.person("Miguel C. Leon"), 14 | as.person("William H. McDowell")), 15 | year = "2015", 16 | journal = "Ecosphere", 17 | volume = "6", 18 | number = "12", 19 | pages = "art269", 20 | doi = "10.1890/ES14-00517.1", 21 | url = "http://www.esajournals.org/doi/full/10.1890/ES14-00517.1", 22 | 23 | textVersion = paste( 24 | "Appling, A. P., M. C. Leon, and W. H. McDowell. 2015.", 25 | "Reducing bias and quantifying uncertainty in watershed flux estimates: the R package loadflex.", 26 | "Ecosphere 6(12):269. https://doi.org/10.1890/ES14-00517.1") 27 | ) 28 | -------------------------------------------------------------------------------- /inst/doc/intro_to_loadflex.R: -------------------------------------------------------------------------------- 1 | ## ---- echo=FALSE, message=FALSE------------------------------------------ 2 | # Set options for producing the html file & figures 3 | library(knitr) 4 | opts_chunk$set(echo=TRUE, message=FALSE) 5 | set.seed(8437) 6 | 7 | ## ------------------------------------------------------------------------ 8 | library(loadflex) 9 | 10 | ## ----data---------------------------------------------------------------- 11 | # Interpolation data: Packers Falls NO3 grab sample observations 12 | data(lamprey_nitrate) 13 | intdat <- lamprey_nitrate[c("DATE","DISCHARGE","NO3")] 14 | 15 | # Calibration data: Restrict to points separated by sufficient time 16 | regdat <- subset(lamprey_nitrate, REGR)[c("DATE","DISCHARGE","NO3")] 17 | 18 | # Estimation data: Packers Falls discharge 19 | data(lamprey_discharge) 20 | estdat <- subset(lamprey_discharge, DATE < as.POSIXct("2012-10-01 00:00:00", tz="EST5EDT")) 21 | estdat <- estdat[seq(1, nrow(estdat), by=96/4),] # pare to 4 obs/day for speed 22 | 23 | ## ----fig_1A-------------------------------------------------------------- 24 | meta <- metadata(constituent="NO3", flow="DISCHARGE", 25 | dates="DATE", conc.units="mg L^-1", flow.units="cfs", load.units="kg", 26 | load.rate.units="kg d^-1", site.name="Lamprey River, NH", 27 | consti.name="Nitrate", site.id='01073500', lat=43.10259, lon=-70.95256) 28 | 29 | ## ----fig_1B-------------------------------------------------------------- 30 | no3_li <- loadInterp(interp.format="conc", interp.fun=rectangularInterpolation, 31 | data=intdat, metadata=meta) 32 | no3_lm <- loadLm(formula=log(NO3) ~ log(DISCHARGE), pred.format="conc", 33 | data=regdat, metadata=meta, retrans=exp) 34 | library(rloadest) 35 | no3_lr <- loadReg2(loadReg(NO3 ~ model(9), data=regdat, 36 | flow="DISCHARGE", dates="DATE", time.step="instantaneous", 37 | flow.units="cfs", conc.units="mg/L", load.units="kg", 38 | station='Lamprey River, NH')) 39 | no3_lc <- loadComp(reg.model=no3_lr, interp.format="conc", 40 | interp.data=intdat) 41 | 42 | ## ---- eval=FALSE--------------------------------------------------------- 43 | # getMetadata(no3_li) 44 | # getFittingFunction(no3_lm) 45 | # getFittedModel(no3_lr) 46 | # getFittingData(no3_lc) 47 | 48 | ## ----fig_1C-------------------------------------------------------------- 49 | preds_li <- predictSolute(no3_li, "flux", estdat, se.pred=TRUE, date=TRUE) 50 | preds_lm <- predictSolute(no3_lm, "flux", estdat, se.pred=TRUE, date=TRUE) 51 | preds_lr <- predictSolute(no3_lr, "flux", estdat, se.pred=TRUE, date=TRUE) 52 | preds_lc <- predictSolute(no3_lc, "flux", estdat, se.pred=TRUE, date=TRUE) 53 | 54 | ## ------------------------------------------------------------------------ 55 | head(preds_lr) 56 | 57 | ## ----fig_1D, eval=FALSE-------------------------------------------------- 58 | # summary(getFittedModel(no3_lm)) 59 | # ggplot2::qplot(x=Date, y=Resid, data=getResiduals(no3_li, newdata=intdat)) 60 | # residDurbinWatson(no3_lr, "conc", newdata=regdat, irreg=TRUE) 61 | # residDurbinWatson(no3_lr, "conc", newdata=intdat, irreg=TRUE) 62 | # estimateRho(no3_lr, "conc", newdata=regdat, irreg=TRUE)$rho 63 | # estimateRho(no3_lr, "conc", newdata=intdat, irreg=TRUE)$rho 64 | # getCorrectionFraction(no3_lc, "flux", newdat=intdat) 65 | 66 | ## ---- fig_1E------------------------------------------------------------- 67 | aggs_li <- aggregateSolute(preds_li, meta, "flux rate", "month") 68 | aggs_lm <- aggregateSolute(preds_lm, meta, "flux rate", "month") 69 | aggs_lr <- aggregateSolute(preds_lr, meta, "flux rate", "month") 70 | aggs_lc <- aggregateSolute(preds_lc, meta, "flux rate", "month") 71 | 72 | ## ------------------------------------------------------------------------ 73 | head(aggs_lc) 74 | 75 | -------------------------------------------------------------------------------- /loadflex.Rproj: -------------------------------------------------------------------------------- 1 | Version: 1.0 2 | 3 | RestoreWorkspace: Default 4 | SaveWorkspace: Default 5 | AlwaysSaveHistory: Default 6 | 7 | EnableCodeIndexing: Yes 8 | UseSpacesForTab: Yes 9 | NumSpacesForTab: 2 10 | Encoding: UTF-8 11 | 12 | RnwWeave: knitr 13 | LaTeX: pdfLaTeX 14 | 15 | AutoAppendNewline: Yes 16 | StripTrailingWhitespace: Yes 17 | 18 | BuildType: Package 19 | PackageUseDevtools: Yes 20 | PackageInstallArgs: --no-multiarch --with-keep.source 21 | PackageBuildArgs: --resave-data --no-build-vignettes 22 | PackageCheckArgs: --no-vignettes 23 | PackageRoxygenize: rd,collate,namespace 24 | -------------------------------------------------------------------------------- /man/as.data.frame.metadata.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/metadata.R 3 | \name{as.data.frame.metadata} 4 | \alias{as.data.frame.metadata} 5 | \title{Convert a metadata object to a 1-row data.frame} 6 | \usage{ 7 | \method{as.data.frame}{metadata}(x, row.names = NULL, optional = FALSE, 8 | ..., stringsAsFactors = FALSE) 9 | } 10 | \arguments{ 11 | \item{x}{a loadflex metadata object} 12 | 13 | \item{row.names}{NULL or a character vector giving the row names for the data 14 | frame. Missing values are not allowed.} 15 | 16 | \item{optional}{logical. If TRUE, setting row names and converting column 17 | names (to syntactic names: see make.names) is optional. Note that all of 18 | R's base package as.data.frame() methods use optional only for column names 19 | treatment, basically with the meaning of data.frame(*, check.names = 20 | !optional).} 21 | 22 | \item{...}{additional arguments to be passed to or from methods.} 23 | 24 | \item{stringsAsFactors}{logical: should the character vector be converted to 25 | a factor?} 26 | } 27 | \description{ 28 | Organize the fields of a metadata object into a 1-row data.frame. If there is 29 | a custom field, attempt to coerce that field into 1-row data.frame columns 30 | using \code{as.data.frame}; if that effort fails, the custom field will be 31 | excluded. 32 | } 33 | -------------------------------------------------------------------------------- /man/checkRloadestStatus.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/loadReg.R 3 | \name{checkRloadestStatus} 4 | \alias{checkRloadestStatus} 5 | \title{Actions & checks for when the user [indirectly] calls loadReg()} 6 | \usage{ 7 | checkRloadestStatus() 8 | } 9 | \description{ 10 | Require that the user has loaded rloadest. Also give the user a message about 11 | rloadest if appropriate. 12 | } 13 | \keyword{internal} 14 | -------------------------------------------------------------------------------- /man/compModel-class.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/loadComp.R 3 | \docType{class} 4 | \name{compModel-class} 5 | \alias{compModel-class} 6 | \title{#### compModel class #### 7 | The engine of a loadInterp model.} 8 | \description{ 9 | This model class is designed to nest within loadComp objects. The compModel 10 | class is actually a container for two inner models implementing the loadModel 11 | interface: reg.model and resid.model. reg.model will usually be a regression 12 | model, often of type loadReg. resid.model is typically a loadInterp, used to 13 | interpolate among the residuals of the reg.model predictions. 14 | } 15 | \section{Slots}{ 16 | 17 | \describe{ 18 | \item{\code{reg.model}}{The regression model - any model that implements the 19 | loadModelInterface.} 20 | 21 | \item{\code{resid.model}}{The interpolation model - any model that implements the 22 | loadModelInterface.} 23 | 24 | \item{\code{log.resids}}{Should residuals be computed in log space (TRUE) or 25 | linear space (FALSE)?} 26 | 27 | \item{\code{abs.or.rel.resids}}{character specifying whether interpolation should be 28 | by absolute residuals (obs-pred) or relative residuals (obs/pred).} 29 | }} 30 | 31 | \seealso{ 32 | Other load.model.fits: \code{\link{interpModel-class}} 33 | } 34 | \concept{load.model.fits} 35 | -------------------------------------------------------------------------------- /man/convertToEGRET.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/convertToEGRET.R 3 | \name{convertToEGRET} 4 | \alias{convertToEGRET} 5 | \title{Convert loadflex to EGRET object} 6 | \usage{ 7 | convertToEGRET(load.model = NULL, newdata = NULL, data = NULL, 8 | meta = NULL) 9 | } 10 | \arguments{ 11 | \item{load.model}{a load model (loadReg2, loadComp, loadInterp, loadLm, etc.) 12 | whose data and predictions are to be converted to EGRET format} 13 | 14 | \item{newdata}{data.frame of data used to generate predictions from an 15 | already-fitted model} 16 | 17 | \item{data}{data.frame of data used to fit a model. only required if 18 | load.model is omitted} 19 | 20 | \item{meta}{loadflex metadata object; it must include constituent, flow, 21 | dates, conc.units, site.id, and consti.name. only required if load.model is 22 | omitted} 23 | } 24 | \description{ 25 | Convert a loadflex object into an EGRET object for plotting. 26 | } 27 | \examples{ 28 | data(lamprey_nitrate) 29 | fitdat <- lamprey_nitrate 30 | data(lamprey_discharge) 31 | estdat <- subset(lamprey_discharge, DATE < as.POSIXct("2012-10-01 00:00:00", tz="EST5EDT")) 32 | estdat <- estdat[seq(1, nrow(estdat), by=96/4),] # only keep 4 observations per day 33 | meta <- metadata(constituent="NO3", flow="DISCHARGE", dates="DATE", 34 | conc.units="mg L^-1", flow.units="cfs", load.units="kg", load.rate.units="kg d^-1", 35 | site.name="Lamprey River, NH", site.id='NWIS 01073500', consti.name = "nitrate") 36 | no3_lm <- loadLm(formula=log(NO3) ~ log(DISCHARGE), pred.format="conc", 37 | data=fitdat, metadata=meta, retrans=exp) 38 | minimalEGRET <- loadflex:::convertToEGRET(data=fitdat, meta=meta) 39 | maximalEGRET <- loadflex:::convertToEGRET(load.model=no3_lm, newdata=estdat) 40 | } 41 | -------------------------------------------------------------------------------- /man/convertToEGRETDaily.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/convertToEGRET.R 3 | \name{convertToEGRETDaily} 4 | \alias{convertToEGRETDaily} 5 | \title{Convert estimation and load prediction data into the EGRET Daily data.frame} 6 | \usage{ 7 | convertToEGRETDaily(newdata, load.model = NULL, meta = NULL) 8 | } 9 | \arguments{ 10 | \item{newdata}{data.frame of data used to generate predictions from an 11 | already-fitted model} 12 | 13 | \item{load.model}{a load model (loadReg2, loadComp, loadInterp, loadLm, etc.) 14 | whose data and predictions are to be converted to EGRET format} 15 | 16 | \item{meta}{loadflex metadata object; it must include constituent, 17 | flow, dates, conc.units, site.id, and consti.name} 18 | } 19 | \description{ 20 | Convert estimation and load prediction data into the EGRET Daily data.frame 21 | } 22 | -------------------------------------------------------------------------------- /man/convertToEGRETInfo.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/convertToEGRET.R 3 | \name{convertToEGRETInfo} 4 | \alias{convertToEGRETInfo} 5 | \title{Convert a loadflex metadata object into the EGRET INFO dataframe.} 6 | \usage{ 7 | convertToEGRETInfo(meta) 8 | } 9 | \arguments{ 10 | \item{meta}{loadflex metadata object; it must include site.name, consti.name, 11 | site.id, constituent, and conc.units} 12 | } 13 | \description{ 14 | Convert a loadflex metadata object into the EGRET INFO dataframe. 15 | } 16 | -------------------------------------------------------------------------------- /man/convertToEGRETSample.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/convertToEGRET.R 3 | \name{convertToEGRETSample} 4 | \alias{convertToEGRETSample} 5 | \title{Convert the interpolation data.frame into the EGRET Sample dataframe.} 6 | \usage{ 7 | convertToEGRETSample(data = NULL, meta = NULL, dailydat = NULL) 8 | } 9 | \arguments{ 10 | \item{data}{data.frame of data used to fit a model. only required if 11 | load.model is omitted} 12 | 13 | \item{meta}{loadflex metadata object; it must include constituent, flow, 14 | dates, conc.units, site.id, and consti.name. only required if load.model is 15 | omitted} 16 | 17 | \item{dailydat}{an EGRET Daily data.frame of flow and prediction values} 18 | } 19 | \description{ 20 | Convert the interpolation data.frame into the EGRET Sample dataframe. 21 | } 22 | -------------------------------------------------------------------------------- /man/convertUnits.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/unit.conversions.R 3 | \name{convertUnits} 4 | \alias{convertUnits} 5 | \title{Produce conversion factor to multiply old.units by to get new.units} 6 | \usage{ 7 | convertUnits(old.units, new.units, attach.units = FALSE) 8 | } 9 | \arguments{ 10 | \item{old.units}{character. The units to convert from.} 11 | 12 | \item{new.units}{character. The units to convert to.} 13 | 14 | \item{attach.units}{logical. Should units be attached to the conversion 15 | factor?} 16 | } 17 | \value{ 18 | a conversion factor that can be multiplied with data in the old.units 19 | to achieve data in the new.units 20 | } 21 | \description{ 22 | Converts units; units can be arbitrarily complex as long as every dimension 23 | of each unit is present in unit.conversions 24 | } 25 | \examples{ 26 | loadflex:::convertUnits('mg/L', 'kg/m^3') 27 | loadflex:::convertUnits('kg d^-1', 'kg/yr') 28 | loadflex:::convertUnits('kg/yr', 'kg/d', attach.units = TRUE) 29 | \dontrun{ 30 | loadflex:::convertUnits('mg/L', 'm^3/d') # error: dimensions must match 31 | loadflex:::convertUnits(unitbundle('ft^3 g L^-1 s^-1'), 'kg/d') # error: too complicated 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /man/correlations-1D.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/covariance.R 3 | \name{correlations-1D} 4 | \alias{correlations-1D} 5 | \alias{rhoEqualDates} 6 | \alias{rho1DayBand} 7 | \title{Get the assumed correlation between residuals or predictions at pairs of 8 | dates.} 9 | \usage{ 10 | rhoEqualDates(date1, date2) 11 | 12 | rho1DayBand(date1, date2) 13 | } 14 | \arguments{ 15 | \item{date1}{The date of the first prediction} 16 | 17 | \item{date2}{The date[s] of the second prediction[s].} 18 | } 19 | \value{ 20 | A correlation coefficient or a vector of coefficients corresponding 21 | to the pair or pairs in the rows of \code{cbind(date1, date2)}. 22 | } 23 | \description{ 24 | These 1D correlation functions are made available to help users explore and 25 | understand the assumptions that may be made about the correlation structure 26 | of residuals or predictions. It is possible to use these functions directly 27 | for aggregation by calling \code{\link{aggregateSolute}} with the 28 | \code{cormat.function} argument set to either 29 | \code{\link{getCormatCustom}(rhoEqualDates)} or 30 | \code{\link{getCormatCustom}(rho1DayBand)}. However, the equivalent but more 31 | efficient options are to set \code{cormat.function} to 32 | \code{\link{cormatEqualDates}} or \code{\link{cormat1DayBand}}, respectively, 33 | because those \code{cormatXXX} functions produce the full correlation matrix 34 | without costly intermediate steps. 35 | } 36 | \details{ 37 | \code{rhoEqualDates} embodies the standard LOADEST/rloadest assumption about 38 | correlation of residuals for the purpose of aggregation. Specifically, if two 39 | point predictions are on the same calendar date, then rho (the correlation of 40 | their errors) is set to 1, and otherwise rho = 0. 41 | 42 | \code{rho1DayBand} returns 1 for pairs of date-times that are within 1 day 43 | (86400 seconds) of each other, or 0 for pairs that are not. This is a comparable 44 | but smoother assumption than \code{rhoEqualDates}. 45 | } 46 | -------------------------------------------------------------------------------- /man/correlations-2D.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/covariance.R 3 | \name{correlations-2D} 4 | \alias{correlations-2D} 5 | \alias{cormatEqualDates} 6 | \alias{cormat1DayBand} 7 | \alias{cormatDiagonal} 8 | \title{Functions that each produce an autocorrelation matrix with a specified 9 | pattern.} 10 | \usage{ 11 | cormatEqualDates(dates) 12 | 13 | cormat1DayBand(dates) 14 | 15 | cormatDiagonal(dates) 16 | } 17 | \arguments{ 18 | \item{dates}{date-times (as Date, POSIXct, chron, etc.) from which the 19 | autocorrelation matrix should be produced.} 20 | } 21 | \value{ 22 | A matrix of autocorrelation coefficients for all possible pairs of 23 | date-times in \code{dates}. 24 | } 25 | \description{ 26 | Accepts a vector of date-times or dates and returns a correlation matrix 27 | describing the assumed correlations between all possible pairs of those 28 | dates. 29 | 30 | \code{cormatEqualDates} formalizes the assumption used by LOADEST and 31 | rloadest: if two date-times are on the same calendar date, the correlation 32 | (rho) is 1. Otherwise, rho=0. 33 | } 34 | -------------------------------------------------------------------------------- /man/correlations.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/covariance.R 3 | \docType{data} 4 | \name{correlations} 5 | \alias{correlations} 6 | \title{Correlation functions in \pkg{loadflex}} 7 | \description{ 8 | Correlations of residuals or prediction errors are important at several 9 | points in the process of estimating solute concentrations or fluxes. Directly 10 | estimating these correlations is difficult, though sometimes possible. The 11 | functions listed here exist to help the user in (1) estimating correlations 12 | from data, and (2) asserting correlation structures when empirical estimates 13 | are weak or unavailable. 14 | 15 | \subsection{1D Correlation Functions}{ 16 | 17 | These are functions that produce one or more correlation coefficients from pairs of dates. 18 | 19 | \itemize{ 20 | 21 | \item \code{\link{rhoEqualDates}} 22 | 23 | \item \code{\link{rho1DayBand}} 24 | 25 | } 26 | 27 | } 28 | 29 | \subsection{1D Correlation Function Generators}{ 30 | 31 | These are functions that produce functions that produce one or more correlation coefficients. 32 | 33 | \itemize{ 34 | 35 | \item \code{\link{getRhoFirstOrderFun}} 36 | 37 | } 38 | 39 | } 40 | 41 | \subsection{2D Correlation Functions}{ 42 | 43 | These are functions that produce a 2D correlation matrix from a vector of dates. 44 | 45 | \itemize{ 46 | 47 | \item \code{\link{cormatEqualDates}} 48 | 49 | \item \code{\link{cormat1DayBand}} 50 | 51 | } 52 | 53 | } 54 | 55 | \subsection{2D Correlation Function Generators}{ 56 | 57 | These are functions that produce functions that produce 2D correlation matrices. 58 | 59 | \itemize{ 60 | 61 | \item \code{\link{getCormatCustom}} 62 | 63 | \item \code{\link{getCormatTaoBand}} 64 | 65 | \item \code{\link{getCormatFirstOrder}} 66 | 67 | } 68 | 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /man/dimInfo.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/unit.conversions.R 3 | \name{dimInfo} 4 | \alias{dimInfo} 5 | \title{Return a data.frame describing each dimension of the units (1 row per dimension)} 6 | \usage{ 7 | dimInfo(unitstr) 8 | } 9 | \arguments{ 10 | \item{unitstr}{A single string representing one set of units dimension} 11 | } 12 | \description{ 13 | Return a data.frame describing each dimension of the units (1 row per dimension) 14 | } 15 | \examples{ 16 | loadflex:::dimInfo('kg') # 'mg' 17 | loadflex:::dimInfo('ha') # 'km^2' 18 | loadflex:::dimInfo('kg d^-1') # NA 19 | loadflex:::dimInfo('m^3') # NA 20 | loadflex:::dimInfo('kk') # NA 21 | } 22 | -------------------------------------------------------------------------------- /man/eg_loadflex.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/examples.R 3 | \docType{data} 4 | \name{eg_loadflex} 5 | \alias{eg_loadflex} 6 | \alias{lamprey_discharge} 7 | \alias{lamprey_nitrate} 8 | \alias{eg_fitdat} 9 | \alias{eg_estdat} 10 | \alias{eg_metadata} 11 | \alias{eg_loadInterp} 12 | \alias{eg_loadLm} 13 | \alias{eg_loadReg2} 14 | \alias{eg_loadComp} 15 | \title{Example datasets and objects for the \pkg{loadflex} package} 16 | \description{ 17 | These datasets and pre-created objects are provided for 18 | exploring and testing the \pkg{loadflex} package. 19 | } 20 | \section{Datasets}{ 21 | 22 | 23 | \describe{ 24 | 25 | \item{\code{eg_fitdat}}{Example dataset for fitting (calibrating) a model. 26 | These data are a lightweight subset of \code{lamprey_nitrate}, below.} 27 | 28 | \item{\code{eg_estdat}}{Example dataset for generating predictions from a 29 | fitted model. These data are a lightweight subset of 30 | \code{lamprey_discharge}, below.} 31 | 32 | \item{\code{lamprey_discharge}}{Discharge data for the Lamprey River from 33 | 10/1/1999 to 11/16/2014. Discharge in CFS measured every 15 minutes and 34 | collected by the US Geological Survey, site 01073500, waterdata.usgs.gov. 35 | The Lamprey River is an 81-km river flowing through southeastern New 36 | Hampshire. Its 548-km2 watershed empties into the Great Bay estuary.} 37 | 38 | \item{\code{lamprey_nitrate}}{Nitrate data for the Lamprey River from 39 | 10/1/1999 to 11/16/2014. Nitrate is in mg/L and is collected weekly. The 40 | Lamprey River is an 81-km river flowing through southeastern New Hampshire. 41 | Its 548-km2 watershed empties into the Great Bay estuary. Nitrate 42 | concentrations have been monitored with weekly and event-based grab samples 43 | at Packers Falls on the Lamprey since 10 September 1999 and are measured by 44 | SmartChem discrete analyzer (Westco, Brookfield, CT).} 45 | 46 | } 47 | } 48 | 49 | \section{Objects}{ 50 | 51 | 52 | \describe{ 53 | 54 | \item{\code{eg_metadata}}{Example metadata object.} 55 | 56 | \item{\code{eg_loadInterp}}{Example interpolation model object.} 57 | 58 | \item{\code{eg_loadLm}}{Example linear regression model object.} 59 | 60 | \item{\code{eg_loadReg2}}{Example model object containing an inner 61 | \pkg{rloadest} model.} 62 | 63 | \item{\code{eg_loadComp}}{Example composite method model object.} 64 | 65 | } 66 | } 67 | 68 | -------------------------------------------------------------------------------- /man/equals.metadata.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/metadata.R 3 | \docType{methods} 4 | \name{==,metadata,metadata-method} 5 | \alias{==,metadata,metadata-method} 6 | \title{Basic equality test for two metadata objects.} 7 | \usage{ 8 | \S4method{==}{metadata,metadata}(e1, e2) 9 | } 10 | \arguments{ 11 | \item{e1}{metadata object to be compared.} 12 | 13 | \item{e2}{metadata object to be compared.} 14 | } 15 | \value{ 16 | logical value indicating whether the two metadata objects have 17 | identical contents. 18 | } 19 | \description{ 20 | Compares the contents of each slot using the == operator. 21 | } 22 | \concept{metadata 23 | md1 <- metadata(constituent="NO3", flow="DISCHARGE", 24 | dates="DATE", conc.units="mg L^-1", flow.units="cfs", load.units="kg", 25 | load.rate.units="kg d^-1", site.name="Lamprey River, NH") 26 | md2 <- updateMetadata(md1, site.id="1073500", 27 | custom=list(data_source="USGS NWIS, waterdata.usgs.gov")) 28 | md1 == md2} 29 | -------------------------------------------------------------------------------- /man/estimateMSE.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/loadModelInterface.R 3 | \name{estimateMSE} 4 | \alias{estimateMSE} 5 | \title{Estimate model uncertainty algorithmically.} 6 | \usage{ 7 | estimateMSE(load.model, ...) 8 | } 9 | \arguments{ 10 | \item{load.model}{A load model object, typically inheriting from loadModel 11 | and always implementing the loadModelInterface.} 12 | 13 | \item{...}{Other arguments passed to inheriting methods for estimateMSE} 14 | } 15 | \description{ 16 | This function is an optional component of the \link{loadModelInterface}. It 17 | is unnecessary for model fitting, assessment, and prediction except when used 18 | in conjunction with the composite method (i.e., within a 19 | \code{\link{loadComp}} model) or for models such as loadInterps for which the 20 | MSE cannot be known without some estimation procedure. 21 | } 22 | \seealso{ 23 | Other loadModelInterface: \code{\link{getFittedModel}}, 24 | \code{\link{getFittingData}}, 25 | \code{\link{getFittingFunction}}, 26 | \code{\link{getMetadata}}, \code{\link{predictSolute}}, 27 | \code{\link{simulateSolute}}, 28 | \code{\link{summarizeModel}}, 29 | \code{\link{validLoadModelInterface}} 30 | 31 | Other estimateMSE: \code{\link{estimateMSE.loadComp}}, 32 | \code{\link{estimateMSE.loadInterp}} 33 | } 34 | \concept{estimateMSE} 35 | \concept{loadModelInterface} 36 | -------------------------------------------------------------------------------- /man/estimateMSE.loadComp.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/loadComp.R 3 | \name{estimateMSE.loadComp} 4 | \alias{estimateMSE.loadComp} 5 | \title{Estimate uncertainty in a composite model.} 6 | \usage{ 7 | \method{estimateMSE}{loadComp}(load.model, n.iter = 100, 8 | method = "parametric", rho, ...) 9 | } 10 | \arguments{ 11 | \item{load.model}{A load model object, typically inheriting from loadModel 12 | and always implementing the loadModelInterface.} 13 | 14 | \item{n.iter}{The number of times to repeat the COMPLETE process of [simulate 15 | predictions from the regression model and do leave-one-out cross validation 16 | (for all interpolation data points)]. Each run through the process 17 | generates one estimate of the MSE, from which a mean and SD of the MSE 18 | estimates will be returned.} 19 | 20 | \item{method}{character. The method by which the model should be 21 | bootstrapped. "non-parametric": resample with replacement from the original 22 | fitting data, refit the model, and make new predictions. "parametric": 23 | resample the model coefficients based on the covariance matrix originally 24 | estimated for those coefficients, then make new predictions.} 25 | 26 | \item{rho}{The first-order autocorrelation coefficient to assume in 27 | simulateSolute(regression.model, interpolation.data). If missing, rho will 28 | be estimated from the interpolation data, but be warned that many data 29 | points are needed to make this estimation with precision.} 30 | 31 | \item{...}{Other arguments passed to inheriting methods for estimateMSE} 32 | } 33 | \description{ 34 | Calculates and returns the mean squared errors (MSEs) in the units and 35 | transformation space (e.g., log space) of the left-hand side of the model fit 36 | equation. 37 | } 38 | \details{ 39 | This method is leave-one-out cross validation (LOOCV) for the interpolation 40 | and involves repeated resampling of the coefficients from which the 41 | regression predictions and residuals are calculated. 42 | } 43 | \seealso{ 44 | Other estimateMSE: \code{\link{estimateMSE.loadInterp}}, 45 | \code{\link{estimateMSE}} 46 | } 47 | \concept{estimateMSE} 48 | -------------------------------------------------------------------------------- /man/estimateMSE.loadInterp.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/loadInterp.R 3 | \name{estimateMSE.loadInterp} 4 | \alias{estimateMSE.loadInterp} 5 | \title{Estimate uncertainty in an interpolation using leave-one-out cross 6 | validation.} 7 | \usage{ 8 | \method{estimateMSE}{loadInterp}(load.model, n.out, 9 | n.iter = floor(nrow(getFittingData(load.model))/n.out), replace, ...) 10 | } 11 | \arguments{ 12 | \item{load.model}{A load model object, typically inheriting from loadModel 13 | and always implementing the loadModelInterface.} 14 | 15 | \item{n.out}{numeric. The number of observations in the fitting data to leave 16 | out in each iteration.} 17 | 18 | \item{n.iter}{numeric. The number of iterations to perform.} 19 | 20 | \item{replace}{logical. In each iteration, should the n.out observations that 21 | are left out be sampled with replacement of any previous sets of n.out 22 | observations (TRUE) or without replacement (FALSE)?} 23 | 24 | \item{...}{Other arguments passed to inheriting methods for estimateMSE} 25 | } 26 | \description{ 27 | Calculates and returns the mean squared errors (MSEs) in the units and 28 | transformation space (e.g., log space) of the left-hand side of the model fit 29 | equation. 30 | } 31 | \details{ 32 | This method is leave-one-out cross validation (LOOCV) when n.out==1, 33 | n.iter==nrow(getFittingData(load.model)), and with.replacement=FALSE. This 34 | method is k-fold cross validation when 35 | n.out*n.iter==nrow(getFittingData(load.model)) and with.replacement==FALSE. 36 | } 37 | \seealso{ 38 | Other estimateMSE: \code{\link{estimateMSE.loadComp}}, 39 | \code{\link{estimateMSE}} 40 | } 41 | \concept{estimateMSE} 42 | -------------------------------------------------------------------------------- /man/estimateRho.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/diagnostics.R 3 | \name{estimateRho} 4 | \alias{estimateRho} 5 | \title{Estimate the autocorrelation of a mid- to high-resolution time series} 6 | \usage{ 7 | estimateRho(load.model, flux.or.conc = c("flux", "conc"), 8 | abs.or.rel.resids = c("absolute", "relative"), use.log = FALSE, 9 | newdata = NULL, plot.acf = TRUE, 10 | timestep.tol = .Machine$double.eps^0.5, irregular.timesteps.ok = NA) 11 | } 12 | \arguments{ 13 | \item{load.model}{a loadModel descendant} 14 | 15 | \item{flux.or.conc}{The format in which residuals should be calculated} 16 | 17 | \item{abs.or.rel.resids}{Should residuals be computed as the difference or 18 | the ratio of the observed and predicted values?} 19 | 20 | \item{use.log}{logical. use log residuals?} 21 | 22 | \item{newdata}{prediction values. If this is set to NULL, 23 | \code{getFittingData(load.model)} will be used.} 24 | 25 | \item{plot.acf}{logical. Should the autocorrelation function be plotted?} 26 | 27 | \item{timestep.tol}{the acceptable tolerance for considering timesteps 28 | regular.} 29 | 30 | \item{irregular.timesteps.ok}{logical. If FALSE, this function requires that 31 | the timesteps between observations are identical to one another, and a plot 32 | is generated and an error is thrown if this requirement is not met. If 33 | TRUE, the check is not performed. If NA (the default), the check is 34 | performed but the function proceeds with a warning and no plot if the 35 | timesteps are found to be irregular. Estimates of autocorrelation are weak 36 | to wrong when timesteps are irregular, but timesteps are often at least a 37 | bit irregular in the real world.} 38 | } 39 | \value{ 40 | Return the rho function and the fitted model. 41 | } 42 | \description{ 43 | Uses arima() to estimate the first-order autocorrelation constant, rho, for 44 | the residuals calculated from a load model and new data. 45 | } 46 | \details{ 47 | For the purpose of estimating prediction error for a composite method 48 | application, this function should be called with a dataset of comparable (or 49 | identical) resolution to that of the interpolation data. 50 | 51 | For the purpose of estimating the covariance of prediction errors for 52 | aggregation, this function should not be called unless newdata are at 53 | approximately the same (or higher) temporal resolution as that of the data to 54 | be used for load estimation. This will almost always involve sensor data. 55 | 56 | If you have no data with sufficient resolution to reasonably call this 57 | function, take your pick from the established assumptions implemented in 58 | functions such as \code{\link{rhoEqualDates}} or \code{\link{rho1DayBand}}, 59 | or write your own assumptions. 60 | } 61 | \seealso{ 62 | Other diagnostics: \code{\link{getCorrectionFraction}}, 63 | \code{\link{residDurbinWatson}} 64 | } 65 | \concept{diagnostics} 66 | -------------------------------------------------------------------------------- /man/expandFlowForEGRET.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/convertToEGRET.R 3 | \name{expandFlowForEGRET} 4 | \alias{expandFlowForEGRET} 5 | \title{Convert a date and discharge data.frame into EGRET format} 6 | \usage{ 7 | expandFlowForEGRET(flowdat, flow.colname, date.colname, flow.units) 8 | } 9 | \arguments{ 10 | \item{flowdat}{data frame with discharge values to convert} 11 | 12 | \item{flow.colname}{character string giving the column name that corresponds 13 | to flow} 14 | 15 | \item{date.colname}{character string giving the column name that corresponds 16 | to dates} 17 | 18 | \item{flow.units}{character string giving the current units of flow in 19 | flowdat} 20 | } 21 | \description{ 22 | Use EGRET functions to convert a data.frame of date and 23 | discharge columns into "the basic Daily data frame used in WRTDS", i.e., a 24 | 13-column data.frame with parsed datetimes, log(Q), and 7-day and 30-day 25 | smoothed Q, plus a column for dateTime. See 26 | \code{\link[EGRET]{populateDaily}} 27 | } 28 | -------------------------------------------------------------------------------- /man/flowconcToFluxConversion.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/unit.conversions.R 3 | \name{flowconcToFluxConversion} 4 | \alias{flowconcToFluxConversion} 5 | \title{Provide the conversion factor which, when multiplied by flow * conc, gives 6 | the flux in the desired units} 7 | \usage{ 8 | flowconcToFluxConversion(flow.units, conc.units, load.rate.units, 9 | attach.units = FALSE) 10 | } 11 | \arguments{ 12 | \item{flow.units}{character. The units of flow.} 13 | 14 | \item{conc.units}{character. The units of concentration.} 15 | 16 | \item{load.rate.units}{character. The units of flux.} 17 | 18 | \item{attach.units}{logical. If TRUE, the conversion factor is returned with 19 | units attached.} 20 | } 21 | \value{ 22 | numeric, or unitted numeric if unitted=TRUE. The conversion factor. 23 | } 24 | \description{ 25 | By dividing rather than multiplying by this factor, the output of this 26 | function may also be used to convert from flux units to the units of the 27 | product of flow and concentration. 28 | } 29 | \examples{ 30 | flowconcToFluxConversion("cfs", "g/L", "kg/d") # 2446.589 31 | library(unitted); u(10, "ft^3 s^-1") * u(2, "mg L^-1") * 32 | flowconcToFluxConversion("cfs", "mg/L", "kg/d", attach.units=TRUE) # u(48.9 ,"kg d^-1") 33 | } 34 | -------------------------------------------------------------------------------- /man/formatPreds.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/unit.conversions.R 3 | \name{formatPreds} 4 | \alias{formatPreds} 5 | \title{formatPreds raw to final predictions} 6 | \usage{ 7 | formatPreds(preds, from.format = c("flux", "conc*flow", "flux/flow", 8 | "conc"), to.format = c("flux", "conc"), newdata, metadata, 9 | lin.or.log = c("linear", "log"), attach.units = FALSE) 10 | } 11 | \arguments{ 12 | \item{preds}{raw prediction values} 13 | 14 | \item{from.format}{character in 15 | \code{c("flux","conc*flow","flux/flow","conc")}. Format of the raw 16 | predictions.} 17 | 18 | \item{to.format}{character indicating whether the returned value should be a 19 | flux or a concentration.} 20 | 21 | \item{newdata}{a data.frame with nrow() == length(preds) and containing any 22 | columns (named as in \code{metadata}) that will be needed to perform the 23 | requested conversion. For example, from="conc" and to="flux" implies that 24 | a discharge column will be available in \code{newdata}.} 25 | 26 | \item{metadata}{An object of class \code{\link{metadata}} used to determine 27 | the units of inputs and desired output} 28 | 29 | \item{lin.or.log}{character. Either "linear" or "log" to say whether the predictions 30 | should be converted to log space or not. If converted to log space, a bias correction 31 | will be applied, see \code{\link{linToLog}}.} 32 | 33 | \item{attach.units}{logical. Attach the units to the returned value?} 34 | } 35 | \value{ 36 | converted predictions (in the format/units specified by to.format and 37 | metadata) 38 | } 39 | \description{ 40 | Convert raw predictions to final predictions, possibly including a switch 41 | between flux and conc. If there is a switch, the units will be converted 42 | according to the metadata. 43 | } 44 | \examples{ 45 | obs <- transform(data.frame(MyConc=1:10, MyFlow=rep(10,10)), 46 | MyFlux=MyConc*MyFlow*rloadest::loadConvFactor("cms", "mg/l", "kg") ) 47 | md <- metadata(constituent="MyConc", flow="MyFlow", 48 | load.rate="MyFlux", dates="none", flow.units="m^3 s^-1", conc.units="mg L^-1", 49 | load.units="kg", load.rate.units="kg/d", site.name='My River', custom=NULL) 50 | 51 | all.equal(obs$MyFlux, formatPreds( 52 | preds=obs$MyConc, from.format="conc", to.format="flux", newdata=obs, metadata=md)) 53 | \dontrun{ 54 | # these examples take too long to build regularly 55 | all.equal(obs$MyFlux, formatPreds( 56 | preds=obs$MyConc*obs$MyFlow, from.format="conc*flow", to.format="flux", 57 | newdata=obs, metadata=md)) 58 | all.equal(obs$MyConc, formatPreds( 59 | preds=obs$MyFlux, from.format="flux", to.format="conc", newdata=obs, metadata=md)) 60 | all.equal(unitted::u(obs$MyConc, "mg L^-1"), formatPreds( 61 | preds=obs$MyFlux, from.format="flux", to.format="conc", newdata=obs, metadata=md, 62 | attach.units=TRUE)) 63 | } 64 | } 65 | \keyword{units} 66 | -------------------------------------------------------------------------------- /man/genericDistanceWeightedInterpolation.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/interpolations.R 3 | \name{genericDistanceWeightedInterpolation} 4 | \alias{genericDistanceWeightedInterpolation} 5 | \title{A parameterizable distance-weighted interpolation function.} 6 | \usage{ 7 | genericDistanceWeightedInterpolation(dates.in, y.in, dates.out, 8 | inv.dist.fun = function(a, b) { 1/((a - b)^2) }) 9 | } 10 | \arguments{ 11 | \item{dates.in}{A numeric vector desribing the dates for each of the values 12 | in \code{y.in}. Dates are represented as the number of seconds since 1970.} 13 | 14 | \item{y.in}{A vector of values (typically fluxes or concentrations) to 15 | interpolate among.} 16 | 17 | \item{dates.out}{A numeric vector of dates for which the corresponding output 18 | values are to be produced. Dates are represented as the number of seconds 19 | since 1970.} 20 | 21 | \item{inv.dist.fun}{A function to calculate an inverse distance metric. 22 | Should be vectorized such that one of \code{a} or \code{b} may be a vector 23 | when the other is a scalar.} 24 | } 25 | \description{ 26 | Does not strictly adhere to the guidelines in \link{interpolations}, but can 27 | be used by \code{\link{getDistanceWeightedInterpolation}} to produce a 28 | function that does. 29 | } 30 | -------------------------------------------------------------------------------- /man/genericSmoothSplineInterpolation.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/interpolations.R 3 | \name{genericSmoothSplineInterpolation} 4 | \alias{genericSmoothSplineInterpolation} 5 | \title{A parameterizable smoothing spline function.} 6 | \usage{ 7 | genericSmoothSplineInterpolation(dates.in, y.in, dates.out, ...) 8 | } 9 | \arguments{ 10 | \item{dates.in}{A numeric vector desribing the dates for each of the values 11 | in \code{y.in}. Dates are represented as the number of seconds since 1970.} 12 | 13 | \item{y.in}{A vector of values (typically fluxes or concentrations) to 14 | interpolate among.} 15 | 16 | \item{dates.out}{A numeric vector of dates for which the corresponding output 17 | values are to be produced. Dates are represented as the number of seconds 18 | since 1970.} 19 | 20 | \item{...}{any arguments other than \code{x} and \code{y} to be passed to 21 | \code{stats::\link{smooth.spline}}.} 22 | } 23 | \description{ 24 | Does not strictly adhere to the guidelines in \link{interpolations}, but can 25 | be used by \code{\link{getSmoothSplineInterpolation}} to produce a 26 | function that does. 27 | } 28 | -------------------------------------------------------------------------------- /man/genericTriangularInterpolation.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/interpolations.R 3 | \name{genericTriangularInterpolation} 4 | \alias{genericTriangularInterpolation} 5 | \title{A parameterizable triangular interpolation function.} 6 | \usage{ 7 | genericTriangularInterpolation(dates.in, y.in, dates.out, y.mid) 8 | } 9 | \arguments{ 10 | \item{dates.in}{A numeric vector desribing the dates for each of the values 11 | in \code{y.in}. Dates are represented as the number of seconds since 1970.} 12 | 13 | \item{y.in}{A vector of values (typically fluxes or concentrations) to 14 | interpolate among.} 15 | 16 | \item{dates.out}{A numeric vector of dates for which the corresponding output 17 | values are to be produced. Dates are represented as the number of seconds 18 | since 1970.} 19 | 20 | \item{y.mid}{The value or values to which midpoints between observations 21 | should be set. Good choices are: mean(y.in) for stand-alone interpolations; 22 | 0 for composite method interpolations among absolute residuals (in log or 23 | linear space); 1 for composite method interpolations among relative 24 | residuals (again, log or linear space).} 25 | } 26 | \description{ 27 | Does not strictly adhere to the guidelines in \link{interpolations}, but can 28 | be used by \code{\link{getTriangularInterpolation}} to produce a 29 | function that does. 30 | } 31 | -------------------------------------------------------------------------------- /man/getCormatCustom.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/covariance.R 3 | \name{getCormatCustom} 4 | \alias{getCormatCustom} 5 | \title{Turn an autocorrelation function into a function that produces a correlation 6 | matrix} 7 | \usage{ 8 | getCormatCustom(cor1D.function, vectorized = FALSE) 9 | } 10 | \arguments{ 11 | \item{cor1D.function}{An autocorrelation function - specifically, a function 12 | that accepts two date arguments and returns the correlation coefficient[s] 13 | for those dates. If each date argument is a single date, the output should 14 | be a single coefficient. If the second date argument is a vector of dates, 15 | the output should be a vector of the same length as that dates vector.} 16 | 17 | \item{vectorized}{logical. Can rho.function accept its second argument as a 18 | vector rather than a scalar? If so, the matrix-generating function may be 19 | faster.} 20 | } 21 | \value{ 22 | A function that accepts a new vector of N dates and produces an 23 | N-by-N correlation matrix. 24 | } 25 | \description{ 26 | Produces a function of the form described in \link{correlations-2D} from a 27 | function of the form described in \link{correlations-1D}. 28 | } 29 | \details{ 30 | For use with custom autocorrelation functions. Although it is usually faster 31 | to create your own matrix-generating function, this function will accept a 32 | simpler autocorrelation function (one of the form described in 33 | \link{correlations-1D}) and return a function that accepts a vector of dates 34 | generates a matrix of correlations for all possible pairs of those dates (a 35 | function of the form described in \link{correlations-2D}. The matrix returned 36 | by that second function will be sparse if it is at least half zeros. 37 | } 38 | -------------------------------------------------------------------------------- /man/getCormatFirstOrder.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/covariance.R 3 | \name{getCormatFirstOrder} 4 | \alias{getCormatFirstOrder} 5 | \title{get rho matrix first order} 6 | \usage{ 7 | getCormatFirstOrder(rho, time.step = as.difftime(1, units = "hours"), 8 | max.tao = as.difftime(1, units = "days")) 9 | } 10 | \arguments{ 11 | \item{rho}{the covariance asdefined as difference between the times divided by the time step} 12 | 13 | \item{time.step}{default is 1 hour} 14 | 15 | \item{max.tao}{don't consider covariance for values further apart then this.} 16 | } 17 | \value{ 18 | covariance defined as difference between the times divided by the time step don't calculate covariance for 19 | values further away then max.tao. 20 | } 21 | \description{ 22 | get rho matrix first order 23 | } 24 | -------------------------------------------------------------------------------- /man/getCormatTaoBand.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/covariance.R 3 | \name{getCormatTaoBand} 4 | \alias{getCormatTaoBand} 5 | \title{Same idea as getCormatCustom(rho1DayBand, dates) but runs faster.} 6 | \usage{ 7 | getCormatTaoBand(max.tao = as.difftime(1, units = "days")) 8 | } 9 | \arguments{ 10 | \item{max.tao}{length of the covariance band, defaults to 1 day} 11 | } 12 | \value{ 13 | matrix of the covariances 14 | } 15 | \description{ 16 | getcormatTaoBand 17 | } 18 | \details{ 19 | calculate the covariance 1 if dates are within the tao band, 0 if they are 20 | not Same idea as cormatrix(rho1DayBand, dates) but runs in linear instead of 21 | quadratic time - a big and much-needed improvement. 22 | } 23 | -------------------------------------------------------------------------------- /man/getCorrectionFraction.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/loadComp.R 3 | \name{getCorrectionFraction} 4 | \alias{getCorrectionFraction} 5 | \alias{getCorrectionFraction.loadComp} 6 | \title{The fraction of prediction that is due to a correction.} 7 | \usage{ 8 | getCorrectionFraction(load.model, flux.or.conc = c("flux", "conc"), 9 | newdata, ...) 10 | 11 | \method{getCorrectionFraction}{loadComp}(load.model, 12 | flux.or.conc = c("flux", "conc"), newdata, na.rm = FALSE, ...) 13 | } 14 | \arguments{ 15 | \item{load.model}{The load model from which to pull the correction fraction.} 16 | 17 | \item{flux.or.conc}{character. Should the metric be computed with respect to 18 | predictions of flux rate or concentration?} 19 | 20 | \item{newdata}{The data for which to compute the correction fraction, usually 21 | containing daily or instantaneous discharge.} 22 | 23 | \item{...}{Other arguments passed to class-specific implementations of 24 | getCorrectionFraction.} 25 | 26 | \item{na.rm}{logical. Should predictions with NA values be excluded?} 27 | } 28 | \value{ 29 | A value between 0 and 1 indicating the fraction of total load that is 30 | attributed to a correction. 31 | } 32 | \description{ 33 | Computes the fraction of total concentration or flux prediction that is 34 | attributable to a correction such as the residuals correction of composite 35 | method models. 36 | 37 | \code{\link{loadComp}} models: The correction fraction for a composite method 38 | (\code{loadComp}) model is defined here as: 39 | 40 | \deqn{CF = (\sum |R| \Delta t) / (\sum L \Delta t)} 41 | 42 | where \eqn{\sum} indicates a sum over all predictions, \eqn{L} is the vector 43 | of composite predictions of flux or concentration, \eqn{R} is the vector of 44 | interpolated residuals in the same format (flux or concentration, non-log 45 | space) as \eqn{L}, and \eqn{\Delta t} is the vector of time periods 46 | represented by the predictions. 47 | } 48 | \seealso{ 49 | Other diagnostics: \code{\link{estimateRho}}, 50 | \code{\link{residDurbinWatson}} 51 | } 52 | \concept{diagnostics} 53 | -------------------------------------------------------------------------------- /man/getDistanceWeightedInterpolation.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/interpolations.R 3 | \name{getDistanceWeightedInterpolation} 4 | \alias{getDistanceWeightedInterpolation} 5 | \title{Generate a distance-weighted interpolation function with the parameters of your choice.} 6 | \usage{ 7 | getDistanceWeightedInterpolation(inv.dist.fun = function(a, b) { 8 | 1/((a - b)^2) }) 9 | } 10 | \arguments{ 11 | \item{inv.dist.fun}{A function to calculate an inverse distance metric. 12 | Should be vectorized such that one of \code{a} or \code{b} may be a vector 13 | when the other is a scalar.} 14 | } 15 | \description{ 16 | Produces an interpolation function of the form described in \link{interpolations}. 17 | } 18 | -------------------------------------------------------------------------------- /man/getFittedModel.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/loadModelInterface.R 3 | \name{getFittedModel} 4 | \alias{getFittedModel} 5 | \title{Retrieve the fitted model, if appropriate, from a loadModel load model} 6 | \usage{ 7 | getFittedModel(load.model) 8 | } 9 | \arguments{ 10 | \item{load.model}{The load model for which to return the inner fitted model.} 11 | } 12 | \value{ 13 | Object of class "function" which 14 | } 15 | \description{ 16 | A function in the loadModelInterface. Takes a load.model and returns a 17 | function to fit a new load.model that is identical in every respect except 18 | its training data and resulting model coefficients or other paramters. The 19 | returned function should accept exactly one argument, the training data, and 20 | should return an object of the same class as load.model. 21 | } 22 | \seealso{ 23 | Other loadModelInterface: \code{\link{estimateMSE}}, 24 | \code{\link{getFittingData}}, 25 | \code{\link{getFittingFunction}}, 26 | \code{\link{getMetadata}}, \code{\link{predictSolute}}, 27 | \code{\link{simulateSolute}}, 28 | \code{\link{summarizeModel}}, 29 | \code{\link{validLoadModelInterface}} 30 | 31 | Other getFittedModel: \code{\link{getFittedModel.loadModel}} 32 | } 33 | \concept{getFittedModel} 34 | \concept{loadModelInterface} 35 | -------------------------------------------------------------------------------- /man/getFittedModel.loadModel.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/loadModel.R 3 | \name{getFittedModel.loadModel} 4 | \alias{getFittedModel.loadModel} 5 | \title{Retrieve the fitted model, if appropriate, from a loadModel load model} 6 | \usage{ 7 | \method{getFittedModel}{loadModel}(load.model) 8 | } 9 | \arguments{ 10 | \item{load.model}{The load model for which to return the inner fitted model.} 11 | } 12 | \description{ 13 | Retrieve the fitted model, if appropriate, from a loadModel load model 14 | } 15 | \seealso{ 16 | Other getFittedModel: \code{\link{getFittedModel}} 17 | } 18 | \concept{getFittedModel} 19 | -------------------------------------------------------------------------------- /man/getFittingData.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/loadModelInterface.R 3 | \name{getFittingData} 4 | \alias{getFittingData} 5 | \title{Extract the data originally used to fit a load model.} 6 | \usage{ 7 | getFittingData(load.model) 8 | } 9 | \arguments{ 10 | \item{load.model}{A load model, implementing the loadModelInterface, for 11 | which to return the fitting data} 12 | } 13 | \value{ 14 | data.frame containing the original fitting data 15 | } 16 | \description{ 17 | A function in the loadModelInterface. 18 | } 19 | \seealso{ 20 | Other loadModelInterface: \code{\link{estimateMSE}}, 21 | \code{\link{getFittedModel}}, 22 | \code{\link{getFittingFunction}}, 23 | \code{\link{getMetadata}}, \code{\link{predictSolute}}, 24 | \code{\link{simulateSolute}}, 25 | \code{\link{summarizeModel}}, 26 | \code{\link{validLoadModelInterface}} 27 | 28 | Other getFittingData: \code{\link{getFittingData.loadModel}} 29 | } 30 | \concept{getFittingData} 31 | \concept{loadModelInterface} 32 | -------------------------------------------------------------------------------- /man/getFittingData.loadModel.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/loadModel.R 3 | \name{getFittingData.loadModel} 4 | \alias{getFittingData.loadModel} 5 | \title{Retrieve the data used to fit the model} 6 | \usage{ 7 | \method{getFittingData}{loadModel}(load.model) 8 | } 9 | \arguments{ 10 | \item{load.model}{A load model, implementing the loadModelInterface, for 11 | which to return the fitting data} 12 | } 13 | \description{ 14 | Retrieve the data used to fit the model 15 | } 16 | \seealso{ 17 | Other getFittingData: \code{\link{getFittingData}} 18 | } 19 | \concept{getFittingData} 20 | -------------------------------------------------------------------------------- /man/getFittingFunction.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/loadModelInterface.R 3 | \name{getFittingFunction} 4 | \alias{getFittingFunction} 5 | \title{Get a function that can be used to refit the load.model with new data.} 6 | \usage{ 7 | getFittingFunction(load.model) 8 | } 9 | \arguments{ 10 | \item{load.model}{The model for which to return a new fitting function.} 11 | } 12 | \value{ 13 | Object of class "function" which 14 | } 15 | \description{ 16 | A function in the loadModelInterface. Takes a load.model and returns a 17 | function to fit a new load.model that is identical in every respect except 18 | its training data and resulting model coefficients or other paramters. The 19 | returned function should accept exactly one argument, the training data, and 20 | should return an object of the same class as load.model. 21 | } 22 | \seealso{ 23 | Other loadModelInterface: \code{\link{estimateMSE}}, 24 | \code{\link{getFittedModel}}, 25 | \code{\link{getFittingData}}, \code{\link{getMetadata}}, 26 | \code{\link{predictSolute}}, 27 | \code{\link{simulateSolute}}, 28 | \code{\link{summarizeModel}}, 29 | \code{\link{validLoadModelInterface}} 30 | 31 | Other getFittingFunction: \code{\link{getFittingFunction.loadModel}} 32 | } 33 | \concept{getFittingFunction} 34 | \concept{loadModelInterface} 35 | -------------------------------------------------------------------------------- /man/getFittingFunction.loadModel.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/loadModel.R 3 | \name{getFittingFunction.loadModel} 4 | \alias{getFittingFunction.loadModel} 5 | \title{Retrieve a fitting function from a loadModel load model} 6 | \usage{ 7 | \method{getFittingFunction}{loadModel}(load.model) 8 | } 9 | \arguments{ 10 | \item{load.model}{The model for which to return a new fitting function.} 11 | } 12 | \description{ 13 | Retrieve a fitting function from a loadModel load model 14 | } 15 | \seealso{ 16 | Other getFittingFunction: \code{\link{getFittingFunction}} 17 | } 18 | \concept{getFittingFunction} 19 | -------------------------------------------------------------------------------- /man/getMetadata.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/loadModelInterface.R 3 | \name{getMetadata} 4 | \alias{getMetadata} 5 | \title{Extract metadata from a load model.} 6 | \usage{ 7 | getMetadata(load.model) 8 | } 9 | \arguments{ 10 | \item{load.model}{A load model, implementing the loadModelInterface, for 11 | which to return the metadata} 12 | } 13 | \value{ 14 | Object of class "metadata" with slots reflecting the metadata for 15 | load.model 16 | } 17 | \description{ 18 | A function in the loadModelInterface. Returns a load model's metadata, 19 | encapsulated as a \code{metadata} object. 20 | } 21 | \seealso{ 22 | Other loadModelInterface: \code{\link{estimateMSE}}, 23 | \code{\link{getFittedModel}}, 24 | \code{\link{getFittingData}}, 25 | \code{\link{getFittingFunction}}, 26 | \code{\link{predictSolute}}, 27 | \code{\link{simulateSolute}}, 28 | \code{\link{summarizeModel}}, 29 | \code{\link{validLoadModelInterface}} 30 | 31 | Other getMetadata: \code{\link{getMetadata.loadModel}}, 32 | \code{\link{getMetadata.loadReg}} 33 | } 34 | \concept{getMetadata} 35 | \concept{loadModelInterface} 36 | -------------------------------------------------------------------------------- /man/getMetadata.loadModel.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/loadModel.R 3 | \name{getMetadata.loadModel} 4 | \alias{getMetadata.loadModel} 5 | \title{Retrieve metadata from a loadModel load model} 6 | \usage{ 7 | \method{getMetadata}{loadModel}(load.model) 8 | } 9 | \arguments{ 10 | \item{load.model}{A load model, implementing the loadModelInterface, for 11 | which to return the metadata} 12 | } 13 | \description{ 14 | Retrieve metadata from a loadModel load model 15 | } 16 | \seealso{ 17 | Other getMetadata: \code{\link{getMetadata.loadReg}}, 18 | \code{\link{getMetadata}} 19 | } 20 | \concept{getMetadata} 21 | -------------------------------------------------------------------------------- /man/getMetadata.loadReg.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/loadReg.R 3 | \name{getMetadata.loadReg} 4 | \alias{getMetadata.loadReg} 5 | \title{Extracts and imports metadata from an rloadest loadReg model into an object of class 6 | "metadata" 7 | #'} 8 | \usage{ 9 | \method{getMetadata}{loadReg}(load.model) 10 | } 11 | \arguments{ 12 | \item{load.model}{a loadReg object} 13 | } 14 | \value{ 15 | Object of class "metadata" with slots modified according to the 16 | metadata contained in load.model 17 | } 18 | \description{ 19 | Extracts and imports metadata from an rloadest loadReg model into an object of class 20 | "metadata" 21 | #' 22 | } 23 | \seealso{ 24 | Other getMetadata: \code{\link{getMetadata.loadModel}}, 25 | \code{\link{getMetadata}} 26 | } 27 | \concept{getMetadata} 28 | -------------------------------------------------------------------------------- /man/getPred_baseflow.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/predictors.R 3 | \name{getPred_baseflow} 4 | \alias{getPred_baseflow} 5 | \title{Create a vector of baseflow rates.} 6 | \usage{ 7 | getPred_baseflow(data, metadata, method = c("hysep", "1p digital filter", 8 | "2p digital filter"), da, select, alpha, BFImax, ...) 9 | } 10 | \arguments{ 11 | \item{data}{data.frame with columns as specified by metadata} 12 | 13 | \item{metadata}{object of class metadata from which Flow and Date columns 14 | will be selected.} 15 | 16 | \item{method}{character naming the method to be used. May be specified by the 17 | first character or characters, e.g., "h", "1", or "2". See details for a 18 | description of each algorithm.} 19 | 20 | \item{da}{numeric, required for method="hysep". As described in 21 | ?DVstats::hysep, 'the drainage area of the basin in square miles.'} 22 | 23 | \item{select}{character, optional argument to method="hysep". As described in 24 | ?DVstats::hysep, 'a character string indicating which method to use for the 25 | baseflow in the output dataset. Must be one of "sliding," "local minimum," 26 | or "fixed." Onle the first letter is required.' See the HYSEP documentation 27 | by Sloto and Crouse at 28 | https://water.usgs.gov/software/HYSEP/code/doc/hysep.pdf for method 29 | descriptions.} 30 | 31 | \item{alpha}{numeric, required argument for \code{method \%in\% c("1p digital 32 | filter","2p digital filter")}. Adjusts the strength of the filter, with 33 | numbers closer to 1 leading to more of total flow being classified as 34 | runoff (non-baseflow). For the 2-parameter digital filter, the default is 35 | 0.98.} 36 | 37 | \item{BFImax}{numeric, required argumend for \code{method=="2p digital 38 | filter"}. The maximum long-term fraction of total streamflow that may be 39 | classified as baseflow. Recommended values are 0.8 for perennial streams 40 | with porous aquifers, 0.50 for ephemeral streams with porous aquifers, and 41 | 0.25 for perennial streams with hard rock aquifers. (Defaults from 42 | https://user.engineering.uiowa.edu/~flood/handouts/ 43 | HO-L17-Baseflow-Separation.pdf)} 44 | 45 | \item{...}{other arguments passed to the specified method (currently only 46 | 'hysep' takes other arguments; see ?DVstats::hysep)} 47 | } 48 | \description{ 49 | Internal for now; not yet ready to be a part of the official API 50 | } 51 | \details{ 52 | Given a dataset with date and flow columns, separates total flow into 53 | baseflow and runoff; returns a vector of baseflow rates. Several methods are 54 | available and can be selected with the "method" argument. All methods assume 55 | that the time series is evenly spaced, and all work better with 56 | higher-resolution data (e.g., hourly or daily rather than weekly or monthly). 57 | 58 | method=="1p digital filter": Uses the one-paramter digital filter described 59 | by Nathan, R.J. and T.A. McMahon, 1990. Evaluation of Automated Techniques 60 | for Baseflow and Recession Analysis. Water Resources Research, 61 | 26(7):1465-1473. This method requires specification of the \code{alpha} 62 | parameter. 63 | 64 | method=="2p digital filter": Uses the two-parameter digital filter described 65 | by Eckhardt, K., 2005. How to Construct Recursive Digital Filters for 66 | Baseflow Separation. Hydrological Processes, 19(2):507-515. This method 67 | requires specification of the \code{alpha} and \code{BFImax} parameters. 68 | } 69 | \references{ 70 | Implementation of the 1- and 2-parameter digital filters was 71 | aided by the online lecture notes of A. Allen Bradley, Jr. for his Fall 72 | 2013 Hydrology course (https://user.engineering.uiowa.edu/~flood) 73 | } 74 | \seealso{ 75 | Other predictors: \code{\link{getPred_isBaseflow}} 76 | } 77 | \concept{predictors} 78 | \keyword{internal} 79 | -------------------------------------------------------------------------------- /man/getPred_isBaseflow.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/predictors.R 3 | \name{getPred_isBaseflow} 4 | \alias{getPred_isBaseflow} 5 | \title{Create a logical vector indicating whether flow at each time point is 6 | dominantly baseflow.} 7 | \usage{ 8 | getPred_isBaseflow(data, metadata, baseflow, threshold = 0.8) 9 | } 10 | \arguments{ 11 | \item{data}{a data.frame of data including a column for flow (with that 12 | column name specified by metadata).} 13 | 14 | \item{metadata}{a metadata object specifying, at minimum, the column name in 15 | \code{data} where total flow is stored.} 16 | 17 | \item{baseflow}{a vector of baseflow values of the same length as 18 | \code{nrow(data)}.} 19 | 20 | \item{threshold}{numeric. The minimum fraction of flow that must be baseflow 21 | for a time point to be classified as baseflow (TRUE).} 22 | } 23 | \description{ 24 | Internal for now; not yet ready to be a part of the official API 25 | } 26 | \seealso{ 27 | Other predictors: \code{\link{getPred_baseflow}} 28 | } 29 | \concept{predictors} 30 | \keyword{internal} 31 | -------------------------------------------------------------------------------- /man/getResiduals.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/getResiduals.R 3 | \name{getResiduals} 4 | \alias{getResiduals} 5 | \title{getResiduals return the residuals of the load.model} 6 | \usage{ 7 | getResiduals(load.model, flux.or.conc = c("flux", "conc"), 8 | abs.or.rel.resids = c("absolute", "relative"), use.log = FALSE, 9 | newdata = NULL, raw = FALSE) 10 | } 11 | \arguments{ 12 | \item{load.model}{a loadModel descendant} 13 | 14 | \item{flux.or.conc}{The format in which residuals should be calculated} 15 | 16 | \item{abs.or.rel.resids}{Should residuals be computed as the difference 17 | ("absolute") or the ratio ("relative") of the observed and predicted 18 | values?} 19 | 20 | \item{use.log}{logical. Should residuals be computed in log space (TRUE) or 21 | linear space (FALSE)?} 22 | 23 | \item{newdata}{New data for prediction and calculation of residuals} 24 | 25 | \item{raw}{logical. [not yet implemented] If TRUE, the residuals are 26 | calculated for predictions as they emerge from the inner model. If FALSE, 27 | those outputs are retransformed if appropriate (e.g., from log to linear 28 | space) and converted to the specified format (flux or conc).} 29 | } 30 | \value{ 31 | return The residuals between model predictions and the observations 32 | in newdata 33 | } 34 | \description{ 35 | getResiduals return the residuals of the load.model 36 | } 37 | -------------------------------------------------------------------------------- /man/getRhoFirstOrderFun.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/covariance.R 3 | \name{getRhoFirstOrderFun} 4 | \alias{getRhoFirstOrderFun} 5 | \title{Produces a function that uses a first-order autocorrelation model to estimate 6 | the correlation between two dates.} 7 | \usage{ 8 | getRhoFirstOrderFun(rho, time.step = as.difftime(1, units = "hours")) 9 | } 10 | \arguments{ 11 | \item{rho}{The coefficient of the first-order autocorrelation model, either 12 | asserted by the user or estimated by \code{\link{estimateRho}}.} 13 | 14 | \item{time.step}{difftime. The time.step of the time series used to estimate 15 | \code{rho}. It is essential to use the right units; \code{as.difftime(1, 16 | units="hours")} is quite different from \code{as.difftime(1, 17 | units="days")}.} 18 | } 19 | \value{ 20 | A function that accepts two date arguments and returns the predicted 21 | correlation between those two dates. One of the date arguments may be a 22 | vector as long as the other is scalar. This function takes the form, 23 | \code{function(date1, date2)} with arguments as defined for 24 | \code{\link{rhoEqualDates}} and \code{\link{rho1DayBand}}. 25 | } 26 | \description{ 27 | Produces a function of the form described in \link{correlations-1D}. 28 | 29 | \code{getRhoFirstOrderFun} accepts an assumed or empirically estimated value 30 | of \eqn{\rho} (\code{rho}), the correlation coefficient in the first-order 31 | autocorrelation model: 32 | 33 | \deqn{cor(y(t1), y(t2)) = \rho^\tau} 34 | 35 | where 36 | 37 | \deqn{\tau = y(t2) - y(t1)} 38 | 39 | and \eqn{\tau} is in the same units as those used to estimate \eqn{\rho} 40 | (\code{rho}). To ensure that the units are the same, this function also 41 | accepts a \code{time.step} argument indicating the interval between two 42 | successive values in the time series used to estimate \eqn{\rho} 43 | (\code{rho}). The function returned by \code{getRhoFirstOrderFun} takes 44 | responsibility for matching the units of \code{date1} and \code{date2} to 45 | those of \code{rho}. 46 | } 47 | -------------------------------------------------------------------------------- /man/getSmoothSplineInterpolation.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/interpolations.R 3 | \name{getSmoothSplineInterpolation} 4 | \alias{getSmoothSplineInterpolation} 5 | \title{Generate a smoothing spline function with the parameters of your choice.} 6 | \usage{ 7 | getSmoothSplineInterpolation(...) 8 | } 9 | \arguments{ 10 | \item{...}{any arguments other than \code{x} and \code{y} to be passed to 11 | \code{stats::\link{smooth.spline}}.} 12 | } 13 | \value{ 14 | A function of the form described in \link{interpolations}, i.e., 15 | accepting the arguments \code{dates.in}, \code{y.in}, and \code{dates.out} 16 | and returning predictions from a smooth spline function for \code{y.out}. 17 | That function will use the arguments supplied in \code{...}. 18 | } 19 | \description{ 20 | Produces an interpolation function of the form described in \link{interpolations}. 21 | } 22 | -------------------------------------------------------------------------------- /man/getTriangularInterpolation.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/interpolations.R 3 | \name{getTriangularInterpolation} 4 | \alias{getTriangularInterpolation} 5 | \title{Generate a triangular interpolation function with the parameters of your 6 | choice.} 7 | \usage{ 8 | getTriangularInterpolation(y.mid = 0) 9 | } 10 | \arguments{ 11 | \item{y.mid}{The value or values to which midpoints between observations 12 | should be set. Good choices are: mean(y.in) for stand-alone interpolations; 13 | 0 for composite method interpolations among absolute residuals (in log or 14 | linear space); 1 for composite method interpolations among relative 15 | residuals (again, log or linear space).} 16 | } 17 | \value{ 18 | A function of the form described in \link{interpolations}, i.e., 19 | accepting the arguments \code{dates.in}, \code{y.in}, and \code{dates.out} 20 | and returning predictions from a triangular interpolation function for 21 | \code{y.out}. That function will use the \code{y.mid} argument supplied 22 | here. 23 | } 24 | \description{ 25 | Produces an interpolation function of the form described in 26 | \link{interpolations}. 27 | } 28 | -------------------------------------------------------------------------------- /man/interpModel-class.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/loadInterp.R 3 | \docType{class} 4 | \name{interpModel-class} 5 | \alias{interpModel-class} 6 | \title{loadInterp is a class of load models that hold interpolation functions. 7 | The engine of a loadInterp model.} 8 | \description{ 9 | This is a model class to nest within loadInterp. This class, interpModel, is 10 | lightweight relative to loadInterp: its focus is on the interpolation rather 11 | than on units conversions, fitting, or other things that loadInterp does 12 | better. This is also the class that is produced by a call to the fitting 13 | function stored in loadInterp. 14 | } 15 | \section{Slots}{ 16 | 17 | \describe{ 18 | \item{\code{dates.class}}{Class of the dates.in.} 19 | 20 | \item{\code{dates.in}}{Dates of the y.in data.} 21 | 22 | \item{\code{y.in}}{Data (usually fluxes, concentrations, or residuals) to 23 | interpolate.} 24 | 25 | \item{\code{interp.function}}{Function that accepts arguments \code{dates.in}, 26 | \code{y.in}, and \code{dates.out}, then returns predictions \code{y.out}} 27 | }} 28 | 29 | \seealso{ 30 | Other load.model.fits: \code{\link{compModel-class}} 31 | } 32 | \concept{load.model.fits} 33 | -------------------------------------------------------------------------------- /man/interpolations.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/interpolations.R 3 | \name{interpolations} 4 | \alias{interpolations} 5 | \alias{linearInterpolation} 6 | \alias{triangularInterpolation} 7 | \alias{rectangularInterpolation} 8 | \alias{splineInterpolation} 9 | \alias{smoothSplineInterpolation} 10 | \alias{distanceWeightedInterpolation} 11 | \title{Interpolation functions} 12 | \usage{ 13 | linearInterpolation(dates.in, y.in, dates.out) 14 | 15 | triangularInterpolation(dates.in, y.in, dates.out) 16 | 17 | rectangularInterpolation(dates.in, y.in, dates.out) 18 | 19 | splineInterpolation(dates.in, y.in, dates.out) 20 | 21 | smoothSplineInterpolation(dates.in, y.in, dates.out) 22 | 23 | distanceWeightedInterpolation(dates.in, y.in, dates.out) 24 | } 25 | \arguments{ 26 | \item{dates.in}{A numeric vector desribing the dates for each of the values 27 | in \code{y.in}. Dates are represented as the number of seconds since 1970.} 28 | 29 | \item{y.in}{A vector of values (typically fluxes or concentrations) to 30 | interpolate among.} 31 | 32 | \item{dates.out}{A numeric vector of dates for which the corresponding output 33 | values are to be produced. Dates are represented as the number of seconds 34 | since 1970.} 35 | } 36 | \value{ 37 | A vector of values (typically fluxes or concentrations), in the same 38 | units and on the same scale as the \code{y.in} values, that are the 39 | function's predictions for \code{y.out} at each of the dates in dates.out. 40 | } 41 | \description{ 42 | A set of functions that interpolate a y variable over time. See the 43 | Interpolation Types section for details specific to each function. These 44 | functions are intended for use within \code{\link{loadInterp}} and 45 | \code{\link{loadComp}} models. 46 | } 47 | \details{ 48 | These functions may assume the following without checking: 49 | 50 | \itemize{ 51 | 52 | \item dates.in is sorted chronologically 53 | 54 | \item y.in is sorted by dates.in 55 | 56 | \item dates.in and dates.out are in the same numeric format 57 | 58 | } 59 | 60 | 61 | \code{linearInterpolation} - straight lines from one point in y.in to the 62 | next. 63 | 64 | \code{triangularInterpolation} - connects each successive pair of points 65 | \code{i} and \code{j} by a straight line from \code{(dates.in[i], y.in[i])} 66 | to \code{(mean(dates.in[i], dates.in[j]), 0)} to \code{(dates.in[j], 67 | y.in[j])}. This function was described by Verma et al. 2012 as an option for 68 | residuals interpolation with the composite method. 69 | 70 | \code{rectangularInterpolation} - horizontal lines through each point 71 | connected by vertical lines at the midpoint between each pair of dates. This 72 | function was described and recommended by Verma et al. 2012 as an option for 73 | residuals interpolation with the composite method. 74 | 75 | \code{splineInterpolation} - a smooth curve that runs through each point in 76 | y.in. 77 | 78 | \code{smoothSplineInterpolation} - a smoothing spline that follows the trends 79 | in y.in without passing through each point. This function always uses a fixed 80 | set of arguments for smooth.spline (mostly the defaults), while 81 | \code{\link{getSmoothSplineInterpolation}} can produce a smooth spline 82 | function with the parameters of your choice. 83 | 84 | \code{distanceWeightedInterpolation} - An inverse-distance-weighted average 85 | of y.in at each dates.out point. This function creates a weight for each y.in 86 | based on the distance from dates.in to the values in dates.out. The y.out 87 | prediction for each value of dates.out is then the weighted average of the 88 | y.in values. This function always uses a fixed inverse-distance function (1/(a-b)^2), 89 | while \code{\link{getDistanceWeightedInterpolation}} can apply the 90 | inverse-distance function of your choice. 91 | } 92 | \references{ 93 | Verma, S., M. Markus, and R. A. Cooke. 2012. Development of error 94 | correction techniques for nitrate-N load estimation methods. Journal of 95 | Hydrology 432-433:12-25. 96 | } 97 | \seealso{ 98 | \code{\link{getSmoothSplineInterpolation}} and 99 | \code{\link{getDistanceWeightedInterpolation}} produce interpolation 100 | functions of the form described here, but with flexibility in the values of 101 | arguments passed to the internal workhorse functions. 102 | } 103 | -------------------------------------------------------------------------------- /man/isTimestepRegular.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/diagnostics.R 3 | \name{isTimestepRegular} 4 | \alias{isTimestepRegular} 5 | \title{Check a time series for evenly spaced dates.} 6 | \usage{ 7 | isTimestepRegular(dates, hist = TRUE, tol = .Machine$double.eps^0.5, 8 | handler = stop) 9 | } 10 | \arguments{ 11 | \item{dates}{A time series of dates in any format accepted by \code{diff}.} 12 | 13 | \item{hist}{logical. If the time series is found to be irregular, should this 14 | function print a histogram of the observed time steps?} 15 | 16 | \item{tol}{time step tolerance, the accepatable amount of difference between time steps to still consider them regular.} 17 | 18 | \item{handler}{A function, e.g., \code{stop} or \code{warning}, to be run if 19 | the time series is irregular.} 20 | } 21 | \value{ 22 | TRUE if the time steps in \code{dates} are identical to within the 23 | tolerance set by {tol}, FALSE otherwise. 24 | } 25 | \description{ 26 | Even spacing of dates is required for many tests and assessments of 27 | autocorrelation. This function checks for even spacing to within a specified 28 | tolerance. If spacing is uneven, a histogram is immediately produced (if 29 | \code{hist=TRUE}), and a handling function is run (e.g., to produce an error 30 | or warning, as specified by \code{handler}). 31 | } 32 | -------------------------------------------------------------------------------- /man/loadComp-class.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/loadComp.R 3 | \docType{class} 4 | \name{loadComp-class} 5 | \alias{loadComp-class} 6 | \title{A load model class implementing the composite method for flux estimation.} 7 | \description{ 8 | A load model class implementing the composite method for flux estimation. 9 | } 10 | \seealso{ 11 | Other load.model.classes: \code{\link{loadInterp-class}}, 12 | \code{\link{loadLm-class}}, 13 | \code{\link{loadModel-class}}, 14 | \code{\link{loadReg2-class}} 15 | } 16 | \concept{load.model.classes} 17 | -------------------------------------------------------------------------------- /man/loadComp.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/loadComp.R 3 | \name{loadComp} 4 | \alias{loadComp} 5 | \title{Create a fitted loadComp object.} 6 | \usage{ 7 | loadComp(reg.model, interp.format = c("flux", "conc"), 8 | abs.or.rel.resids = c("absolute", "relative"), use.log = TRUE, 9 | interp.data, interp.function = linearInterpolation, store = c("data", 10 | "fitting.function"), n.iter = 100, MSE.method = "parametric") 11 | } 12 | \arguments{ 13 | \item{reg.model}{The model, usually a regression model, to whose predictions 14 | the residuals corrections should be added.} 15 | 16 | \item{interp.format}{character specifying the load format in which residuals 17 | should be interpolated} 18 | 19 | \item{abs.or.rel.resids}{Should residuals be computed as the difference 20 | ("absolute") or the ratio ("relative") of the observed and predicted 21 | values?} 22 | 23 | \item{use.log}{logical. Should residuals be computed in log space (TRUE) or 24 | linear space (FALSE)?} 25 | 26 | \item{interp.data}{the dataset, possibly differing from 27 | getFittingData(reg.model), from which regression residuals will be 28 | calculated and interpolated.} 29 | 30 | \item{interp.function}{a function accepting args dates.in, y.in, and 31 | dates.out and returning y.out. See \link{interpolations} for pre-defined 32 | options, or write your own having the same form.} 33 | 34 | \item{store}{One or more character strings specifying which information to 35 | write within the model. Options are 'data': the original fitting data; 36 | 'fitting.function': a fitting function that can produce a new loadComp 37 | object from new data (this currently uses the same new data for both 38 | regression calibration and interpolation); 'uncertainty': an estimate of 39 | uncertainty, which can take some time to compute but will permit creation 40 | of uncertainty intervals, etc. in the prediction and aggregation phases.} 41 | 42 | \item{n.iter}{The number of times to repeat the COMPLETE process of [simulate 43 | predictions from the regression model and do leave-one-out cross validation 44 | (for all interpolation data points)]. Each run through the process 45 | generates one estimate of the MSE, from which a mean and SD of the MSE 46 | estimates will be returned.} 47 | 48 | \item{MSE.method}{character. The method by which the model should be 49 | bootstrapped. "non-parametric": resample with replacement from the original 50 | fitting data, refit the model, and make new predictions. "parametric": 51 | resample the model coefficients based on the covariance matrix originally 52 | estimated for those coefficients, then make new predictions.} 53 | } 54 | \value{ 55 | A fitted loadComp model. 56 | } 57 | \description{ 58 | Generates a new model of class loadComp (\code{\link{loadComp-class}}). 59 | loadComps themselves contain two inner load models, one for regression and 60 | one for interpolation of the residuals of the regression predictions. 61 | } 62 | \seealso{ 63 | Other load.model.inits: \code{\link{loadInterp}}, 64 | \code{\link{loadLm}}, \code{\link{loadModel}}, 65 | \code{\link{loadReg2}} 66 | } 67 | \concept{load.model.inits} 68 | -------------------------------------------------------------------------------- /man/loadInterp-class.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/loadInterp.R 3 | \docType{class} 4 | \name{loadInterp-class} 5 | \alias{loadInterp-class} 6 | \title{A load model class specific to interpolations for flux estimation.} 7 | \description{ 8 | loadInterps use a variety of interpolation methods to connect predictions of 9 | y values (usually fluxes, concentrations, or residuals) over time. 10 | } 11 | \section{Slots}{ 12 | 13 | \describe{ 14 | \item{\code{fit}}{the interpolation model to be used.} 15 | 16 | \item{\code{MSE}}{numeric. The mean squared error, i.e., the variance of prediction 17 | errors, probably as estimated by leave-one-out cross validation.} 18 | }} 19 | 20 | \seealso{ 21 | Other load.model.classes: \code{\link{loadComp-class}}, 22 | \code{\link{loadLm-class}}, 23 | \code{\link{loadModel-class}}, 24 | \code{\link{loadReg2-class}} 25 | } 26 | \concept{load.model.classes} 27 | -------------------------------------------------------------------------------- /man/loadInterp.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/loadInterp.R 3 | \name{loadInterp} 4 | \alias{loadInterp} 5 | \title{Create a fitted loadInterp object.} 6 | \usage{ 7 | loadInterp(interp.format = c("flux", "conc"), 8 | interp.function = linearInterpolation, data, metadata, 9 | retrans.function = NULL, store = c("data", "fitting.function", 10 | "uncertainty")) 11 | } 12 | \arguments{ 13 | \item{interp.format}{character. Which sort of observation should the 14 | interpolations be done among?} 15 | 16 | \item{interp.function}{function. The function to use for interpolation. 17 | Pre-defined choices are described in \link{interpolations}; additional 18 | functions may be defined by the user as long as they adhere to the 19 | guidelines given there.} 20 | 21 | \item{data}{data.frame. The data to be interpolated} 22 | 23 | \item{metadata}{metadata, used to access the appropriate columns of data. At 24 | a minimum, \code{metadata} should correctly specify the date column and the 25 | column indicated by \code{interp.format}.} 26 | 27 | \item{retrans.function}{irrelevant to loadInterp and must be NULL. for other 28 | models, permits fitting in log or other transformed spaces.} 29 | 30 | \item{store}{One or more character strings specifying which information to 31 | write within the model. Options are 'data': the original fitting data; 32 | 'fitting.function': a fitting function that can produce a new loadComp 33 | object from new data (this currently uses the same new data for both 34 | regression calibration and interpolation); 'uncertainty': an estimate of 35 | uncertainty, which can take some time to compute but will permit creation 36 | of uncertainty intervals, etc. in the prediction and aggregation phases.} 37 | } 38 | \value{ 39 | A fitted loadInterp model. 40 | } 41 | \description{ 42 | Generates a new model of class loadInterp (\code{\link{loadInterp-class}}) 43 | which can iterpolate among observations of concentration or flux. 44 | } 45 | \details{ 46 | loadInterps are simple load models that predict concentration or flux based 47 | on one or more preceding and following measurements of flux. The specific 48 | interpolation method can be varied; examples include linear, spline, and 49 | triangular interpolations. See \link{interpolations} for the full list of 50 | pre-defined options; others may also be defined by the user. 51 | 52 | loadInterps are currently assumed to have normally distributed residuals. An 53 | unwitting user might violate this assumption without being caught by the 54 | code, so be careful! This assumption is mainly relevant to the calculation of 55 | confidence or prediction intervals. Also, where other models such as loadReg 56 | and loadLm will retransform predictions back into linear space, loadInterps 57 | will not. 58 | } 59 | \seealso{ 60 | Other load.model.inits: \code{\link{loadComp}}, 61 | \code{\link{loadLm}}, \code{\link{loadModel}}, 62 | \code{\link{loadReg2}} 63 | } 64 | \concept{load.model.inits} 65 | -------------------------------------------------------------------------------- /man/loadLm-class.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/loadLm.R 3 | \docType{class} 4 | \name{loadLm-class} 5 | \alias{loadLm-class} 6 | \title{A load model class specific to simple linear models (\code{\link{lm}}s) for 7 | flux estimation.} 8 | \description{ 9 | loadLms can take any lm formula. 10 | } 11 | \section{Slots}{ 12 | 13 | \describe{ 14 | \item{\code{fit}}{the interpolation model to be used.} 15 | 16 | \item{\code{ylog}}{logical. If TRUE, this constitutes affirmation that the values 17 | passed to the left-hand side of the model formula will be in log space. If 18 | missing, the value of \code{ylog} will be inferred from the values of 19 | \code{formula} and \code{y.trans.function}, but be warned that this 20 | inference is fallible.} 21 | }} 22 | 23 | \seealso{ 24 | Other load.model.classes: \code{\link{loadComp-class}}, 25 | \code{\link{loadInterp-class}}, 26 | \code{\link{loadModel-class}}, 27 | \code{\link{loadReg2-class}} 28 | } 29 | \concept{load.model.classes} 30 | -------------------------------------------------------------------------------- /man/loadLm.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/loadLm.R 3 | \name{loadLm} 4 | \alias{loadLm} 5 | \title{Create a fitted loadLm object.} 6 | \usage{ 7 | loadLm(formula, pred.format = c("flux", "conc"), data, metadata, 8 | fitting_function = NULL, y.trans.function = NULL, 9 | retrans.function = exp, store = c("data", "fitting.function"), ylog) 10 | } 11 | \arguments{ 12 | \item{formula}{A formula specifying the linear model to fit.} 13 | 14 | \item{pred.format}{In what format (flux or conc) does the lm object make 15 | predictions when predict.lm() is called?} 16 | 17 | \item{data}{data.frame. The data to be interpolated} 18 | 19 | \item{metadata}{metadata, used to access the appropriate columns of data. At 20 | a minimum, \code{metadata} should correctly specify the date column.} 21 | 22 | \item{fitting_function}{a fitting function that can produce a new loadComp 23 | object from new data (this currently uses the same new data for both 24 | regression calibration and interpolation)} 25 | 26 | \item{y.trans.function}{function that accepts a vector of predictions 27 | straight from the fitted model and retransforms them, if appropriate, to 28 | predictions in linear space and with units of concentration*flow. Because 29 | load models are frequently fit to log(y) ~ ..., the default is 30 | retrans.function=exp. After retrans.function has been applied to the 31 | predictions, the retransformed predictions will automatically undergo 32 | further units conversion from conc*flow to load.rate, according to the 33 | metadata elements conc.units, flow.units, and load.rate.units.} 34 | 35 | \item{retrans.function}{function that accepts a vector of predictions 36 | straight from the fitted model and retransforms them, if appropriate, to 37 | predictions in linear space and with units of concentration*flow. Because 38 | load models are frequently fit to log(y) ~ ..., the default is 39 | retrans.function=exp. After retrans.function has been applied to the 40 | predictions, the retransformed predictions will automatically undergo 41 | further units conversion from conc*flow to load.rate, according to the 42 | metadata elements conc.units, flow.units, and load.rate.units.} 43 | 44 | \item{store}{One or more character strings specifying which information to 45 | write within the model. Options are 'data': the original fitting data; 46 | 'fitting.function': a fitting function that can produce a new loadComp 47 | object from new data} 48 | 49 | \item{ylog}{logical. If TRUE, this constitutes affirmation that the values 50 | passed to the left-hand side of the model formula will be in log space. If 51 | missing, the value of \code{ylog} will be inferred from the values of 52 | \code{formula} and \code{y.trans.function}, but be warned that this 53 | inference is fallible.} 54 | } 55 | \value{ 56 | A fitted loadLm model. 57 | } 58 | \description{ 59 | Generates a new model of class loadInterp (\code{\link{loadLm-class}}) which 60 | can connect observations of concentration or flux using a linear regression 61 | model. 62 | } 63 | \examples{ 64 | data(eg_fitdat, eg_metadata) 65 | no3_lm <- loadLm(formula=log(NO3) ~ log(DISCHARGE) + DATE, pred.format="conc", 66 | data=eg_fitdat, metadata=eg_metadata, retrans=exp) 67 | } 68 | \seealso{ 69 | Other load.model.inits: \code{\link{loadComp}}, 70 | \code{\link{loadInterp}}, \code{\link{loadModel}}, 71 | \code{\link{loadReg2}} 72 | } 73 | \concept{load.model.inits} 74 | -------------------------------------------------------------------------------- /man/loadModel-class.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/loadModel.R 3 | \docType{class} 4 | \name{loadModel-class} 5 | \alias{loadModel-class} 6 | \title{A generic load model class.} 7 | \description{ 8 | Class and function definitions for very generic load models that you can 9 | create with a single function call (\code{\link{loadModel}}) or extend to 10 | more specific model types (e.g., \code{\link{loadInterp}}, 11 | \code{\link{loadReg2}}, \code{\link{loadComp}}) 12 | } 13 | \section{Slots}{ 14 | 15 | \describe{ 16 | \item{\code{fit}}{A statistical model, fit to the data and wrapped by the loadModel 17 | class for additional functionality specific to load models.} 18 | 19 | \item{\code{pred.format}}{A string indicating the format of predictions (flux or 20 | conc).} 21 | 22 | \item{\code{metadata}}{A metadata object describing the load model.} 23 | 24 | \item{\code{data}}{The fitting data for the model (fit).} 25 | 26 | \item{\code{fitting.function}}{The function used to create or recreate the loadModel, 27 | possibly with new fitting data.} 28 | 29 | \item{\code{y.trans.function}}{A function to be applied to the y variable before 30 | fitting the model.} 31 | 32 | \item{\code{retrans.function}}{A function to be applied to the y predictions before 33 | returning their values from \code{predictSolute()}.} 34 | }} 35 | 36 | \seealso{ 37 | Other load.model.classes: \code{\link{loadComp-class}}, 38 | \code{\link{loadInterp-class}}, 39 | \code{\link{loadLm-class}}, \code{\link{loadReg2-class}} 40 | } 41 | \concept{load.model.classes} 42 | -------------------------------------------------------------------------------- /man/loadModel.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/loadModel.R 3 | \name{loadModel} 4 | \alias{loadModel} 5 | \title{Create a fitted loadModel object.} 6 | \usage{ 7 | loadModel(inner.fit.function, pred.format, data, metadata, 8 | y.trans.function = NULL, retrans.function = exp, store = c("data", 9 | "fitting.function")) 10 | } 11 | \arguments{ 12 | \item{inner.fit.function}{function that accepts one argument, a training data 13 | frame, and returns a [re]fitted statistical model, such as an \code{lm}, 14 | relating flux or concentration to predictors in the training data.} 15 | 16 | \item{pred.format}{character string that describes the output of 17 | retrans.function(predict(fit)) [NOT of predictSolute.loadModel(), which can 18 | do either!]} 19 | 20 | \item{data}{data.frame containing the initial training observations} 21 | 22 | \item{metadata}{An object of class \code{\link{metadata}}} 23 | 24 | \item{y.trans.function}{function that accepts a vector of observed response 25 | values (e.g., concentrations or flux rates) and transforms them into the 26 | values on the left-hand side of the calibration formula. Because load 27 | models are frequently fit to log(y) ~ ..., the default is 28 | y.trans.function=log.} 29 | 30 | \item{retrans.function}{function that accepts a vector of predictions 31 | straight from the fitted model and retransforms them, if appropriate, to 32 | predictions in linear space and with units of concentration*flow. Because 33 | load models are frequently fit to log(y) ~ ..., the default is 34 | retrans.function=exp. After retrans.function has been applied to the 35 | predictions, the retransformed predictions will automatically undergo 36 | further units conversion from conc*flow to load.rate, according to the 37 | metadata elements conc.units, flow.units, and load.rate.units.} 38 | 39 | \item{store}{One or more character strings specifying which information to 40 | write within the model. Options are 'data': the original fitting data; 41 | 'fitting.function': a fitting function that can produce a new loadComp 42 | object from new data} 43 | } 44 | \value{ 45 | A fitted loadModel. 46 | } 47 | \description{ 48 | Generates a new model of class loadModel (\code{\link{loadModel-class}}). 49 | } 50 | \seealso{ 51 | Other load.model.inits: \code{\link{loadComp}}, 52 | \code{\link{loadInterp}}, \code{\link{loadLm}}, 53 | \code{\link{loadReg2}} 54 | } 55 | \concept{load.model.inits} 56 | -------------------------------------------------------------------------------- /man/loadModelInterface.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/loadModelInterface.R 3 | \docType{data} 4 | \name{loadModelInterface} 5 | \alias{loadModelInterface} 6 | \title{Functions implemented by any \code{loadflex}-compatible load model.} 7 | \format{A collection of functions which any load model for use with 8 | \code{loadflex} should implement.} 9 | \description{ 10 | Solute load models in the \code{loadflex} package, such as \code{loadModel}, 11 | \code{loadReg2}, and \code{loadComp}, all implement a common set of core 12 | functions. These functions are conceptually packaged as the 13 | \code{loadModelInterface} defined here. 14 | } 15 | \section{Functions in the interface}{ 16 | \itemize{ \item 17 | \code{\link{getMetadata}(load.model) \{ return(metadata) \}} \item 18 | \code{\link{getFittingData}(load.model) \{ return(data.frame) \}} \item 19 | \code{\link{getFittingFunction}(load.model) \{ return(function) \}} \item 20 | \code{\link{predictSolute}(load.model, flux.or.conc, newdata, interval, 21 | level, se.fit, se.pred, attach.units, ...) \{ return(numeric vector or 22 | data.frame) \}} } 23 | } 24 | 25 | \section{Defining new load models}{ 26 | Users may define additional custom load 27 | models for use with \code{loadflex} as long as those models, too, implement 28 | the loadModelInterface. One easy way to implement the interface is to write 29 | the new load model class so that it inherits from the 30 | \code{\link{loadModel}} class. 31 | 32 | If a new load model class is defined, the user may confirm that the new 33 | class implements the loadModelInterface by running 34 | \code{\link{validLoadModelInterface}}. 35 | } 36 | 37 | -------------------------------------------------------------------------------- /man/loadReg2-class.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/loadReg2.R 3 | \docType{class} 4 | \name{loadReg2-class} 5 | \alias{loadReg2-class} 6 | \title{A load model class specific to loadReg objects produced by the USGS rloadest 7 | package.} 8 | \description{ 9 | This class is closely related to loadModel except that the model slot is more 10 | strictly defined, and the associated methods are a little different. 11 | } 12 | \seealso{ 13 | Other load.model.classes: \code{\link{loadComp-class}}, 14 | \code{\link{loadInterp-class}}, 15 | \code{\link{loadLm-class}}, \code{\link{loadModel-class}} 16 | } 17 | \concept{load.model.classes} 18 | -------------------------------------------------------------------------------- /man/loadflex-deprecated-data.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/deprecated.R 3 | \name{loadflex-deprecated-data} 4 | \alias{loadflex-deprecated-data} 5 | \title{Renamed or deprecated datasets for the \pkg{loadflex} package} 6 | \description{ 7 | These datasets have been renamed or removed from the package. 8 | } 9 | \section{Datasets}{ 10 | 11 | 12 | \itemize{ 13 | 14 | \item There aren't any deprecated or defunct datasets yet. 15 | 16 | } 17 | } 18 | 19 | \seealso{ 20 | loadflex-deprecated 21 | } 22 | -------------------------------------------------------------------------------- /man/loadflex-deprecated-internal.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/deprecated.R, R/unit.conversions.R 3 | \name{loadflex-deprecated-internal} 4 | \alias{loadflex-deprecated-internal} 5 | \alias{generateUnitsData} 6 | \title{Deprecated internal functions in the \pkg{loadflex} package} 7 | \usage{ 8 | generateUnitsData() 9 | } 10 | \description{ 11 | These functions were formerly private functions in loadflex but are now 12 | deprecated and may be removed in the future. See the Details section for 13 | suggestion on where to look instead. 14 | } 15 | \details{ 16 | \code{generateUnitsData} (defunct as of v1.2.0) has been replaced by the 17 | script at data-raw/createUnitsData.R 18 | } 19 | \keyword{internal} 20 | -------------------------------------------------------------------------------- /man/loadflex-deprecated.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/deprecated.R, R/examples.R 3 | \name{loadflex-deprecated} 4 | \alias{loadflex-deprecated} 5 | \alias{exampleMetadata} 6 | \title{Deprecated functions in the \pkg{loadflex} package} 7 | \usage{ 8 | exampleMetadata() 9 | } 10 | \description{ 11 | These functions were formerly part of loadflex but are now deprecated and may 12 | be removed in the future. See the Details section for suggestion on where to 13 | look instead. 14 | } 15 | \details{ 16 | \code{exampleMetadata} has been replaced by \code{data(eg_metadata)} 17 | } 18 | \seealso{ 19 | loadflex-deprecated-data 20 | } 21 | -------------------------------------------------------------------------------- /man/loadflex.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/loadflex.R 3 | \docType{package} 4 | \name{loadflex} 5 | \alias{loadflex} 6 | \alias{loadflex-package} 7 | \title{Models and Tools for Watershed Flux Estimates} 8 | \description{ 9 | Models and Tools for Watershed Flux Estimates 10 | } 11 | \section{Models}{ 12 | 13 | 14 | \itemize{ 15 | 16 | \item Linear and period-weighted interpolations: \code{\link{loadInterp}} 17 | 18 | \item Generic regression-based models: \code{\link{loadModel}} 19 | 20 | \item Regression-based models with rloadest (USGS, from LOADEST): 21 | \code{\link{loadReg2}} 22 | 23 | \item Composite-method-based models: \code{\link{loadComp}} 24 | 25 | } 26 | } 27 | 28 | \section{Predictions}{ 29 | 30 | 31 | \itemize{ 32 | 33 | \item Make predictions at the resolution of the predictor data: 34 | \code{\link{predictSolute}} 35 | 36 | \item Collect predictions into means or totals over longer time periods: 37 | \code{\link{aggregateSolute}} 38 | 39 | } 40 | } 41 | 42 | \section{Installation}{ 43 | 44 | 45 | loadflex makes use of packages that are currently only available from 46 | GitHub or the USGS R package repository. To install these packages, run the 47 | following lines: 48 | 49 | \code{install.packages(c("smwrData", "smwrBase", "smwrGraphs", "smwrStats", 50 | "smwrQW", "rloadest", "unitted"), repos=c("https://owi.usgs.gov/R", 51 | "https://cran.rstudio.com"), dependencies=TRUE, type="both")} 52 | 53 | \code{install.packages(c("car", "dplyr", "ggplot2", "lubridate", "MASS", 54 | "Matrix"), dependencies=TRUE, type="both")} 55 | 56 | You'll also need the `devtools` package; see 57 | \url{https://www.rstudio.com/products/rpackages/devtools/} for special 58 | instructions, and also run this command: 59 | 60 | \code{install.packages("devtools")} 61 | 62 | and lastly run this call to actually install `loadflex`: 63 | 64 | \code{devtools::install_github("USGS-R/loadflex")} 65 | } 66 | 67 | -------------------------------------------------------------------------------- /man/match.arg.loadflex.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/match.arg.loadflex.R 3 | \name{match.arg.loadflex} 4 | \alias{match.arg.loadflex} 5 | \title{Require an argument to match the loadflex conventions for that argument name} 6 | \usage{ 7 | match.arg.loadflex(arg, choices, several.ok = FALSE) 8 | } 9 | \arguments{ 10 | \item{arg}{An argument, passed as a symbol. May be a missing argument to the 11 | calling function.} 12 | 13 | \item{choices}{Optional. A vector of choices, character or logical, that 14 | should be accepted by partial matching.} 15 | 16 | \item{several.ok}{logical. If TRUE, a vector of several choices in \code{arg} 17 | will be accepted and returned as such.} 18 | } 19 | \value{ 20 | The argument after matching to the allowed options for that argument 21 | name. This may differ from the original value of \code{arg} if \code{arg} 22 | is a truncated version of one of the character options for the argument 23 | (identified using \code{pmatch}, as in \code{match.arg}. 24 | } 25 | \description{ 26 | This function is modeled on \code{match.arg}, but it is designed to 27 | facilitate consistency in how argument names are used within the 28 | \code{loadflex} package. 29 | } 30 | \details{ 31 | The key differences between this function and \code{match.arg} are that this 32 | function (1) decides what the available options are without reference to the 33 | defaults defined in the calling function, and (2) permits atomic but 34 | non-character choices. 35 | } 36 | \examples{ 37 | # match.arg.loadflex knows about some variables by their names alone 38 | flux.or.conc="conc"; flux.or.conc <- loadflex:::match.arg.loadflex(flux.or.conc) 39 | attach.units=TRUE; attach.units <- loadflex:::match.arg.loadflex(attach.units) 40 | 41 | # you can also pass in custom choices. as always, partial matching is available 42 | ci.distrib="log"; ci.distrib <- loadflex:::match.arg.loadflex(ci.distrib, c("lognormal","normal")) 43 | } 44 | -------------------------------------------------------------------------------- /man/meltDates.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/plots.R 3 | \name{meltDates} 4 | \alias{meltDates} 5 | \title{Helper function for plotting: melt dates from wide to long format.} 6 | \usage{ 7 | meltDates(plotsols) 8 | } 9 | \arguments{ 10 | \item{plotsols}{A data.frame with a DATE column} 11 | } 12 | \description{ 13 | We definitely don't want to include this function in the official API, so 14 | keeping it internal. 15 | } 16 | \keyword{internal} 17 | -------------------------------------------------------------------------------- /man/metadata-class.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/metadata.R 3 | \docType{class} 4 | \name{metadata-class} 5 | \alias{metadata-class} 6 | \title{Store metadata relevant to a load model.} 7 | \description{ 8 | \code{metadata} objects store metadata for a load model of any type (e.g., 9 | \code{\link{loadModel}}, \code{\link{loadInterp}}, \code{\link{loadReg2}}, or 10 | \code{\link{loadComp}}). See an example object at 11 | \code{data(\link{eg_metadata})}. Metadata can be created and modified by 12 | calls to \code{\link{metadata}} or \code{\link{updateMetadata}}. Values and 13 | relevant information can be accessed by \code{\link{getCol}}, 14 | \code{\link{getUnits}}, or \code{\link{getInfo}}. 15 | } 16 | \section{Slots}{ 17 | 18 | \describe{ 19 | \item{\code{constituent}}{character. The name of the data.frame column describing the 20 | concentration of the solute or material to be modeled.} 21 | 22 | \item{\code{consti.name}}{character. Consituent long name, for use in plots and 23 | reports} 24 | 25 | \item{\code{flow}}{character. The name of the data.frame column describing flow 26 | (discharge)} 27 | 28 | \item{\code{load.rate}}{character. The name of the data.frame column, if it exists, 29 | describing instantaneous load} 30 | 31 | \item{\code{dates}}{character. The name of the data.frame column describing date 32 | and/or time} 33 | 34 | \item{\code{flow.units}}{character. The units in which flow is both input and 35 | exported.} 36 | 37 | \item{\code{conc.units}}{character. The units in which concentration is both input 38 | and exported.} 39 | 40 | \item{\code{load.units}}{character. The units in which load (flux) is both input and 41 | exported.} 42 | 43 | \item{\code{load.rate.units}}{character. The units in which load (flux) is reported 44 | by predict.loadModel().} 45 | 46 | \item{\code{station}}{deprecated. character. A description of the sampling station or 47 | site. It's now recommended to use \code{site.name} and/or \code{site.id} 48 | instead.} 49 | 50 | \item{\code{site.name}}{character. A description of the station or site where the 51 | concentration of the constituent was measured. This slot or \code{site.id} 52 | is a better place for a site identifier than the \code{station} slot, which 53 | is deprecated.} 54 | 55 | \item{\code{site.id}}{character Station ID for the site where the concentration of 56 | the constituent was measured.} 57 | 58 | \item{\code{lat}}{numeric Station latitude where concentration (and possibly also 59 | discharge) was measured.} 60 | 61 | \item{\code{lon}}{numeric Station longitude where concentration (and possibly also 62 | discharge) was measured.} 63 | 64 | \item{\code{basin.area}}{numeric Area of the drainage basin contributing water to the 65 | site where concentrations were measured.} 66 | 67 | \item{\code{flow.site.name}}{character Long name of the station where flow was 68 | monitored, if different from where concentration was monitored (as in 69 | \code{site.name}).} 70 | 71 | \item{\code{flow.site.id}}{character Station ID of the station where flow was 72 | monitored, if different from where concentration was monitored (as in 73 | \code{site.id}).} 74 | 75 | \item{\code{flow.lat}}{numeric Latitude of the station where flow was monitored, if 76 | different from where concentration was monitored (as in \code{site.lat}).} 77 | 78 | \item{\code{flow.lon}}{numeric Longitude of the station where flow was monitored, if 79 | different from where concentration was monitored (as in \code{site.lon}).} 80 | 81 | \item{\code{flow.basin.area}}{numeric Area of the drainage basin contributing water 82 | to the site where flow was monitored, if different from where concentration 83 | was monitored (as in \code{basin.area}).} 84 | 85 | \item{\code{basin.area.units}}{character Units of the values in \code{basin.area} and 86 | \code{flow.basin.area} (must be the same for both). Basin areas are used to 87 | compute yields as loads per contributing (basin) area.} 88 | 89 | \item{\code{custom}}{ANY. Empty by default, but may be modified to store any 90 | additional data the user wants to track.} 91 | }} 92 | 93 | -------------------------------------------------------------------------------- /man/metadata-getters.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/metadata.R 3 | \name{metadata-getters} 4 | \alias{metadata-getters} 5 | \alias{getCol} 6 | \alias{getUnits} 7 | \alias{getInfo} 8 | \title{Access information about a load model.} 9 | \usage{ 10 | getCol(metadata, data, field = c("conc", "flow", "flux rate", "date"), 11 | attach.units = FALSE) 12 | 13 | getUnits(metadata, field = c("conc", "flow", "flux", "flux rate"), 14 | format = NA, stop.on.empty = FALSE) 15 | 16 | getInfo(metadata, field = c("constituent", "consti.name", "flow", 17 | "load.rate", "dates", "conc.units", "flow.units", "load.units", 18 | "load.rate.units", "station", "site.name", "site.id", "lat", "lon", 19 | "basin.area", "flow.site.name", "flow.site.id", "flow.lat", "flow.lon", 20 | "flow.basin.area", "basin.area.units", "custom"), 21 | stop.on.empty = FALSE) 22 | } 23 | \arguments{ 24 | \item{metadata}{a metadata object from which the information will be 25 | retrieved} 26 | 27 | \item{data}{a data.frame from which the data column will be retrieved} 28 | 29 | \item{field}{character string identifying the field to extract. Partial 30 | matching is allowed.} 31 | 32 | \item{attach.units}{logical. If TRUE, the return value will be a 33 | \pkg{\link{unitted}} vector.} 34 | 35 | \item{format}{character. The format in which units should be returned. Set to 36 | 'rloadest' to output units in a format recognized by \code{rloadest}, or 37 | 'EGRET' for crosstalk with that package, or NA to keep units as stored in 38 | 'loadflex'.} 39 | 40 | \item{stop.on.empty}{logical. Stops f the field is empty or non-character} 41 | } 42 | \value{ 43 | \code{getCol} returns the specified column of data as a vector. 44 | 45 | \code{getUnits} returns the specified units as a character string. 46 | 47 | \code{getInfo} returns the miscellaneous information specified by 48 | \code{field}. 49 | } 50 | \description{ 51 | \code{getCol} locates a column of data specified by a field name (conc, flow, 52 | flux rate, or date). 53 | 54 | \code{getUnits} finds the units associated with a data type (conc, flow, 55 | flux, or flux rate). 56 | 57 | \code{getInfo} returns miscellaneous information (station, custom) about a 58 | model. 59 | } 60 | \details{ 61 | These metadata-getters provide a weak wall of abstraction between metadata 62 | and clients of the metadata; more importantly, they do the error checking to 63 | make sure that the designated field or data column exists and return an 64 | informative error if it does not. 65 | } 66 | \examples{ 67 | md <- metadata(constituent="NO3", flow="DISCHARGE", 68 | dates="DATE", conc.units="mg L^-1", flow.units="cfs", load.units="kg", 69 | load.rate.units="kg d^-1", site.name="Lamprey River, NH") 70 | data(lamprey_nitrate) 71 | head(getCol(md, lamprey_nitrate, 'date')) 72 | head(getCol(md, lamprey_nitrate, 'conc')) 73 | md <- metadata(constituent="NO3", flow="DISCHARGE", 74 | dates="DATE", conc.units="mg L^-1", flow.units="cfs", load.units="kg", 75 | load.rate.units="kg d^-1", site.name="Lamprey River, NH") 76 | getUnits(md, 'flow') 77 | md <- metadata(constituent="NO3", flow="DISCHARGE", 78 | dates="DATE", conc.units="mg L^-1", flow.units="cfs", load.units="kg", 79 | load.rate.units="kg d^-1", site.name="Lamprey River, NH") 80 | getInfo(md, 'site.name') 81 | } 82 | \seealso{ 83 | Other metadata: \code{\link{metadata}} 84 | } 85 | \concept{metadata} 86 | -------------------------------------------------------------------------------- /man/observeSolute.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/unit.conversions.R 3 | \name{observeSolute} 4 | \alias{observeSolute} 5 | \title{observeSolute - instantaneous loads or concentrations} 6 | \usage{ 7 | observeSolute(data, flux.or.conc = c("flux", "conc"), metadata, 8 | calculate = isTRUE(flux.or.conc == "flux"), attach.units = FALSE) 9 | } 10 | \arguments{ 11 | \item{data}{data.frame containing, at a minimum, the columns named by 12 | metadata@constituent and metadata@flow} 13 | 14 | \item{flux.or.conc}{character giving the desired output format} 15 | 16 | \item{metadata}{An object of class "metadata" describing the units of flow 17 | (flow.units) and concentration (conc.units) of the input data, and the 18 | desired units of load (load.rate.units) for the output data} 19 | 20 | \item{calculate}{logical. If FALSE, looks for a column containing the output 21 | of interest. If true, uses the other two columns (out of those for conc, 22 | flow, and flux) to calculate the output of interest.} 23 | 24 | \item{attach.units}{logical. If TRUE, the converted observations are returned 25 | with units attached.} 26 | } 27 | \description{ 28 | Calculates observed instantaneous loading rates or concentrations from 29 | observed concentrations, flows, and/or fluxes, with units conversions 30 | according to the supplied metadata. 31 | } 32 | \examples{ 33 | data(eg_metadata) 34 | obs <- data.frame(MyConc=(1:10)/10, MyFlow=rep(10,10), MyFlux=2) # intentionally inconsistent 35 | md <- updateMetadata(eg_metadata, constituent="MyConc", flow="MyFlow", 36 | load.rate="MyFlux", dates="none", flow.units="cms", conc.units="mg/l", 37 | load.units="g", load.rate.units="g/s", custom=NULL) 38 | 39 | observeSolute(obs, "flux", md, attach.units=TRUE) # calculate from conc & flow 40 | observeSolute(obs, "flux", md, calculate=FALSE, attach.units=TRUE) # read flux from data 41 | observeSolute(obs, "conc", md, calculate=TRUE, attach.units=TRUE) # calculate from flow & flux 42 | observeSolute(obs, "conc", md, calculate=FALSE, attach.units=TRUE) # read conc from data 43 | } 44 | \keyword{units} 45 | -------------------------------------------------------------------------------- /man/onBuild.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/aaa_onLoad.R 3 | \name{onBuild} 4 | \alias{onBuild} 5 | \title{On package load, create a private environment in the namespace.} 6 | \usage{ 7 | onBuild() 8 | } 9 | \description{ 10 | Should not be run except on building the package. 11 | } 12 | \keyword{internal} 13 | -------------------------------------------------------------------------------- /man/plotCM.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/plots.R 3 | \name{plotCM} 4 | \alias{plotCM} 5 | \title{Create plots for examining the results from the composite method} 6 | \usage{ 7 | plotCM(flux.or.conc, show.observations, load.model, finalloads, 8 | observations = NULL, composite = TRUE, 9 | linear.interpolation = FALSE, regression = TRUE, xrange = "none", 10 | dateField = "Date", verbose = FALSE) 11 | } 12 | \arguments{ 13 | \item{flux.or.conc}{character indicating whether the plots are of 14 | concentrations or loads, this is used for string concatation to name the 15 | columns of data produced through composite method.} 16 | 17 | \item{show.observations}{true or false display observations or not.} 18 | 19 | \item{load.model}{use this to pull names of date column and constituent name} 20 | 21 | \item{finalloads}{these are the loads or concentrations to plot} 22 | 23 | \item{observations}{these are the observations to plot, if you are plotting 24 | observations} 25 | 26 | \item{composite, }{TRUE or FALSE flag for whether or not to display the 27 | composite results} 28 | 29 | \item{linear.interpolation}{TRUE or FALSE flag for whether or not to display 30 | linear interpolation of the observations} 31 | 32 | \item{regression}{TRUE or FALSE flag for whether or not to display the linear 33 | regression results} 34 | 35 | \item{xrange, }{a user provded range for the xvalues (dates)} 36 | 37 | \item{verbose}{flag for to print for debugging} 38 | } 39 | \description{ 40 | Not sure we want to include this function in the official API, so keeping it 41 | internal for now. 42 | } 43 | \keyword{internal} 44 | -------------------------------------------------------------------------------- /man/plotConcCM.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/plots.R 3 | \name{plotConcCM} 4 | \alias{plotConcCM} 5 | \title{Plot composite method results for concentrations.} 6 | \usage{ 7 | plotConcCM(...) 8 | } 9 | \arguments{ 10 | \item{...}{arguments passed to plotCM} 11 | } 12 | \description{ 13 | Not sure we want to include this function in the official API, so keeping it 14 | internal for now. 15 | } 16 | \keyword{internal} 17 | -------------------------------------------------------------------------------- /man/plotConcResidualsCM.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/plots.R 3 | \name{plotConcResidualsCM} 4 | \alias{plotConcResidualsCM} 5 | \title{Plot concentration residuals.} 6 | \usage{ 7 | plotConcResidualsCM(...) 8 | } 9 | \description{ 10 | Not sure we want to include this function in the official API, so keeping it 11 | internal for now. 12 | } 13 | \keyword{internal} 14 | -------------------------------------------------------------------------------- /man/plotEGRET.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/plotEGRET.R 3 | \name{plotEGRET} 4 | \alias{plotEGRET} 5 | \title{Create an EGRET-style plot} 6 | \usage{ 7 | plotEGRET(plot.name, load.model = NULL, newdata = NULL, data = NULL, 8 | meta = NULL, eList = NULL, moreTitle = "loadflex", 9 | plotFlowNorm = FALSE, ...) 10 | } 11 | \arguments{ 12 | \item{plot.name}{the name of the plot the user wants to create. See Details 13 | for current options. For now, only one allowed at time.} 14 | 15 | \item{load.model}{a load model (loadReg2, loadComp, loadInterp, loadLm, etc.) 16 | whose data and predictions are to be converted to EGRET format} 17 | 18 | \item{newdata}{data.frame of data used to generate predictions from an 19 | already-fitted model} 20 | 21 | \item{data}{data.frame of data used to fit a model. only required if 22 | load.model is omitted} 23 | 24 | \item{meta}{loadflex metadata object; it must include constituent, flow, 25 | dates, conc.units, site.id, and consti.name. only required if load.model is 26 | omitted} 27 | 28 | \item{eList}{an EGRET eList, as output from EGRET or 29 | loadflex::convertToEGRET, to override separate inputs of \code{load.model}, 30 | \code{newdata}, \code{data}, and/or \code{meta}} 31 | 32 | \item{moreTitle}{additional text to include in the fluxBiasMulti plot title. 33 | The EGRET default is "WRTDS", so this changes the default to "loadflex".} 34 | 35 | \item{plotFlowNorm}{logical indicating whether or not to plot the normalized 36 | flow lines. This defaults to FALSE, which overrides the EGRET default TRUE. 37 | Applicable in plotFluxHist and plotConcHist.} 38 | 39 | \item{...}{additional arguments to pass to the plot} 40 | } 41 | \description{ 42 | Use loadflex data frames, but create an EGRET plot. 43 | } 44 | \details{ 45 | EGRET plots that require \code{data, meta}: \itemize{ \item 46 | boxConcMonth \item plotConcTime \item plotConcQ \item plotFluxQ } EGRET 47 | plots that require \code{data, newdata, preds, meta}: \itemize{ \item 48 | boxQTwice \item multiPlotDataOverview \item plotConcTimeDaily \item 49 | plotFluxTimeDaily \item plotConcPred \item plotFluxPred \item plotResidPred 50 | \item plotResidQ \item plotResidTime \item boxResidMonth \item boxConcThree 51 | \item plotConcHist \item plotFluxHist \item fluxBiasMulti } 52 | } 53 | \examples{ 54 | 55 | # Load necessary data + create the appropriate metadata 56 | data(lamprey_nitrate) # interpolation data (grab sample obs) 57 | fitdat <- lamprey_nitrate 58 | 59 | data("lamprey_discharge") 60 | estdat <- lamprey_discharge # estimation data (15 min interval) 61 | estdat <- subset(estdat, DATE < as.POSIXct("2012-10-01 00:00:00", tz="EST5EDT")) 62 | estdat <- estdat[seq(1, nrow(estdat), by=96/4),] # only keep 4 observations per day 63 | 64 | meta <- metadata( 65 | constituent="NO3", 66 | flow="DISCHARGE", 67 | dates="DATE", 68 | conc.units="mg L^-1", 69 | flow.units="cfs", 70 | load.units="kg", 71 | load.rate.units="kg d^-1", 72 | site.name="Lamprey River, NH", 73 | site.id="01073500", 74 | consti.name="Nitrate") 75 | 76 | # Run your model and get your predictions 77 | no3_lm <- loadLm( 78 | formula=log(NO3) ~ log(DISCHARGE), pred.format="conc", 79 | data=fitdat, metadata=meta, retrans=exp) 80 | 81 | # Now you can plot 82 | plotEGRET("boxConcMonth", data = lamprey_nitrate, meta = meta) 83 | plotEGRET("multiPlotDataOverview", load.model=no3_lm, newdata=estdat) 84 | 85 | } 86 | -------------------------------------------------------------------------------- /man/plotLoadResidualsCM.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/plots.R 3 | \name{plotLoadResidualsCM} 4 | \alias{plotLoadResidualsCM} 5 | \title{Plot flux residuals.} 6 | \usage{ 7 | plotLoadResidualsCM(...) 8 | } 9 | \description{ 10 | Not sure we want to include this function in the official API, so keeping it 11 | internal for now. 12 | } 13 | \keyword{internal} 14 | -------------------------------------------------------------------------------- /man/plotLoadsCM.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/plots.R 3 | \name{plotLoadsCM} 4 | \alias{plotLoadsCM} 5 | \title{Plot composite method results for fluxes.} 6 | \usage{ 7 | plotLoadsCM(...) 8 | } 9 | \arguments{ 10 | \item{...}{arguments passed to plotCM} 11 | } 12 | \description{ 13 | Not sure we want to include this function in the official API, so keeping it 14 | internal for now. 15 | } 16 | \keyword{internal} 17 | -------------------------------------------------------------------------------- /man/plotObservationsCM.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/plots.R 3 | \name{plotObservationsCM} 4 | \alias{plotObservationsCM} 5 | \title{Plot observations relevant to the composite method.} 6 | \usage{ 7 | plotObservationsCM(...) 8 | } 9 | \arguments{ 10 | \item{...}{arguments passed to plotCM} 11 | } 12 | \description{ 13 | Not sure we want to include this function in the official API, so keeping it 14 | internal for now. 15 | } 16 | \keyword{internal} 17 | -------------------------------------------------------------------------------- /man/plotResidualsCM.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/plots.R 3 | \name{plotResidualsCM} 4 | \alias{plotResidualsCM} 5 | \title{Plot concentration or flux residuals.} 6 | \usage{ 7 | plotResidualsCM(type, load.model, observations, resids, 8 | dateField = "Date", verbose = FALSE, xObservations = FALSE, 9 | xFlow = FALSE, day.of.year = FALSE) 10 | } 11 | \arguments{ 12 | \item{load.model}{use this to pull names of date column and constituent name} 13 | 14 | \item{observations}{these are the observations to plot the residuals for} 15 | 16 | \item{dateField}{name of the date field in observations} 17 | 18 | \item{verbose}{debugging flag} 19 | 20 | \item{day.of.year}{flag if true will plot residuals by the day of year to,} 21 | 22 | \item{residuals}{the observation residuals} 23 | } 24 | \description{ 25 | Not sure we want to include this function in the official API, so keeping it 26 | internal for now. 27 | } 28 | \keyword{internal} 29 | -------------------------------------------------------------------------------- /man/reSpace.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/text.R 3 | \name{reSpace} 4 | \alias{reSpace} 5 | \alias{.reSpace} 6 | \title{Replace any space or spaces with a single new.space character apiece} 7 | \usage{ 8 | .reSpace(x, new.space = "_", reduce.spaces = FALSE, 9 | old.space = "[[:punct:]|[:blank:]]") 10 | } 11 | \arguments{ 12 | \item{x}{string[s] to be respaced} 13 | 14 | \item{new.space}{character[s] with which to replace spaces} 15 | 16 | \item{reduce.spaces}{logical. Reduce multiple consecutive spaces to a single one?} 17 | 18 | \item{old.space}{regular expression defining space; default includes punctuation, space, and tab} 19 | } 20 | \value{ 21 | The respaced character string 22 | } 23 | \description{ 24 | Replace any space or spaces with a single new.space character apiece 25 | } 26 | \examples{ 27 | loadflex:::.reSpace("this \\t old *!$?# mandolin", reduce.spaces=TRUE) # returns "this_old_mandolin" 28 | } 29 | \keyword{internal} 30 | -------------------------------------------------------------------------------- /man/resampleCoefficients.lm.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/loadLm.R 3 | \name{resampleCoefficients.lm} 4 | \alias{resampleCoefficients.lm} 5 | \title{Resample the coefficients of a linear model (lm)} 6 | \usage{ 7 | resampleCoefficients.lm(fit) 8 | } 9 | \arguments{ 10 | \item{fit}{an lm object whose coefficients should be resampled} 11 | } 12 | \value{ 13 | A new lm object with resampled coefficients such that predict.lm() 14 | will make predictions reflecting those new coefficients. No other 15 | properties of the returned model are guaranteed. 16 | } 17 | \description{ 18 | Returns a new linear model given their original covariance and uncertainty 19 | } 20 | \details{ 21 | (Although the name suggests otherwise, resampleCoefficients is not currently 22 | an S3 generic. You should refer to this function by its complete name.) 23 | } 24 | \references{ 25 | http://www.clayford.net/statistics/simulation-to-represent-uncertainty-in-regression-coefficients/ 26 | } 27 | -------------------------------------------------------------------------------- /man/resampleCoefficients.loadReg.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/loadReg.R 3 | \name{resampleCoefficients.loadReg} 4 | \alias{resampleCoefficients.loadReg} 5 | \title{Resample the coefficients from a loadReg model.} 6 | \usage{ 7 | resampleCoefficients.loadReg(fit, flux.or.conc) 8 | } 9 | \arguments{ 10 | \item{fit}{a loadReg object} 11 | 12 | \item{flux.or.conc}{Should the resampling be done for the coefficients 13 | appropriate to flux or those for concentration?} 14 | } 15 | \value{ 16 | A new loadReg object with resampled coefficients such that one of 17 | predConc or predLoad (corresponding to the value of \code{flux.or.conc}) 18 | will make predictions reflecting those new coefficients. No other 19 | properties of the returned model are guaranteed. 20 | } 21 | \description{ 22 | Dives deep into loadReg objects to replace the coefficients for the purpose 23 | of simulating new predictions. 24 | } 25 | -------------------------------------------------------------------------------- /man/residDurbinWatson.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/diagnostics.R 3 | \name{residDurbinWatson} 4 | \alias{residDurbinWatson} 5 | \title{Test for autocorrelation of residuals} 6 | \usage{ 7 | residDurbinWatson(load.model, flux.or.conc = c("flux", "conc"), 8 | abs.or.rel.resids = c("absolute", "relative"), use.log = FALSE, 9 | newdata = NULL, plot.acf = TRUE, 10 | timestep.tol = .Machine$double.eps^0.5, irregular.timesteps.ok = NA) 11 | } 12 | \arguments{ 13 | \item{load.model}{a loadModel descendant} 14 | 15 | \item{flux.or.conc}{character. The format in which residuals should be 16 | calculated} 17 | 18 | \item{abs.or.rel.resids}{character. Should residuals be computed as the 19 | difference or the ratio of the observed and predicted values?} 20 | 21 | \item{use.log}{logical. use log residuals?} 22 | 23 | \item{newdata}{The data from which to compute residuals; if NULL, the 24 | original fitting data for load.model will be used.} 25 | 26 | \item{plot.acf}{logical. Should the autocorrelation function be plotted?} 27 | 28 | \item{timestep.tol}{the acceptable tolerance for considering timesteps 29 | regular.} 30 | 31 | \item{irregular.timesteps.ok}{logical. If FALSE, this function requires that 32 | the timesteps between observations are identical to one another, and a plot 33 | is generated and an error is thrown if this requirement is not met. If 34 | TRUE, the check is not performed. If NA (the default), the check is 35 | performed but the function proceeds with a warning and no plot if the 36 | timesteps are found to be irregular. Tests of autocorrelation are weak to 37 | wrong when timesteps are irregular, but timesteps are often at least a bit 38 | irregular in the real world.} 39 | } 40 | \value{ 41 | A Durbin-Watson test statistic applied to residuals. 42 | } 43 | \description{ 44 | Extracts residuals from a load.model (where residuals may be for the 45 | calibration data or for a new set of observations). Applies 46 | car::durbinWatsonTest to test for autocorrelation of those residuals. 47 | } 48 | \seealso{ 49 | car::durbinWatsonTest 50 | 51 | Other diagnostics: \code{\link{estimateRho}}, 52 | \code{\link{getCorrectionFraction}} 53 | } 54 | \concept{diagnostics} 55 | -------------------------------------------------------------------------------- /man/rlmetricPPCC.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/loadReg.R 3 | \name{rlmetricPPCC} 4 | \alias{rlmetricPPCC} 5 | \title{Compute the probability plot correlation coefficient of a loadReg fit} 6 | \usage{ 7 | rlmetricPPCC(fit) 8 | } 9 | \arguments{ 10 | \item{fit}{the loadReg lfit or cfit object} 11 | } 12 | \description{ 13 | Helper function to compute the probability plot correlation coefficient as 14 | rloadest does in print.loadReg, lines 141-144 15 | } 16 | \keyword{internal} 17 | -------------------------------------------------------------------------------- /man/rlmetricPVal.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/loadReg.R 3 | \name{rlmetricPVal} 4 | \alias{rlmetricPVal} 5 | \title{Compute the p-value of a loadReg fit} 6 | \usage{ 7 | rlmetricPVal(fit) 8 | } 9 | \arguments{ 10 | \item{fit}{the loadReg lfit or cfit object} 11 | } 12 | \description{ 13 | Helper function to compute the p-value like rloadest does in print.loadReg 14 | } 15 | \keyword{internal} 16 | -------------------------------------------------------------------------------- /man/rlmetricRsq.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/loadReg.R 3 | \name{rlmetricRsq} 4 | \alias{rlmetricRsq} 5 | \title{Compute the [generalized] R squared of a loadReg fit} 6 | \usage{ 7 | rlmetricRsq(fit) 8 | } 9 | \arguments{ 10 | \item{fit}{the loadReg lfit or cfit object} 11 | } 12 | \description{ 13 | Helper function to compute the R squared like rloadest does in print.loadReg 14 | } 15 | \keyword{internal} 16 | -------------------------------------------------------------------------------- /man/sentenceCase.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/text.R 3 | \name{sentenceCase} 4 | \alias{sentenceCase} 5 | \alias{.sentenceCase} 6 | \title{Capitalize first letter of words.} 7 | \usage{ 8 | .sentenceCase(x) 9 | } 10 | \arguments{ 11 | \item{x}{a character vector to convert} 12 | } 13 | \value{ 14 | a character vector with each word having its first letter capitalized 15 | and all others lowercase 16 | } 17 | \description{ 18 | Convert each word in x to have an upper-case first letter and lower-case 19 | subsequent letters. Doesn't make exceptions for articles like "the" or "a". A 20 | word is defined as continuous alpha characters, so "bill's" becomes "Bill'S" 21 | and "u.s.a." becomes "U.S.A". 22 | } 23 | \examples{ 24 | loadflex:::.sentenceCase("the QUICK brown Fox jumped oVer the LaZY doG") 25 | loadflex:::.sentenceCase(c("QUICK brown Fox","LaZY doG")) 26 | loadflex:::.sentenceCase(c("u.s.a.", "u_s_a", "bill's", "3 bears", "2 be or not 2be")) 27 | } 28 | \keyword{internal} 29 | -------------------------------------------------------------------------------- /man/show.loadModel.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/loadModel.R 3 | \docType{methods} 4 | \name{show,loadModel-method} 5 | \alias{show,loadModel-method} 6 | \title{Display a loadModel object} 7 | \usage{ 8 | \S4method{show}{loadModel}(object) 9 | } 10 | \arguments{ 11 | \item{object}{loadModel object to be displayed.} 12 | } 13 | \description{ 14 | This will print a loadModel object to the console and is the default method 15 | used for that process. 16 | } 17 | -------------------------------------------------------------------------------- /man/show.metadata.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/metadata.R 3 | \docType{methods} 4 | \name{show,metadata-method} 5 | \alias{show,metadata-method} 6 | \title{Display a metadata object} 7 | \usage{ 8 | \S4method{show}{metadata}(object) 9 | } 10 | \arguments{ 11 | \item{object}{The metadata object to be displayed} 12 | } 13 | \description{ 14 | Display a metadata object 15 | } 16 | \examples{ 17 | md <- metadata(constituent="NO3", flow="DISCHARGE", 18 | dates="DATE", conc.units="mg L^-1", flow.units="cfs", load.units="kg", 19 | load.rate.units="kg d^-1", site.name="Lamprey River, NH") 20 | show(md) # or just md at the command prompt 21 | } 22 | -------------------------------------------------------------------------------- /man/simulateSolute.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/loadModelInterface.R 3 | \name{simulateSolute} 4 | \alias{simulateSolute} 5 | \title{Simulate solute concentrations based on the model and model uncertainty.} 6 | \usage{ 7 | simulateSolute(load.model, flux.or.conc = c("flux", "conc"), newdata, 8 | method = c("non-parametric", "parametric"), 9 | from.interval = c("confidence", "prediction"), rho, ...) 10 | } 11 | \arguments{ 12 | \item{load.model}{A load model object, typically inheriting from loadModel 13 | and always implementing the loadModelInterface.} 14 | 15 | \item{flux.or.conc}{character. Should the simulations be reported as flux 16 | rates or concentrations?} 17 | 18 | \item{newdata}{An optional data.frame of predictor observations. The column 19 | names in this data.frame must match those specified in the load model's 20 | metadata.} 21 | 22 | \item{method}{character. The method by which the model should be 23 | bootstrapped. "non-parametric": resample with replacement from the original 24 | fitting data, refit the model, and make new predictions. "parametric": 25 | resample the model coefficients based on the covariance matrix originally 26 | estimated for those coefficients, then make new predictions.} 27 | 28 | \item{from.interval}{character. The interval type from which to resample 29 | (simulate) the solute. If "confidence", the regression model coefficients 30 | are resampled from their multivariate normal distribution and predictions 31 | are made from the new coefficients. If "prediction", an additional vector 32 | of noise is added to those "confidence"-based predictions.} 33 | 34 | \item{rho}{An autocorrelation coefficient to assume for the residuals, 35 | applicable when from.interval=="prediction". If rho is missing and 36 | interval=="prediction", rho will be estimated from the residuals calculated 37 | from newdata with the fitted (not yet resampled) load.model.} 38 | 39 | \item{...}{Other arguments passed to inheriting methods} 40 | } 41 | \value{ 42 | A vector or data.frame of predictions, as for the generic 43 | \code{\link{predictSolute}}. The simulated predictions are distributed 44 | according to the uncertainty of the coefficients (if 45 | from.interval=="confidence") and also the estimated natural variability + 46 | measurement error (if from.interval=="prediction"). 47 | } 48 | \description{ 49 | This function is an optional component of the \link{loadModelInterface}. It 50 | is unnecessary for model fitting, assessment, and prediction except when used 51 | in conjunction with the composite method (i.e., within a 52 | \code{\link{loadComp}} model). 53 | } 54 | \seealso{ 55 | Other loadModelInterface: \code{\link{estimateMSE}}, 56 | \code{\link{getFittedModel}}, 57 | \code{\link{getFittingData}}, 58 | \code{\link{getFittingFunction}}, 59 | \code{\link{getMetadata}}, \code{\link{predictSolute}}, 60 | \code{\link{summarizeModel}}, 61 | \code{\link{validLoadModelInterface}} 62 | 63 | Other simulateSolute: \code{\link{simulateSolute.loadLm}}, 64 | \code{\link{simulateSolute.loadModel}}, 65 | \code{\link{simulateSolute.loadReg2}} 66 | } 67 | \concept{loadModelInterface} 68 | \concept{simulateSolute} 69 | -------------------------------------------------------------------------------- /man/simulateSolute.loadLm.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/loadLm.R 3 | \name{simulateSolute.loadLm} 4 | \alias{simulateSolute.loadLm} 5 | \title{Produce a set of predictions that reflect the coefficient uncertainty and 6 | natural variation.} 7 | \usage{ 8 | \method{simulateSolute}{loadLm}(load.model, flux.or.conc = c("flux", 9 | "conc"), newdata, method = c("parametric", "non-parametric"), 10 | from.interval = c("confidence", "prediction"), rho, ...) 11 | } 12 | \arguments{ 13 | \item{load.model}{A loadLm object.} 14 | 15 | \item{flux.or.conc}{character. Should the simulations be reported as flux 16 | rates or concentrations?} 17 | 18 | \item{newdata}{\code{data.frame}, optional. Predictor data. Column names 19 | should match those given in the \code{loadLm} metadata. If 20 | \code{newdata} is not supplied, the original fitting data will be used.} 21 | 22 | \item{method}{character. The method by which the model should be 23 | bootstrapped. "non-parametric": resample with replacement from the original 24 | fitting data, refit the model, and make new predictions. "parametric": 25 | resample the model coefficients based on the covariance matrix originally 26 | estimated for those coefficients, then make new predictions.} 27 | 28 | \item{from.interval}{character. The interval type from which to resample 29 | (simulate) the solute. If "confidence", the regression model coefficients 30 | are resampled from their multivariate normal distribution and predictions 31 | are made from the new coefficients. If "prediction", an additional vector 32 | of noise is added to those "confidence"-based predictions.} 33 | 34 | \item{rho}{An autocorrelation coefficient to assume for the residuals, 35 | applicable when from.interval=="prediction". If rho is missing and 36 | interval=="prediction", rho will be estimated from the residuals calculated 37 | from newdata with the fitted (not yet resampled) load.model.} 38 | 39 | \item{...}{Other arguments passed to inheriting methods} 40 | } 41 | \value{ 42 | A vector of data.frame of predictions, as for the generic 43 | \code{\link{predictSolute}}. 44 | 45 | A vector of predictions that are distributed according to the 46 | uncertainty of the coefficients and the estimated natural variability + 47 | measurement error. 48 | } 49 | \description{ 50 | This function resamples the coefficients from their joint distribution, then 51 | makes predictions whose individual errors are sampled from a time series with 52 | the same first-order autocorrelation as the original series of errors. 53 | } 54 | \seealso{ 55 | Other simulateSolute: \code{\link{simulateSolute.loadModel}}, 56 | \code{\link{simulateSolute.loadReg2}}, 57 | \code{\link{simulateSolute}} 58 | } 59 | \concept{simulateSolute} 60 | -------------------------------------------------------------------------------- /man/simulateSolute.loadModel.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/loadModel.R 3 | \name{simulateSolute.loadModel} 4 | \alias{simulateSolute.loadModel} 5 | \title{Produce a set of predictions that reflect the coefficient uncertainty and 6 | natural variation.} 7 | \usage{ 8 | \method{simulateSolute}{loadModel}(load.model, flux.or.conc = c("flux", 9 | "conc"), newdata, method = c("parametric", "non-parametric"), 10 | from.interval = c("confidence", "prediction"), rho, ...) 11 | } 12 | \arguments{ 13 | \item{load.model}{A loadModel object.} 14 | 15 | \item{flux.or.conc}{character. Should the simulations be reported as flux 16 | rates or concentrations?} 17 | 18 | \item{newdata}{\code{data.frame}, optional. Predictor data. Column names 19 | should match those given in the \code{loadModel} metadata. If 20 | \code{newdata} is not supplied, the original fitting data will be used.} 21 | 22 | \item{method}{character. The method by which the model should be 23 | bootstrapped. "non-parametric": resample with replacement from the original 24 | fitting data, refit the model, and make new predictions. "parametric": 25 | resample the model coefficients based on the covariance matrix originally 26 | estimated for those coefficients, then make new predictions.} 27 | 28 | \item{from.interval}{character. The interval type from which to resample 29 | (simulate) the solute. If "confidence", the regression model coefficients 30 | are resampled from their multivariate normal distribution and predictions 31 | are made from the new coefficients. If "prediction", an additional vector 32 | of noise is added to those "confidence"-based predictions.} 33 | 34 | \item{rho}{An autocorrelation coefficient to assume for the residuals, 35 | applicable when from.interval=="prediction". If rho is missing and 36 | interval=="prediction", rho will be estimated from the residuals calculated 37 | from newdata with the fitted (not yet resampled) load.model.} 38 | 39 | \item{...}{Other arguments passed to inheriting methods} 40 | } 41 | \value{ 42 | A vector of data.frame of predictions, as for the generic 43 | \code{\link{predictSolute}}. 44 | 45 | A vector of predictions that are distributed according to the 46 | uncertainty of the coefficients and the estimated natural variability + 47 | measurement error. 48 | } 49 | \description{ 50 | This function resamples the coefficients from their joint distribution, then 51 | makes predictions whose individual errors are sampled from a time series with 52 | the same first-order autocorrelation as the original series of errors. 53 | } 54 | \seealso{ 55 | Other simulateSolute: \code{\link{simulateSolute.loadLm}}, 56 | \code{\link{simulateSolute.loadReg2}}, 57 | \code{\link{simulateSolute}} 58 | } 59 | \concept{simulateSolute} 60 | -------------------------------------------------------------------------------- /man/simulateSolute.loadReg2.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/loadReg2.R 3 | \name{simulateSolute.loadReg2} 4 | \alias{simulateSolute.loadReg2} 5 | \title{Produce a set of predictions that reflect the coefficient uncertainty and 6 | possibly also natural variation.} 7 | \usage{ 8 | \method{simulateSolute}{loadReg2}(load.model, flux.or.conc = c("flux", 9 | "conc"), newdata, method = c("parametric", "non-parametric"), 10 | from.interval = c("confidence", "prediction"), rho, ...) 11 | } 12 | \arguments{ 13 | \item{load.model}{A loadReg2 object.} 14 | 15 | \item{flux.or.conc}{character. Should the simulations be reported as flux 16 | rates or concentrations?} 17 | 18 | \item{newdata}{\code{data.frame}, optional. Predictor data. Column names 19 | should match those given in the \code{loadReg2} metadata. If 20 | \code{newdata} is not supplied, the original fitting data will be used.} 21 | 22 | \item{method}{character. The method by which the model should be 23 | bootstrapped. "non-parametric": resample with replacement from the original 24 | fitting data, refit the model, and make new predictions. "parametric": 25 | resample the model coefficients based on the covariance matrix originally 26 | estimated for those coefficients, then make new predictions.} 27 | 28 | \item{from.interval}{character. The interval type from which to resample 29 | (simulate) the solute. If "confidence", the regression model coefficients 30 | are resampled from their multivariate normal distribution and predictions 31 | are made from the new coefficients. If "prediction", an additional vector 32 | of noise is added to those "confidence"-based predictions.} 33 | 34 | \item{rho}{An autocorrelation coefficient to assume for the residuals, 35 | applicable when from.interval=="prediction". If rho is missing and 36 | interval=="prediction", rho will be estimated from the residuals calculated 37 | from newdata with the fitted (not yet resampled) load.model.} 38 | 39 | \item{...}{Other arguments passed to inheriting methods} 40 | } 41 | \value{ 42 | A vector of predictions that are distributed according to the 43 | uncertainty of the coefficients and the estimated natural variability + 44 | measurement error. 45 | } 46 | \description{ 47 | This function resamples the coefficients from their joint distribution, then 48 | makes predictions whose individual errors are sampled from a time series with 49 | the same first-order autocorrelation as the original series of errors. 50 | } 51 | \seealso{ 52 | Other simulateSolute: \code{\link{simulateSolute.loadLm}}, 53 | \code{\link{simulateSolute.loadModel}}, 54 | \code{\link{simulateSolute}} 55 | } 56 | \concept{simulateSolute} 57 | -------------------------------------------------------------------------------- /man/summarizeModel.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/loadModelInterface.R 3 | \name{summarizeModel} 4 | \alias{summarizeModel} 5 | \title{Extract model summary statistics} 6 | \usage{ 7 | summarizeModel(load.model, ...) 8 | } 9 | \arguments{ 10 | \item{load.model}{A load model object, typically inheriting from loadModel 11 | and always implementing the loadModelInterface.} 12 | 13 | \item{...}{Other arguments passed to model-specific methods} 14 | } 15 | \description{ 16 | summarizeModel produces a 1-row data.frame of model metrics. The relevant 17 | metrics vary by model type; only the relevant metrics are reported for each 18 | model. 19 | } 20 | \seealso{ 21 | Other loadModelInterface: \code{\link{estimateMSE}}, 22 | \code{\link{getFittedModel}}, 23 | \code{\link{getFittingData}}, 24 | \code{\link{getFittingFunction}}, 25 | \code{\link{getMetadata}}, \code{\link{predictSolute}}, 26 | \code{\link{simulateSolute}}, 27 | \code{\link{validLoadModelInterface}} 28 | 29 | Other summarizeModel: \code{\link{summarizeModel.loadComp}}, 30 | \code{\link{summarizeModel.loadInterp}}, 31 | \code{\link{summarizeModel.loadLm}}, 32 | \code{\link{summarizeModel.loadModel}}, 33 | \code{\link{summarizeModel.loadReg2}} 34 | } 35 | \concept{loadModelInterface} 36 | \concept{summarizeModel} 37 | -------------------------------------------------------------------------------- /man/summarizeModel.loadComp.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/loadComp.R 3 | \name{summarizeModel.loadComp} 4 | \alias{summarizeModel.loadComp} 5 | \title{Extract model summary statistics from a loadComp model} 6 | \usage{ 7 | \method{summarizeModel}{loadComp}(load.model, newdata, 8 | irregular.timesteps.ok = NA, ...) 9 | } 10 | \arguments{ 11 | \item{load.model}{A load model object, typically inheriting from loadModel 12 | and always implementing the loadModelInterface.} 13 | 14 | \item{newdata}{data.frame of data that was/will be used to predict 15 | concentration or load; should be the same as the \code{newdata} argument to 16 | \code{predictSolute}, e.g. a data.frame of daily or instantaneous dates and 17 | discharges.} 18 | 19 | \item{irregular.timesteps.ok}{logical. If FALSE, this function requires that 20 | the timesteps between observations are identical to one another, and a plot 21 | is generated and an error is thrown if this requirement is not met. If 22 | TRUE, the check is not performed. If NA (the default), the check is 23 | performed but the function proceeds with a warning and no plot if the 24 | timesteps are found to be irregular. Tests and estimates of autocorrelation 25 | are weak to wrong when timesteps are irregular, but timesteps are often at 26 | least a bit irregular in the real world.} 27 | 28 | \item{...}{Other arguments passed to model-specific methods} 29 | } 30 | \value{ 31 | Returns a 1-row data frame with the following columns: 32 | \itemize{ 33 | \item \code{site.id} - the unique identifier of the site, as in \code{\link[=metadata]{metadata()}} 34 | \item \code{constituent} - the unique identifier of the constituent, as in 35 | \code{\link[=metadata]{metadata()}} 36 | \item \code{RMSE.lin} or \code{RMSE.log} - the square root of the mean squared error, in 37 | log space (\code{RMSE.log}) if the \code{use.log} equalled \code{TRUE} in the call to 38 | \code{\link[=loadComp]{loadComp()}} that created this model. 39 | \item \code{reg.durbin.watson} - the Durbin Watson test statistic as applied to the 40 | residuals from the regression model fitting process 41 | \item \code{reg.rho} - the autocorrelation coefficient of the residuals from the 42 | regression model fitting process 43 | \item \code{int.durbin.watson} - the Durbin Watson test statistic as applied to the 44 | residuals from the interpolation model fitting process. See 45 | \code{\link[=residDurbinWatson]{residDurbinWatson()}} 46 | \item \code{int.rho} - the autocorrelation coefficient of the residuals from the 47 | interpolation model fitting process. See \code{\link[=estimateRho]{estimateRho()}} 48 | \item \code{correction.frac} - the correction fraction, i.e., the fraction of total 49 | concentration or flux prediction that is attributable to a correction such 50 | as the residuals correction of composite method models. See 51 | \code{\link[=getCorrectionFraction]{getCorrectionFraction()}} 52 | } 53 | } 54 | \description{ 55 | Produce a 1-row data.frame of model metrics. The relevant metrics for 56 | loadComp models include two sets of statistics about autocorrelation (one for 57 | the regression residuals, one for the 'residuals' used to do the composite 58 | correction). 59 | } 60 | \seealso{ 61 | Other summarizeModel: \code{\link{summarizeModel.loadInterp}}, 62 | \code{\link{summarizeModel.loadLm}}, 63 | \code{\link{summarizeModel.loadModel}}, 64 | \code{\link{summarizeModel.loadReg2}}, 65 | \code{\link{summarizeModel}} 66 | } 67 | \concept{summarizeModel} 68 | -------------------------------------------------------------------------------- /man/summarizeModel.loadInterp.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/loadInterp.R 3 | \name{summarizeModel.loadInterp} 4 | \alias{summarizeModel.loadInterp} 5 | \title{Extract model summary statistics from a loadInterp model} 6 | \usage{ 7 | \method{summarizeModel}{loadInterp}(load.model, 8 | irregular.timesteps.ok = NA, ...) 9 | } 10 | \arguments{ 11 | \item{load.model}{A load model object, typically inheriting from loadModel 12 | and always implementing the loadModelInterface.} 13 | 14 | \item{irregular.timesteps.ok}{logical. If FALSE, this function requires that 15 | the timesteps between observations are identical to one another, and a plot 16 | is generated and an error is thrown if this requirement is not met. If 17 | TRUE, the check is not performed. If NA (the default), the check is 18 | performed but the function proceeds with a warning and no plot if the 19 | timesteps are found to be irregular. Tests and estimates of autocorrelation 20 | are weak to wrong when timesteps are irregular, but timesteps are often at 21 | least a bit irregular in the real world.} 22 | 23 | \item{...}{Other arguments passed to model-specific methods} 24 | } 25 | \value{ 26 | Returns a 1-row data frame with the following columns: 27 | \itemize{ 28 | \item \code{site.id} - the unique identifier of the site, as in \code{\link[=metadata]{metadata()}} 29 | \item \code{constituent} - the unique identifier of the constituent, as in 30 | \code{\link[=metadata]{metadata()}} 31 | \item \code{RMSE.lin}- the square root of the mean squared error 32 | \item \code{durbin.watson} - the Durbin Watson test statistic as applied to the 33 | observations used to fit the interpolation model 34 | \item \code{rho}, \code{acf1}, \code{acf1demean}, \code{corlag} - measures of the autocorrelation 35 | of the observations used to fit the model 36 | } 37 | } 38 | \description{ 39 | Produce a 1-row data.frame of model metrics. The relevant metrics for 40 | loadInterp models include RMSE, p-values, and others TBD. 41 | } 42 | \seealso{ 43 | Other summarizeModel: \code{\link{summarizeModel.loadComp}}, 44 | \code{\link{summarizeModel.loadLm}}, 45 | \code{\link{summarizeModel.loadModel}}, 46 | \code{\link{summarizeModel.loadReg2}}, 47 | \code{\link{summarizeModel}} 48 | } 49 | \concept{summarizeModel} 50 | -------------------------------------------------------------------------------- /man/summarizeModel.loadLm.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/loadLm.R 3 | \name{summarizeModel.loadLm} 4 | \alias{summarizeModel.loadLm} 5 | \title{Extract model summary statistics from a loadLm model} 6 | \usage{ 7 | \method{summarizeModel}{loadLm}(load.model, ...) 8 | } 9 | \arguments{ 10 | \item{load.model}{A load model object, typically inheriting from loadModel 11 | and always implementing the loadModelInterface.} 12 | 13 | \item{...}{Other arguments passed to model-specific methods} 14 | } 15 | \value{ 16 | Returns a 1-row data frame with the following columns: 17 | \itemize{ 18 | \item \code{site.id} - the unique identifier of the site, as in \code{\link[=metadata]{metadata()}} 19 | \item \code{constituent} - the unique identifier of the constituent, as in 20 | \code{\link[=metadata]{metadata()}} 21 | \item \code{eqn} - the regression equation, possibly in the form \code{const ~ model(x)} 22 | where \code{x} is the \code{Number} of a pre-defined equation in \link[rloadest:Models]{rloadest::Models} 23 | \item \code{RMSE} - the square root of the mean squared error. Errors will be 24 | computed from either fluxes or concentrations, as determined by the value 25 | of \code{pred.format} that was passed to \code{\link[=loadReg2]{loadReg2()}} when this model was 26 | created 27 | \item \code{r.squared} - the r-squared value, generalized for censored data, 28 | describing the amount of observed variation explained by the model 29 | \item \code{p.value} - the p-value for the overall model fit 30 | \item \code{cor.resid} - the serial correlation of the model residuals 31 | \item \code{PPCC} - the probability plot correlation coefficient measuring the 32 | normality of the residuals 33 | \item \code{Intercept}, \code{lnQ}, \code{lnQ2}, \code{DECTIME}, \code{DECTIME2}, \code{sin.DECTIME}, 34 | \code{cos.DECTIME}, etc. - the fitted value of the intercept and other terms 35 | included in this model (list differs by model equation) 36 | \item \code{Intercept.SE}, \code{lnQ.SE}, \code{lnQ2.SE}, \code{DECTIME.SE}, \code{DECTIME2.SE}, 37 | \code{sin.DECTIME.SE}, \code{cos.DECTIME.SE}, etc. - the standard error of the fitted 38 | estimates of these terms 39 | \item \code{Intercept.p.value}, \code{lnQ.p.value}, \code{lnQ2.p.value}, \code{DECTIME.p.value}, 40 | \code{DECTIME2.p.value}, \code{sin.DECTIME.p.value}, \code{cos.DECTIME.p.value} - the 41 | p-values for each of these model terms 42 | } 43 | 44 | A 1-row data.frame of model metrics 45 | } 46 | \description{ 47 | Produce a 1-row data.frame of model metrics. 48 | } 49 | \examples{ 50 | data(eg_loadLm) 51 | summarizeModel(eg_loadLm) 52 | } 53 | \seealso{ 54 | Other summarizeModel: \code{\link{summarizeModel.loadComp}}, 55 | \code{\link{summarizeModel.loadInterp}}, 56 | \code{\link{summarizeModel.loadModel}}, 57 | \code{\link{summarizeModel.loadReg2}}, 58 | \code{\link{summarizeModel}} 59 | } 60 | \concept{summarizeModel} 61 | -------------------------------------------------------------------------------- /man/summarizeModel.loadModel.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/loadModel.R 3 | \name{summarizeModel.loadModel} 4 | \alias{summarizeModel.loadModel} 5 | \title{Extract model summary statistics from a loadModel model} 6 | \usage{ 7 | \method{summarizeModel}{loadModel}(load.model, ...) 8 | } 9 | \arguments{ 10 | \item{load.model}{A load model object, typically inheriting from loadModel 11 | and always implementing the loadModelInterface.} 12 | 13 | \item{...}{Other arguments passed to model-specific methods} 14 | } 15 | \value{ 16 | A 1-row data.frame of model metrics 17 | } 18 | \description{ 19 | Produce a 1-row data.frame of model metrics. The relevant metrics for 20 | loadModel models include two sets of statistics about autocorrelation (one for 21 | the regression residuals, one for the 'residuals' used to do the composite 22 | correction). 23 | } 24 | \seealso{ 25 | Other summarizeModel: \code{\link{summarizeModel.loadComp}}, 26 | \code{\link{summarizeModel.loadInterp}}, 27 | \code{\link{summarizeModel.loadLm}}, 28 | \code{\link{summarizeModel.loadReg2}}, 29 | \code{\link{summarizeModel}} 30 | } 31 | \concept{summarizeModel} 32 | -------------------------------------------------------------------------------- /man/summarizeModel.loadReg.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/loadReg.R 3 | \name{summarizeModel.loadReg} 4 | \alias{summarizeModel.loadReg} 5 | \title{Extract model summary statistics from an \code{\link[rloadest:loadReg]{rloadest::loadReg()}} model} 6 | \usage{ 7 | \method{summarizeModel}{loadReg}(load.model, flux.or.conc = c("flux", 8 | "conc"), ...) 9 | } 10 | \arguments{ 11 | \item{load.model}{A load model object, typically inheriting from loadModel 12 | and always implementing the loadModelInterface.} 13 | 14 | \item{flux.or.conc}{character. Which internal model (the flux model or the 15 | concentration model) should be summarized? An \link[rloadest:loadReg]{rloadest::loadReg} model is 16 | actually two different models for (1) flux and (2) concentration, each 17 | fitted to the same data and with the same model structure except for 18 | whether the left-hand side of the model formula is flux or concentration. 19 | Some of the model metrics differ between these two internal models.} 20 | 21 | \item{...}{Other arguments passed to model-specific methods} 22 | } 23 | \value{ 24 | Returns a 1-row data frame with the following columns: 25 | \itemize{ 26 | \item \code{eqn} - the regression equation, possibly in the form \code{const ~ model(x)} 27 | where \code{x} is the \code{Number} of a pre-defined equation in \link[rloadest:Models]{rloadest::Models} 28 | \item \code{RMSE} - the square root of the mean squared error. Errors will be 29 | computed from either fluxes or concentrations, as determined by the value 30 | of \code{pred.format} that was passed to \code{\link[=loadReg2]{loadReg2()}} when this model was 31 | created 32 | \item \code{r.squared} - the r-squared value, generalized for censored data, 33 | describing the amount of observed variation explained by the model 34 | \item \code{p.value} - the p-value for the overall model fit 35 | \item \code{cor.resid} - the serial correlation of the model residuals 36 | \item \code{PPCC} - the probability plot correlation coefficient measuring the 37 | normality of the residuals 38 | \item \code{Intercept}, \code{lnQ}, \code{lnQ2}, \code{DECTIME}, \code{DECTIME2}, \code{sin.DECTIME}, 39 | \code{cos.DECTIME}, etc. - the fitted value of the intercept and other terms 40 | included in this model (list differs by model equation) 41 | \item \code{Intercept.SE}, \code{lnQ.SE}, \code{lnQ2.SE}, \code{DECTIME.SE}, \code{DECTIME2.SE}, 42 | \code{sin.DECTIME.SE}, \code{cos.DECTIME.SE}, etc. - the standard error of the fitted 43 | estimates of these terms 44 | \item \code{Intercept.p.value}, \code{lnQ.p.value}, \code{lnQ2.p.value}, \code{DECTIME.p.value}, 45 | \code{DECTIME2.p.value}, \code{sin.DECTIME.p.value}, \code{cos.DECTIME.p.value} - the 46 | p-values for each of these model terms 47 | } 48 | } 49 | \description{ 50 | Produce a 1-row data.frame of model metrics. The relevant metrics for loadReg 51 | models are largely the same as those reported by the \code{rloadest} package, 52 | though reported in this streamlined data.frame format for bulk reporting. 53 | \code{summarizeModel.loadReg} should rarely be accessed directly; instead, call 54 | \code{summarizeModel()} on a \link{loadReg} object. 55 | } 56 | -------------------------------------------------------------------------------- /man/summarizeModel.loadReg2.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/loadReg2.R 3 | \name{summarizeModel.loadReg2} 4 | \alias{summarizeModel.loadReg2} 5 | \title{Extract model summary statistics from a loadReg2 model} 6 | \usage{ 7 | \method{summarizeModel}{loadReg2}(load.model, ...) 8 | } 9 | \arguments{ 10 | \item{load.model}{A load model object, typically inheriting from loadModel 11 | and always implementing the loadModelInterface.} 12 | 13 | \item{...}{Other arguments passed to model-specific methods} 14 | } 15 | \value{ 16 | Returns a 1-row data frame with the following columns: 17 | \itemize{ 18 | \item \code{site.id} - the unique identifier of the site, as in \code{\link[=metadata]{metadata()}} 19 | \item \code{constituent} - the unique identifier of the constituent, as in 20 | \code{\link[=metadata]{metadata()}} 21 | \item \code{eqn} - the regression equation, possibly in the form \code{const ~ model(x)} 22 | where \code{x} is the \code{Number} of a pre-defined equation in \link[rloadest:Models]{rloadest::Models} 23 | \item \code{RMSE} - the square root of the mean squared error. Errors will be 24 | computed from either fluxes or concentrations, as determined by the value 25 | of \code{pred.format} that was passed to \code{\link[=loadReg2]{loadReg2()}} when this model was 26 | created 27 | \item \code{r.squared} - the r-squared value, generalized for censored data, 28 | describing the amount of observed variation explained by the model 29 | \item \code{p.value} - the p-value for the overall model fit 30 | \item \code{cor.resid} - the serial correlation of the model residuals 31 | \item \code{PPCC} - the probability plot correlation coefficient measuring the 32 | normality of the residuals 33 | \item \code{Intercept}, \code{lnQ}, \code{lnQ2}, \code{DECTIME}, \code{DECTIME2}, \code{sin.DECTIME}, 34 | \code{cos.DECTIME}, etc. - the fitted value of the intercept and other terms 35 | included in this model (list differs by model equation) 36 | \item \code{Intercept.SE}, \code{lnQ.SE}, \code{lnQ2.SE}, \code{DECTIME.SE}, \code{DECTIME2.SE}, 37 | \code{sin.DECTIME.SE}, \code{cos.DECTIME.SE}, etc. - the standard error of the fitted 38 | estimates of these terms 39 | \item \code{Intercept.p.value}, \code{lnQ.p.value}, \code{lnQ2.p.value}, \code{DECTIME.p.value}, 40 | \code{DECTIME2.p.value}, \code{sin.DECTIME.p.value}, \code{cos.DECTIME.p.value} - the 41 | p-values for each of these model terms 42 | } 43 | } 44 | \description{ 45 | Produce a 1-row data.frame of model metrics. The relevant metrics for 46 | loadReg2 models are largely the same as those reported by the \code{rloadest} 47 | package, though reported in this streamlined data.frame format for bulk 48 | reporting. \code{summarizeModel.loadReg2} should rarely be accessed directly; 49 | instead, call \code{summarizeModel()} on a \link{loadReg2} object. 50 | } 51 | \examples{ 52 | \dontrun{ 53 | library(rloadest) 54 | no3_lr <- suppressWarnings( 55 | loadReg2(loadReg(NO3 ~ model(9), data=get(data(lamprey_nitrate)), 56 | flow="DISCHARGE", dates="DATE", time.step="instantaneous", 57 | flow.units="cfs", conc.units="mg/L", load.units="kg", 58 | station='Lamprey River, NH'))) 59 | summarizeModel(no3_lr) 60 | } 61 | } 62 | \seealso{ 63 | Other summarizeModel: \code{\link{summarizeModel.loadComp}}, 64 | \code{\link{summarizeModel.loadInterp}}, 65 | \code{\link{summarizeModel.loadLm}}, 66 | \code{\link{summarizeModel.loadModel}}, 67 | \code{\link{summarizeModel}} 68 | } 69 | \concept{summarizeModel} 70 | -------------------------------------------------------------------------------- /man/summarizeTimeseries.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/summarizeData.R 3 | \name{summarizeTimeseries} 4 | \alias{summarizeTimeseries} 5 | \title{Get summary statistics for a single input data.frame} 6 | \usage{ 7 | summarizeTimeseries(metadata, data) 8 | } 9 | \arguments{ 10 | \item{metadata}{object of class metadata, describing the site and data} 11 | 12 | \item{data}{data.frame of input data, either for model fitting (concentration 13 | and discharge) or prediction (discharge only)} 14 | } 15 | \value{ 16 | data frame of statistics about the input data 17 | } 18 | \description{ 19 | Get summary statistics for a single input data.frame 20 | } 21 | \keyword{internal} 22 | -------------------------------------------------------------------------------- /man/transformDates.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/plots.R 3 | \name{transformDates} 4 | \alias{transformDates} 5 | \title{Helper function for plotting: transform dates from something to something.} 6 | \usage{ 7 | transformDates(plotsols) 8 | } 9 | \arguments{ 10 | \item{plotsols}{A data.frame with a DATE column} 11 | } 12 | \value{ 13 | same data.frame but with DATE field converted to POSIXct or lt 14 | } 15 | \description{ 16 | We definitely don't want to include this function in the official API, so 17 | keeping it internal. 18 | } 19 | \keyword{internal} 20 | -------------------------------------------------------------------------------- /man/translateFreeformToUnitted.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/unit.conversions.R 3 | \name{translateFreeformToUnitted} 4 | \alias{translateFreeformToUnitted} 5 | \title{Convert units from a greater variety of forms, including rloadest form, to 6 | unitted form} 7 | \usage{ 8 | translateFreeformToUnitted(freeform.units, attach.units = FALSE) 9 | } 10 | \arguments{ 11 | \item{freeform.units}{character string or list of character strings 12 | describing one or more sets of units. "Freeform" is an exaggeration but 13 | gets at the idea that these units can take a greater variety of forms than 14 | those accepted by unitted and the units conversion functions in 15 | \code{loadflex}.} 16 | 17 | \item{attach.units}{logical. If TRUE, returned value is unitted; otherwise, 18 | it's character.} 19 | } 20 | \value{ 21 | a unitbundle or list of unitbundles containing equivalent but simpler 22 | and more uniform units 23 | } 24 | \description{ 25 | Convert units from a greater variety of forms, including rloadest form, to 26 | unitted form 27 | } 28 | \examples{ 29 | loadflex:::translateFreeformToUnitted("cfs") # "ft^3 s^-1" 30 | loadflex:::translateFreeformToUnitted("kg/d") # "kg d^-1" 31 | loadflex:::translateFreeformToUnitted("mg L^-1") # "mg L^-1" 32 | } 33 | -------------------------------------------------------------------------------- /man/unitType.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/unit.conversions.R 3 | \name{unitType} 4 | \alias{unitType} 5 | \title{Return the unit.type of a unit string} 6 | \usage{ 7 | unitType(unitstr) 8 | } 9 | \arguments{ 10 | \item{unitstr}{A string representing units (just one at a time, please)} 11 | } 12 | \description{ 13 | Return the unit.type of a unit string 14 | } 15 | \examples{ 16 | loadflex:::unitType('kg') # 'load.units' 17 | loadflex:::unitType('kg/d') # NA 18 | loadflex:::unitType(loadflex:::translateFreeformToUnitted('kg/d')) # 'load.rate.units' 19 | loadflex:::unitType('nothing') # NA 20 | } 21 | -------------------------------------------------------------------------------- /man/units_loadflex.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/unit.conversions.R 3 | \docType{data} 4 | \name{units_loadflex} 5 | \alias{units_loadflex} 6 | \alias{valid.metadata.units} 7 | \alias{freeform.unit.translations} 8 | \alias{unit.conversions} 9 | \title{Units-related datasets for the \pkg{loadflex} package} 10 | \description{ 11 | These datasets are provided for managing units within the 12 | \pkg{loadflex} package. It is recommended NOT to use these datasets 13 | directly within your code, as they may change structure or contents in the 14 | future. 15 | } 16 | \section{Datasets}{ 17 | 18 | 19 | \describe{ 20 | 21 | \item{\code{valid.metadata.units}}{A data.frame with character columns 22 | "unit", "standard", and "dimension". Used (1) to determine whether units in 23 | slots of a `metadata` object have the appropriate dimensionality; e.g., 24 | \code{conc.units} must have dimensions of mass or count per volume, and (2) 25 | to convert among units of the same dimensionality.} 26 | 27 | \item{\code{freeform.unit.translations}}{A data.frame with character 28 | columns "new" and "old". Used for mapping freeform units ("old") to the 29 | specific format required by \pkg{loadflex} ("new").} 30 | 31 | \item{\code{unit.conversions}}{A data.frame with character columns 32 | "numerator", "denominator", and numeric column "value", one conversion per 33 | row. Used for converting among } 34 | 35 | } 36 | } 37 | 38 | -------------------------------------------------------------------------------- /man/validDim.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/unit.conversions.R 3 | \name{validDim} 4 | \alias{validDim} 5 | \title{Determine whether a 1D dimension string is known and of the expected 6 | dimension type} 7 | \usage{ 8 | validDim(dimstr, dim.type = c("ANY", "volume", "time", "mass", "count", 9 | "area")) 10 | } 11 | \arguments{ 12 | \item{dimstr}{A string representing one units dimension (just one at a time, 13 | please). For example: kg, d, or m^3, but not kg/d or d^-1} 14 | 15 | \item{dim.type}{One or more acceptable dimension types} 16 | } 17 | \description{ 18 | Determine whether a 1D dimension string is known and of the expected 19 | dimension type 20 | } 21 | \examples{ 22 | loadflex:::validDim('kg') # TRUE 23 | loadflex:::validDim('kg', 'mass') # TRUE 24 | loadflex:::validDim('kg', 'volume') # FALSE 25 | loadflex:::validDim('whoknows') # FALSE 26 | loadflex:::validDim('whoknows', 'time') # FALSE 27 | } 28 | -------------------------------------------------------------------------------- /man/validLoadModelInterface.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/loadModelInterface.R 3 | \name{validLoadModelInterface} 4 | \alias{validLoadModelInterface} 5 | \title{Test whether a class implements the loadModelInterface} 6 | \usage{ 7 | validLoadModelInterface(object, stop.on.error = TRUE, verbose = TRUE) 8 | } 9 | \arguments{ 10 | \item{object}{an object with a LoadModelInterface} 11 | 12 | \item{stop.on.error}{logical. If the interface is invalid, should the 13 | function throw an error (TRUE) or quietly return a warning object (FALSE)?} 14 | 15 | \item{verbose}{logical. turn on or off verbose messages.} 16 | } 17 | \value{ 18 | TRUE if interface for given load.model is well defined; otherwise, 19 | either throws an error (if stop.on.error=TRUE) or returns a vector of 20 | character strings describing the errors (if stop.on.error=FALSE). 21 | } 22 | \description{ 23 | \code{validLoadModelInterface} can be used to test whether the 24 | \code{\link{loadModelInterface}} has been successfully implemented for the class of a 25 | provided object. 26 | } 27 | \seealso{ 28 | Other loadModelInterface: \code{\link{estimateMSE}}, 29 | \code{\link{getFittedModel}}, 30 | \code{\link{getFittingData}}, 31 | \code{\link{getFittingFunction}}, 32 | \code{\link{getMetadata}}, \code{\link{predictSolute}}, 33 | \code{\link{simulateSolute}}, 34 | \code{\link{summarizeModel}} 35 | } 36 | \concept{loadModelInterface} 37 | -------------------------------------------------------------------------------- /man/validMetadataUnits.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/unit.conversions.R 3 | \name{validMetadataUnits} 4 | \alias{validMetadataUnits} 5 | \title{Check whether these units are acceptable (without translation) for inclusion in metadata} 6 | \usage{ 7 | validMetadataUnits(unitstr, unit.type = c("ANY", "flow.units", 8 | "conc.units", "load.units", "load.rate.units", "basin.area.units")) 9 | } 10 | \arguments{ 11 | \item{unitstr}{A string representing units (just one bundle at a time, please)} 12 | 13 | \item{unit.type}{string. accepts "ANY","flow.units","conc.units","load.units", or "load.rate.units"} 14 | 15 | \item{type}{A string describing the type of units desired} 16 | } 17 | \value{ 18 | logical. TRUE if valid for that unit type, FALSE otherwise 19 | } 20 | \description{ 21 | Check whether these units are acceptable (without translation) for inclusion in metadata 22 | } 23 | \examples{ 24 | validMetadataUnits("colonies d^-1") # TRUE 25 | validMetadataUnits("m^3 s^-1", unit.type="ANY") # TRUE 26 | validMetadataUnits("nonsensical") # FALSE 27 | validMetadataUnits("g", unit.type="load.units") # TRUE 28 | validMetadataUnits("g", unit.type="flow.units") # FALSE 29 | } 30 | \keyword{units} 31 | -------------------------------------------------------------------------------- /tests/testthat.R: -------------------------------------------------------------------------------- 1 | library(testthat) 2 | library(loadflex) 3 | 4 | test_check('loadflex', filter='01') 5 | test_check('loadflex', filter='02') 6 | # test_check('loadflex', filter='03') # breaks 7 | # test_check('loadflex', filter='04') # takes forever & has interaction 8 | # test_check('loadflex', filter='05') # segfault on travis (not appveyor or local) 9 | # test_check('loadflex', filter='06') # just a shell of a test now 10 | test_check('loadflex', filter='11') 11 | test_check('loadflex', filter='21') 12 | test_check('loadflex', filter='22') 13 | test_check('loadflex', filter='23') 14 | # test_check('loadflex', filter='24') # takes forever 15 | # test_check('loadflex', filter='25') # breaks 16 | test_check('loadflex', filter='31') # loadReg() call is commented out 17 | # test_check('loadflex', filter='32') # loadReg() call is integral to test, probably causes segfault on travis 18 | # test_check('loadflex', filter='33') # loadReg() calls are integral to test, probably cause segfault on travis 19 | test_check('loadflex', filter='41') 20 | # test_check('loadflex', filter='42') # empty test 21 | test_check('loadflex', filter='44') 22 | test_check('loadflex', filter='51') 23 | 24 | # test_check('loadflex', filter='01|02|05|06|11|21|22|23|31|32|33|41|42') 25 | -------------------------------------------------------------------------------- /tests/testthat/helpers.R: -------------------------------------------------------------------------------- 1 | #' Suppresses only those warnings given in messages; warnings must be presented 2 | #' in number and order expected. 3 | library(evaluate) 4 | gives_exact_warnings <- function(regexp) { 5 | function(expr) { 6 | res <- evaluate(substitute(expr), parent.frame(), new_device = FALSE) 7 | warnings <- vapply(Filter(is.warning, res), "[[", "message", 8 | FUN.VALUE = character(1)) 9 | errors <- vapply(Filter(is.error, res), "[[", "message", 10 | FUN.VALUE = character(1)) 11 | if(length(errors) > 0) { 12 | stop(errors) 13 | } else if (!is.null(regexp) && length(warnings) > 0) { 14 | matches(regexp, all = TRUE)(warnings) 15 | } 16 | else { 17 | expectation(length(warnings) > 0, "no warnings given") 18 | } 19 | } 20 | } 21 | 22 | library(ggplot2) 23 | 24 | # A helper function for testing: passes if the user looks at the plot and 25 | # presses enter, fails if the user enters anything else 26 | expect_manual_OK <- function(test.id, prompt="Look at the plot.") { 27 | #user.input <- readline(paste0("Test '",test.id, "': ", prompt, " Hit ENTER for OK; enter any character otherwise: ")) 28 | user.gives.OK <- TRUE 29 | expect_true(user.gives.OK, label=paste0("Test '",test.id,"' okayed by user")) 30 | } 31 | # A test for expect_manual_OK: 32 | # test_that("expect_manual_OK makes sense as a helper function", { 33 | # plot(1:25, pch=1:25) 34 | # expect_manual_OK(1) 35 | # 36 | # print(data.frame(x=1:3,y=6:8)) 37 | # expect_manual_OK("'data.frame looks good'", "Look at the table. ") 38 | # }) 39 | -------------------------------------------------------------------------------- /tests/testthat/test-01-match.arg.loadflex.R: -------------------------------------------------------------------------------- 1 | context("match.arg.loadflex") 2 | 3 | tryCatch({source("tests/testthat/helpers.R"); source("helpers.R")}, warning=function(w) invisible()) 4 | 5 | test_that("loadflex:::match.arg.loadflex knows the defaults for many args", { 6 | 7 | # Passes when given acceptable answers 8 | expect_true((function(flux.or.conc){loadflex:::match.arg.loadflex(flux.or.conc); return(TRUE)})("flux")) 9 | expect_true((function(pred.format){loadflex:::match.arg.loadflex(pred.format); return(TRUE)})("flux")) 10 | expect_true((function(interp.format){loadflex:::match.arg.loadflex(interp.format); return(TRUE)})("flux")) 11 | expect_true((function(interval){loadflex:::match.arg.loadflex(interval); return(TRUE)})("confidence")) 12 | expect_true((function(abs.or.rel.resids){loadflex:::match.arg.loadflex(abs.or.rel.resids); return(TRUE)})("relative")) 13 | expect_true((function(attach.units){loadflex:::match.arg.loadflex(attach.units); return(TRUE)})(FALSE)) 14 | 15 | # Throws error when arg isn't one of the options 16 | expect_error((function(flux.or.conc){loadflex:::match.arg.loadflex(flux.or.conc); return(TRUE)})("wronganswer"), "should be one of") 17 | expect_error((function(pred.format){loadflex:::match.arg.loadflex(pred.format); return(TRUE)})("wronganswer"), "should be one of") 18 | expect_error((function(interp.format){loadflex:::match.arg.loadflex(interp.format); return(TRUE)})("wronganswer"), "should be one of") 19 | expect_error((function(interval){loadflex:::match.arg.loadflex(interval); return(TRUE)})("wronganswer"), "should be one of") 20 | expect_error((function(abs.or.rel.resids){loadflex:::match.arg.loadflex(abs.or.rel.resids); return(TRUE)})("wronganswer"), "should be one of") 21 | expect_error((function(attach.units){loadflex:::match.arg.loadflex(attach.units); return(TRUE)})("wronganswer"), "should be one of") 22 | 23 | }) 24 | 25 | test_that("loadflex:::match.arg.loadflex can handle manually specified args", { 26 | 27 | expect_true((function(any.arg){loadflex:::match.arg.loadflex(any.arg, c(1,4,NA)); return(TRUE)})(1)) 28 | expect_error((function(any.arg){loadflex:::match.arg.loadflex(any.arg, c(1,4,NA)); return(TRUE)})(0), "should be one of") 29 | 30 | }) 31 | 32 | test_that("loadflex:::match.arg.loadflex can handle multiple args", { 33 | 34 | # Should reject 2 answers when several.ok==FALSE, accept them when several.ok==TRUE, reject answers that aren't in the choices 35 | expect_error((function(any.arg){loadflex:::match.arg.loadflex(any.arg, c(1,4,NA), several.ok=FALSE)})(c(NA,1))) 36 | expect_equal((function(any.arg){loadflex:::match.arg.loadflex(any.arg, c(1,4,NA), several.ok=TRUE)})(c(NA,1)), c(NA,1)) 37 | 38 | # If one but not all of the values supplied are in the choices, those that 39 | # overlap are returned without error. Not sure this is optimal, but it's 40 | # consistent with match.arg 41 | expect_false(length((function(any.arg){loadflex:::match.arg.loadflex(any.arg, c(1,4,NA), several.ok=TRUE)})(c(17,NA))) == 2) 42 | expect_false(length((function(any.arg){match.arg(any.arg, c("1","4","NA"), several.ok=TRUE)})(c("17","4"))) == 2) 43 | 44 | }) -------------------------------------------------------------------------------- /tests/testthat/test-02-text.R: -------------------------------------------------------------------------------- 1 | context("text") 2 | 3 | tryCatch({source("tests/testthat/helpers.R"); source("helpers.R")}, warning=function(w) invisible()) 4 | 5 | test_that(".sentenceCase works", { 6 | 7 | expect_equal(loadflex:::.sentenceCase("hark the herald"), "Hark The Herald") 8 | expect_equal(loadflex:::.sentenceCase("Hark tHE heRald"), "Hark The Herald") 9 | expect_equal(loadflex:::.sentenceCase(c("QUICK brown Fox","LaZY doG")), c("Quick Brown Fox","Lazy Dog")) 10 | 11 | }) 12 | 13 | 14 | test_that(".reSpace works", { 15 | 16 | expect_equal(loadflex:::.reSpace(" angles sing GLORIA", new.space="_"), "_angles_sing___GLORIA") 17 | expect_equal(loadflex:::.reSpace(" angles sing GLORIA", new.space="_", reduce.spaces=TRUE), "angles_sing_GLORIA") 18 | expect_equal(loadflex:::.reSpace(" angles sing GLORIA", new.space="*|", reduce.spaces=TRUE), "angles*|sing*|GLORIA") 19 | expect_equal(loadflex:::.reSpace("^Shalom^aleichem^*#)", old.space="[[:punct:]|[:blank:]]"), "_Shalom_aleichem____") 20 | 21 | }) 22 | -------------------------------------------------------------------------------- /tests/testthat/test-04-uncertainty.R: -------------------------------------------------------------------------------- 1 | context("uncertainty") 2 | 3 | tryCatch({source("tests/testthat/helpers.R"); source("helpers.R")}, warning=function(w) invisible()) 4 | 5 | test_that("it's easy to get log-to-linear transformations of distribution moments", { 6 | # meanlin, sdlin, meanlog, and sdlog args work, and the outputs are a 7 | # reasonable and informatively named data.frame 8 | expect_equal(linToLog(meanlin=1, sdlin=0.5), data.frame(meanlog=-0.1115718, sdlog=0.472380), tol=0.00001) 9 | expect_equal(logToLin(meanlog=1, sdlog=0.5), data.frame(meanlin= 3.0802170, sdlin=1.641572), tol=0.00001) 10 | 11 | # meanlin, sdlin, meanlog, and sdlog args work, and you can go round trip from 12 | # log to lin to log or from lin to log to lin 13 | expect_equivalent(logToLin(ms=linToLog(meanlin=1, sdlin=0.5)), list(1,0.5)) 14 | expect_equivalent(linToLog(ms=logToLin(meanlog=1, sdlog=0.5)), list(1,0.5)) 15 | 16 | # mslist args work, and you can go round trip from log to lin to log or from 17 | # lin to log to lin 18 | expect_equivalent(logToLin(ms=linToLog(ms=logToLin(ms=linToLog(ms=list(1,1))))), list(1,1)) 19 | expect_equivalent(linToLog(ms=logToLin(ms=linToLog(ms=logToLin(ms=list(0,1))))), list(0,1)) 20 | 21 | # you may supply more than one sd 22 | expect_equal(logToLin(ms=linToLog(meanlin=9, sdlin=c(1,3,5))), data.frame(meanlin=9, sdlin=c(1,3,5))) 23 | expect_equal(linToLog(ms=logToLin(meanlog=9, sdlog=c(1,3,5))), data.frame(meanlog=9, sdlog=c(1,3,5))) 24 | 25 | # mixed conversion 26 | linparams <- data.frame(meanlin=1, sdlin=0.5) 27 | logparams <- linToLog(ms=linparams) 28 | expect_equal(mixedToLog(meanlin=linparams$meanlin, sdlog=logparams$sdlog), data.frame(meanlog=-0.1115718, sdlog=0.472380), tol=0.00001) 29 | expect_equal(logToLin(ms=mixedToLog(meanlin=linparams$meanlin, sdlog=logparams$sdlog)), linparams, tol=0.00001) 30 | 31 | }) 32 | -------------------------------------------------------------------------------- /tests/testthat/test-23-1-interpolations.R: -------------------------------------------------------------------------------- 1 | tryCatch({source("tests/testthat/helpers.R"); source("helpers.R")}, warning=function(w) invisible()) 2 | 3 | # A helper function to test each type of interpolation 4 | checkInterpPreds <- function(interp.fun) { 5 | # data for calibration of the interpolation models 6 | mydat <- data.frame( 7 | conc=c(1.3,-0.5,0,1.2,-0.1,1.4,-2.3,-0.4,0.7,0.5), 8 | datetime=strptime(paste0("2000-05-",1:10),format="%Y-%m-%d")) 9 | mymd <- metadata( 10 | constituent="conc", flow="discharge", load.rate="", dates="datetime", 11 | conc.units="mg/L", flow.units="cfs", load.units="kg", load.rate.units="kg/day", 12 | station="", custom=NULL) 13 | 14 | # data for prediction (interpolation) 15 | mydat2 <- data.frame(datetime=strptime(paste0("2000-05-",rep(1:10, each=24)," ",rep(0:23, 10)),format="%Y-%m-%d %H")) 16 | 17 | # Fit an interpolation model & make predictions 18 | lic <- loadInterp(interp.format="conc", data=mydat, interp.function=interp.fun, metadata=mymd) 19 | preds <- data.frame(mydat2, conc=predictSolute(lic, "conc", newdata=mydat2)) 20 | 21 | # Make and plot the predictions and the original data 22 | #print(ggplot(preds, aes(x=datetime, y=conc)) + 23 | # geom_point(color="pink") + geom_line(color="pink") + 24 | # geom_point(data=mydat, shape=2, size=3, color="blue") + theme_bw()) 25 | 26 | # Get the tester's OK 27 | expect_manual_OK(paste0(as.character(substitute(interp.fun))[1],"s (pink) look good with respect to observations (blue)")) 28 | } 29 | 30 | test_that("linearInterpolations look like they should", { 31 | checkInterpPreds(linearInterpolation) 32 | }) 33 | test_that("triangularInterpolations look like they should", { 34 | checkInterpPreds(triangularInterpolation) 35 | checkInterpPreds(getTriangularInterpolation(0)) 36 | checkInterpPreds(getTriangularInterpolation(0.75)) 37 | }) 38 | test_that("rectangularInterpolations look like they should", { 39 | checkInterpPreds(rectangularInterpolation) 40 | }) 41 | test_that("splineInterpolations look like they should", { 42 | checkInterpPreds(splineInterpolation) 43 | }) 44 | test_that("smoothSplineInterpolations look like they should", { 45 | checkInterpPreds(smoothSplineInterpolation) 46 | checkInterpPreds(getSmoothSplineInterpolation(df=3)) 47 | checkInterpPreds(getSmoothSplineInterpolation(df=8)) 48 | checkInterpPreds(getSmoothSplineInterpolation(spar=0.6)) 49 | checkInterpPreds(getSmoothSplineInterpolation(spar=0.15)) 50 | }) 51 | test_that("distanceWeightedInterpolations look like they should", { 52 | checkInterpPreds(distanceWeightedInterpolation) 53 | checkInterpPreds(getDistanceWeightedInterpolation(inv.dist.fun=function(a,b) { 1 / abs(a-b) })) # neat! 54 | checkInterpPreds(getDistanceWeightedInterpolation(inv.dist.fun=function(a,b) { exp(-abs(a-b)/20000) })) # quite sensitive to the 20000 55 | checkInterpPreds(getDistanceWeightedInterpolation(inv.dist.fun=function(a,b) { 1 / ((a-b)^4) })) 56 | }) 57 | 58 | 59 | 60 | -------------------------------------------------------------------------------- /tests/testthat/test-24-1-loadReg.R: -------------------------------------------------------------------------------- 1 | context("loadReg() is defined within rloadest. The functions required to implement loadModelInterface are defined in loadReg.R within the current package.") 2 | tryCatch({source("tests/testthat/helpers.R"); source("helpers.R")}, warning=function(w) invisible()) 3 | 4 | #' loadReg() is defined within rloadest. The functions required to implement 5 | #' loadModelInterface are defined in loadReg.R within the current package. 6 | library(rloadest) 7 | 8 | test_that("loadReg models can be created", { 9 | 10 | suppressWarnings(rm(simpledata)) #make sure it's not defined elsewhere 11 | simpledata <- transform(app2.calib[-which(diff(app2.calib$DATES) < 7),], 12 | Period=seasons(DATES,breaks=c("Apr", "Jul"))) 13 | 14 | # Fit the model 15 | load.model <- loadReg( 16 | Atrazine ~ Period*center(log(FLOW)), 17 | data = simpledata, 18 | flow = "FLOW", dates = "DATES", conc.units="mg/L") 19 | 20 | expect_is(load.model, "loadReg") 21 | 22 | }) 23 | 24 | test_that("metadata can be extracted from loadReg models", { 25 | 26 | library(rloadest) 27 | # Sample data & model 28 | simpledata <- transform(app2.calib[-which(diff(app2.calib$DATES) < 7),], Period=seasons(DATES,breaks=c("Apr", "Jul"))) 29 | load.model <- loadReg( 30 | Atrazine ~ Period*center(log(FLOW)), 31 | data = simpledata, 32 | flow = "FLOW", dates = "DATES", conc.units="mg/L") 33 | 34 | expect_equal(getMetadata(load.model), 35 | metadata(constituent = "Atrazine", flow="FLOW", load.rate="", dates="DATES", conc.units="mg L^-1", 36 | flow.units="s^-1 ft^3", load.units="kg", load.rate.units="kg/day", station="")) 37 | 38 | }) 39 | 40 | 41 | test_that("resampleCoefficients.loadReg looks OK", { 42 | 43 | # Sample data & model 44 | library(rloadest) 45 | simpledata <- transform(app2.calib[-which(diff(app2.calib$DATES) < 7),], Period=seasons(DATES,breaks=c("Apr", "Jul"))) 46 | load.model <- loadReg( 47 | Atrazine ~ Period*center(log(FLOW)), 48 | data = simpledata, 49 | flow = "FLOW", dates = "DATES", conc.units="mg/L") 50 | 51 | # resample 1000 times and plot the resampled coefficients 52 | new_coefs <- setNames(data.frame(t(replicate(n=1000, coef(resampleCoefficients.loadReg(load.model, "flux"))))), c("intercept","period","flow","periodflow")) 53 | #print(ggplot(new_coefs, aes(x=intercept, y=period, color=flow)) + geom_point() + theme_bw()) 54 | # repeat, but for flux 55 | new_coefs <- setNames(data.frame(t(replicate(n=1000, coef(resampleCoefficients.loadReg(load.model, "conc"), which="conc")))), c("intercept","period","flow","periodflow")) 56 | #print(ggplot(new_coefs, aes(x=intercept, y=period, color=flow)) + geom_point() + theme_bw()) 57 | # library(lattice) 58 | # cloud(intercept ~ dtsimple * discharge, data=new_coefs, alpha=0.6) 59 | 60 | # check against covariance matrix 61 | SCV <- load.model$cfit$SCV 62 | NPAR <- load.model$cfit$NPAR 63 | GAMMA <- SCV[1:NPAR,NPAR+1]/SCV[NPAR+1,NPAR+1] 64 | C <- SCV[1:NPAR,1:NPAR] - SCV[NPAR+1,NPAR+1]*(GAMMA %*% t(GAMMA)) 65 | dimnames(C) <- list(c("intercept","period","flow","periodflow"), c("intercept","period","flow","periodflow")) 66 | S2 <- load.model$cfit$PARMLE[NPAR+1]/(1+load.model$cfit$BIAS[NPAR+1]) 67 | #print(cov.scaled <- S2*C) 68 | #expect_manual_OK("resampled coefficients follow the expected covariance structure") 69 | }) -------------------------------------------------------------------------------- /tests/testthat/test-31-loadModelInterface.R: -------------------------------------------------------------------------------- 1 | context("load model interface") 2 | test_that("validLoadModelInterface reports validity for all base load model types", { 3 | 4 | # Verbose mode is nice if you're running this manually 5 | verbose <- FALSE 6 | 7 | # Made-up data and metadata 8 | mydat <- data.frame(conc=c(5,4,2,6,9,8,9,7,4,3),discharge=10+rnorm(10,0,0.2),datetime=seq(as.Date("2000-05-01"), by="7 days", length.out=10)) 9 | mymd <- metadata( 10 | constituent="conc", flow="discharge", load.rate="", dates="datetime", 11 | conc.units="mg/L", flow.units="cfs", load.units="kg", load.rate.units="kg/day", 12 | station="", custom=NULL) 13 | 14 | # loadModel 15 | load.model <- loadModel( 16 | inner.fit.function=function(training.data) { lm(conc ~ discharge, data=training.data) }, 17 | pred.format="conc", data=mydat, metadata=mymd) 18 | expect_true(validLoadModelInterface(load.model, verbose=verbose)) 19 | 20 | # loadLm 21 | load.lm <- loadLm( 22 | formula=log(conc) ~ discharge, 23 | pred.format="conc", data=mydat, metadata=mymd) 24 | expect_true(validLoadModelInterface(load.lm, verbose=verbose)) 25 | 26 | # loadReg2 - segfaults on travis 27 | # library(rloadest) 28 | # load.reg2 <- loadReg2(loadReg( 29 | # conc ~ model(2), data = mydat, 30 | # flow = "discharge", dates = "datetime", conc.units="mg/L")) 31 | # expect_true(validLoadModelInterface(load.reg2, verbose=verbose)) 32 | 33 | # loadInterp 34 | load.interp <- loadInterp( 35 | interp.format="conc", data=mydat, 36 | interp.function=linearInterpolation, metadata=mymd) 37 | expect_true(validLoadModelInterface(load.interp, verbose=verbose)) 38 | 39 | # loadComp 40 | load.comp <- loadComp( 41 | reg.model=load.lm, interp.format="flux", 42 | interp.data=mydat, interp.function=linearInterpolation, n.iter = 0) 43 | expect_true(validLoadModelInterface(load.comp, verbose=verbose)) 44 | 45 | }) -------------------------------------------------------------------------------- /tests/testthat/test-32-getResiduals.R: -------------------------------------------------------------------------------- 1 | context("getResiduals") 2 | test_that("getResiduals works", { 3 | library(rloadest) 4 | simpledata <- transform(app2.calib[-which(diff(app2.calib$DATES) < 7),], 5 | Period=seasons(DATES,breaks=c("Apr", "Jul"))) 6 | reg.model <- loadReg2(loadReg( 7 | Atrazine ~ Period*center(log(FLOW)), 8 | data = simpledata, 9 | flow = "FLOW", dates = "DATES", conc.units="mg/L")) 10 | 11 | # get residuals from fitting data 12 | expect_equal(dim(getResiduals(reg.model)), c(27,2)) 13 | 14 | # get residuals from new data 15 | app2.calib2 <- transform(app2.calib, Period=seasons(DATES,breaks=c("Apr", "Jul"))) 16 | expect_equal(dim(getResiduals(reg.model, newdata=app2.calib2)), c(32,2)) 17 | 18 | # fail elegantly to get residuals from data that don't have observations 19 | app2.calib3 <- app2.calib2[c("DATES","TIMES","FLOW","Period")] 20 | expect_error(getResiduals(reg.model, newdata=app2.calib3), "'Atrazine'") 21 | 22 | # check that flux residuals and conc residuals can be calculated from one 23 | # another if computed as absolutes in linear space 24 | residmetadata <- updateMetadata(getMetadata(reg.model), load.rate="Resid", constituent="Resid") 25 | abslinflux <- getResiduals(reg.model, "flux", abs.or.rel.resids="absolute", use.log=FALSE) 26 | abslinconc <- getResiduals(reg.model, "conc", abs.or.rel.resids="absolute", use.log=FALSE) 27 | expect_equal(observeSolute(data.frame(FLOW=simpledata$FLOW, abslinflux), "conc", meta=residmetadata, calculate=TRUE), 28 | abslinconc$Resid) 29 | expect_equal(observeSolute(data.frame(FLOW=simpledata$FLOW, abslinconc), "flux", meta=residmetadata, calculate=TRUE), 30 | abslinflux$Resid) 31 | 32 | # check that flux & conc residuals equal one another if computed as absolutes 33 | # in log space, or as relatives in linear space 34 | abslinflux <- getResiduals(reg.model, "flux", abs.or.rel.resids="absolute", use.log=TRUE) 35 | abslinconc <- getResiduals(reg.model, "conc", abs.or.rel.resids="absolute", use.log=TRUE) 36 | expect_equal(abslinflux$Resid, abslinconc$Resid) 37 | abslinflux <- getResiduals(reg.model, "flux", abs.or.rel.resids="relative", use.log=FALSE) 38 | abslinconc <- getResiduals(reg.model, "conc", abs.or.rel.resids="relative", use.log=FALSE) 39 | expect_equal(abslinflux$Resid, abslinconc$Resid) 40 | 41 | # it's pretty strange to use relative AND logged flux & conc residuals. it 42 | # can be done, but i don't recommend it 43 | abslinflux <- getResiduals(reg.model, "flux", abs.or.rel.resids="relative", use.log=TRUE) 44 | abslinconc <- getResiduals(reg.model, "conc", abs.or.rel.resids="relative", use.log=TRUE) 45 | #plot(abslinconc$Resid ~ abslinflux$Resid) # see how strange? 46 | }) -------------------------------------------------------------------------------- /tests/testthat/test-41-predictors.R: -------------------------------------------------------------------------------- 1 | context("predictors") 2 | tryCatch({source("tests/testthat/helpers.R"); source("helpers.R")}, warning=function(w) invisible()) 3 | 4 | library(rloadest) 5 | data(app2.est) 6 | data(eg_metadata) 7 | md <- updateMetadata(eg_metadata, flow="FLOW", dates="DATES") 8 | library(ggplot2) 9 | 10 | #method hysep is commented out mcl - 1-22-16 11 | # test_that("getPred_baseflow with method='hysep' works", { 12 | # 13 | # app2.est$Baseflow <- getPred_baseflow(data=app2.est, metadata=md, da=200000, select="sliding") 14 | # print(ggplot(app2.est, aes(x=DATES)) + geom_line(aes(y=FLOW), color="blue") + geom_line(aes(y=Baseflow), color="black") + theme_bw()) 15 | # expect_manual_OK("hysep|sliding: Baseflow (black) is reasonably separated from total flow (blue)") 16 | # 17 | # app2.est$Baseflow <- getPred_baseflow(data=app2.est, metadata=md, da=200000, select="local minimum") 18 | # print(ggplot(app2.est, aes(x=DATES)) + geom_line(aes(y=FLOW), color="blue") + geom_line(aes(y=Baseflow), color="black") + theme_bw()) 19 | # expect_manual_OK("hysep|local minimum: Baseflow (black) is reasonably separated from total flow (blue)") 20 | # 21 | # app2.est$Baseflow <- getPred_baseflow(data=app2.est, metadata=md, da=200000, select="fixed") 22 | # print(ggplot(app2.est, aes(x=DATES)) + geom_line(aes(y=FLOW), color="blue") + geom_line(aes(y=Baseflow), color="black") + theme_bw()) 23 | # expect_manual_OK("hysep|fixed: Baseflow (black) is reasonably separated from total flow (blue)") 24 | # 25 | # }) 26 | 27 | test_that("getPred_baseflow with method='1' works", { 28 | 29 | app2.est$Baseflow <- getPred_baseflow(data=app2.est, metadata=md, method="1p digital filter", alpha=0.98) 30 | #print(ggplot(app2.est, aes(x=DATES)) + geom_line(aes(y=FLOW), color="blue") + geom_line(aes(y=Baseflow), color="black") + theme_bw()) 31 | expect_manual_OK("1pDF: Baseflow (black) is reasonably separated from total flow (blue)") 32 | 33 | }) 34 | 35 | test_that("getPred_baseflow with method='2' works", { 36 | 37 | app2.est$Baseflow <- getPred_baseflow(data=app2.est, metadata=md, method="2p digital filter", alpha=0.98, BFImax=0.5) 38 | #print(ggplot(app2.est, aes(x=DATES)) + geom_line(aes(y=FLOW), color="blue") + geom_line(aes(y=Baseflow), color="black") + theme_bw()) 39 | expect_manual_OK("2pDF: Baseflow (black) is reasonably separated from total flow (blue)") 40 | 41 | }) 42 | 43 | test_that("getPred_isBaseflow works", { 44 | 45 | app2.est$Baseflow <- getPred_baseflow(data=app2.est, metadata=md, method="2p digital filter", alpha=0.98, BFImax=0.5) 46 | app2.est$IsBaseflow <- getPred_isBaseflow(data=app2.est, metadata=md, baseflow=app2.est$Baseflow, threshold=0.8) 47 | #print(ggplot(app2.est, aes(x=DATES)) + geom_line(aes(y=FLOW), color="lightgrey") + geom_line(aes(y=Baseflow), color="grey") + 48 | # geom_point(aes(y=FLOW, color=IsBaseflow), size=0.3) + theme_bw()) 49 | expect_manual_OK("isBaseflow: Runoff (red) is reasonably separated from baseflow (blue)") 50 | 51 | }) 52 | 53 | -------------------------------------------------------------------------------- /tests/testthat/test-42-outliers.R: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DOI-USGS/loadflex/bfcd8f767efc5298852be0883ec5b12fb3525972/tests/testthat/test-42-outliers.R -------------------------------------------------------------------------------- /tests/testthat/test-44-plots.R: -------------------------------------------------------------------------------- 1 | context("plotEGRET") 2 | 3 | # Setup of data to use in tests 4 | data(lamprey_nitrate) 5 | fitdat <- lamprey_nitrate 6 | data(lamprey_discharge) 7 | estdat <- subset(lamprey_discharge, DATE < as.POSIXct("2012-10-01 00:00:00", tz="EST5EDT")) 8 | estdat <- estdat[seq(1, nrow(estdat), by=96/4),] # only keep 4 observations per day 9 | meta <- metadata(constituent="NO3", flow="DISCHARGE", dates="DATE", 10 | conc.units="mg L^-1", flow.units="cfs", load.units="kg", load.rate.units="kg d^-1", 11 | site.name="Lamprey River, NH", site.id='NWIS 01073500', consti.name = "nitrate") 12 | conc_lm <- loadLm(formula=log(NO3) ~ log(DISCHARGE), pred.format="conc", 13 | data=fitdat, metadata=meta, retrans=exp) 14 | preds <- predictSolute(conc_lm, "conc", estdat, se.pred=TRUE, date=TRUE) 15 | preds_flux <- predictSolute(conc_lm, "flux", estdat, se.pred=TRUE, date=TRUE) 16 | 17 | test_that("plotEGRET will reject a fake plot name", { 18 | expect_error(plotEGRET(plot.name = 'myplot', meta = meta), 19 | 'unrecognized plot.name: myplot') 20 | }) 21 | 22 | test_that("plotEGRET will reject a plot type that is missing required data", { 23 | expect_error(plotEGRET(plot.name = 'plotConcTime', data = fitdat), 24 | 'missing data requirements for plotConcTime') 25 | }) 26 | 27 | test_that("plotEGRET works for fitdat and meta", { 28 | plotEGRET(plot.name = 'plotConcQ', data = fitdat, meta = meta) 29 | expect_false(is.null(dev.list())) 30 | dev.off() 31 | }) 32 | 33 | test_that("plotEGRET works for fitdat, estdat, preds, and meta", { 34 | plotEGRET(plot.name = 'boxQTwice', load.model = conc_lm, newdata = estdat) 35 | expect_false(is.null(dev.list())) 36 | dev.off() 37 | }) 38 | --------------------------------------------------------------------------------