diff --git a/.Rbuildignore b/.Rbuildignore index b51a2f6b..6b14c5ba 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -62,4 +62,5 @@ deploy_simple.R cobertura.xml test-out.xml ^_pkgdown\.yml$ -review/* \ No newline at end of file +review/* +docs/* \ No newline at end of file diff --git a/.gitignore b/.gitignore index 4e166fa0..17d60f26 100644 --- a/.gitignore +++ b/.gitignore @@ -7,7 +7,6 @@ Meta/ Newstuff/ *.docx vignettes/*.html -vignettes/*.R vignettes/EGRET.R vignettes/Enhancements.R vignettes/TrendsByMonth.R diff --git a/DESCRIPTION b/DESCRIPTION index 2d67f187..6b3f9085 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: EGRET Type: Package Title: Exploration and Graphics for RivEr Trends -Version: 3.0.9 +Version: 3.0.10 Authors@R: c( person("Robert", "Hirsch", role = c("aut"), email = "rhirsch@usgs.gov", comment=c(ORCID="0000-0002-4534-075X")), @@ -58,6 +58,6 @@ Copyright: This software is in the public domain because it contains materials the United States Department of Interior. For more information, see the official USGS copyright policy at https://www.usgs.gov/information-policies-and-instructions/copyrights-and-credits -RoxygenNote: 7.2.3 +RoxygenNote: 7.3.2 Roxygen: list(old_usage = TRUE) Encoding: UTF-8 diff --git a/NAMESPACE b/NAMESPACE index 357c1799..ade8afc5 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -140,16 +140,7 @@ exportClasses(fluxUnit) exportClasses(monthLabel) exportClasses(qUnit) import(methods) -importFrom(grDevices,colorRampPalette) -importFrom(graphics,abline) importFrom(graphics,axis) -importFrom(graphics,box) -importFrom(graphics,boxplot) -importFrom(graphics,contour) -importFrom(graphics,filled.contour) -importFrom(graphics,grconvertX) -importFrom(graphics,grconvertY) -importFrom(graphics,legend) importFrom(graphics,lines) importFrom(graphics,mtext) importFrom(graphics,par) @@ -157,18 +148,4 @@ importFrom(graphics,plot) importFrom(graphics,points) importFrom(graphics,segments) importFrom(graphics,title) -importFrom(stats,aggregate) -importFrom(stats,filter) -importFrom(stats,lm) -importFrom(stats,median) -importFrom(stats,na.omit) -importFrom(stats,predict) -importFrom(stats,quantile) -importFrom(stats,reshape) -importFrom(stats,rnorm) -importFrom(stats,sd) importFrom(stats,var) -importFrom(utils,URLencode) -importFrom(utils,read.delim) -importFrom(utils,tail) -importFrom(utils,write.table) diff --git a/NEWS b/NEWS index 70499963..57e1e6b7 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,12 @@ +EGRET 3.0.10 +=========== +* Fix bug with 0 concentration values in readWQPSample. +* Style updates. +* Port readNWISSample to Water Quality Portal. NWIS services are retired. +* Move removing the rows of Sample data with 0 concentration to outside compressData +* Add columns from raw WQP data to be retained in Sample dataframe. + + EGRET 3.0.9 =========== * Bug fix for the monthly concentration trend results in runPairs. diff --git a/R/EGRET.R b/R/EGRET.R index 038e9db6..78cfe6f0 100644 --- a/R/EGRET.R +++ b/R/EGRET.R @@ -3,7 +3,7 @@ if (!interactive()) return() EGRET_version = utils::packageVersion("EGRET") packageStartupMessage("EGRET ", EGRET_version," -Extended Documentation: https://rconnect.usgs.gov/EGRET") +Extended Documentation: https://doi-usgs.github.io/EGRET") } @@ -26,43 +26,20 @@ Extended Documentation: https://rconnect.usgs.gov/EGRET") #' #' @name EGRET-package #' @docType package -#' @importFrom utils write.table -#' @importFrom utils read.delim -#' @importFrom utils URLencode -#' @importFrom utils tail -#' @importFrom stats aggregate -#' @importFrom stats lm -#' @importFrom stats median -#' @importFrom stats sd -#' @importFrom stats reshape -#' @importFrom stats filter -#' @importFrom stats rnorm -#' @importFrom stats na.omit #' -#' @importFrom graphics abline #' @importFrom graphics axis -#' @importFrom graphics box -#' @importFrom graphics boxplot -#' @importFrom graphics contour -#' @importFrom graphics filled.contour -#' @importFrom graphics grconvertX -#' @importFrom graphics grconvertY -#' @importFrom graphics legend #' @importFrom graphics lines #' @importFrom graphics mtext #' @importFrom graphics par #' @importFrom graphics points #' @importFrom graphics segments #' @importFrom graphics title -#' @importFrom stats predict -#' @importFrom stats quantile -#' @importFrom grDevices colorRampPalette #' @author Robert M. Hirsch \email{rhirsch@@usgs.gov}, Laura De Cicco \email{ldecicco@@usgs.gov} #' @references Hirsch, R.M., and De Cicco, L.A., 2014, User guide to Exploration and Graphics for RivEr Trends #' (EGRET) and dataRetrieval: R packages for hydrologic data: U.S. Geological Survey Techniques and Methods book 4, #' chap. A10, 94 p., \doi{10.3133/tm4A10} -#' @keywords water-quality graphics streamflow statistics -NULL +#' @keywords internal +"_PACKAGE" #' Example eList #' @@ -85,10 +62,10 @@ NULL #' Constants included with EGRET #' -#'\itemize{ -#' \item{fluxConst}{Flux conversion object} -#' \item{qConst}{Flow conversion object} -#' \item{monthInfo}{Month object} +#'\tabular{ll}{ +#' fluxConst \tab Flux conversion object\cr +#' qConst \tab Flow conversion object\cr +#' monthInfo \tab Month object\cr #'} #' #'@aliases fluxConst qConst monthInfo concConst diff --git a/R/boxConcMonth.R b/R/boxConcMonth.R index 586e564c..1a8a315d 100644 --- a/R/boxConcMonth.R +++ b/R/boxConcMonth.R @@ -17,7 +17,7 @@ #' @param tinyPlot logical variable, if TRUE plot is designed to be plotted small as part of a multi-plot figure, default is FALSE. #' @param logScale logical if TRUE y plotted in log axis #' @param customPar logical defaults to FALSE. If TRUE, par() should be set by user before calling this function -#' @param las numeric in {0,1,2,3}; the style of axis labels, see ?par +#' @param las numeric in c(0,1,2,3); the style of axis labels, see ?par #' @param showXLabels logical defaults to TRUE. If FALSE, the x axis label is not plotted #' @param showYLabels logical defaults to TRUE. If FALSE, the y axis label is not plotted #' @param showXAxis logical defaults to TRUE. If FALSE, the x axis is not plotted @@ -124,7 +124,7 @@ boxConcMonth <- function(eList, printTitle = TRUE, units = localINFO$param.units) yTicksLab <- prettyNum(yInfo$ticks) - boxplot(tempDF$conc ~ tempDF$month, + graphics::boxplot(tempDF$conc ~ tempDF$month, ylim = c(yInfo$bottom,yInfo$top), yaxs = "i", yTicks = yInfo$ticks, diff --git a/R/boxConcThree.R b/R/boxConcThree.R index ae6104a2..ba8dc37d 100644 --- a/R/boxConcThree.R +++ b/R/boxConcThree.R @@ -107,7 +107,7 @@ boxConcThree<-function (eList, tinyPlot=FALSE, yTicks <- yPretty(yMax) yTop <- yTicks[length(yTicks)] - boxplot(concV ~ index,varwidth=TRUE, + graphics::boxplot(concV ~ index,varwidth=TRUE, names = groupNames,xlab = "", ylab = yLab, ylim = c(0,yTop), axes = FALSE, main = plotTitle, font.main = font.main, cex = cex, @@ -119,7 +119,7 @@ boxConcThree<-function (eList, tinyPlot=FALSE, axis(2,tcl=0.5,las=1,at=yTicks,cex.axis=cex.axis) axis(3,tcl=0.5,at=c(1,2,3),labels=FALSE) axis(4,tcl=0.5,at=yTicks,labels=FALSE) - box() + graphics::box() if (!tinyPlot) mtext(title2,side=3,line=-1.5) invisible(eList) } \ No newline at end of file diff --git a/R/boxQTwice.R b/R/boxQTwice.R index f61304a5..9bfdfd50 100644 --- a/R/boxQTwice.R +++ b/R/boxQTwice.R @@ -27,7 +27,7 @@ #' @param logScale logical if TRUE y plotted in log axis. Defaults to TRUE. #' @param tinyPlot logical variable, if TRUE plot is designed to be plotted small as part of a multi-plot figure, default is FALSE. #' @param customPar logical defaults to FALSE. If TRUE, par() should be set by user before calling this function -#' @param las numeric in {0,1,2,3}; the style of axis labels, see ?par +#' @param las numeric in c(0,1,2,3); the style of axis labels, see ?par #' @param usgsStyle logical option to use USGS style guidelines. Setting this option #' to TRUE does NOT guarantee USGS compliance. It will only change automatically #' generated labels. @@ -111,7 +111,7 @@ boxQTwice<-function(eList, logScaleText <- "" } - boxplot(bigQ~index,varwidth=TRUE, + graphics::boxplot(bigQ~index,varwidth=TRUE, names=groupNames,xlab="", ylim=c(yInfo$bottom,yInfo$top), main=plotTitle,cex=cex,ylab=yLabel, diff --git a/R/boxResidMonth.R b/R/boxResidMonth.R index 8df64c30..e635be0f 100644 --- a/R/boxResidMonth.R +++ b/R/boxResidMonth.R @@ -21,7 +21,7 @@ #' @param cex.main magnification to be used for main titles relative to the current setting of cex #' @param font.main font to be used for plot main titles #' @param customPar logical defaults to FALSE. If TRUE, par() should be set by user before calling this function -#' @param las numeric in {0,1,2,3}; the style of axis labels +#' @param las numeric in c(0,1,2,3); the style of axis labels #' @param randomCensored logical. Show censored residuals as randomized. Default = FALSE. #' @param monthLab object of monthLabel class, or numeric represented the short code, #' or character representing the descriptive name. @@ -104,7 +104,7 @@ boxResidMonth <- function(eList, monthList <- singleMonthList[localSample$Month] monthList <- factor(monthList, namesListFactor) - boxplot(resid ~ monthList, + graphics::boxplot(resid ~ monthList, varwidth = TRUE, xlab = "Month", ylab = yLab, main = plotTitle, @@ -114,7 +114,7 @@ boxResidMonth <- function(eList, cex.axis = cex.axis, las = las, ...) - abline(h = 0) + graphics::abline(h = 0) if (!tinyPlot) mtext(title2, side = 3, line = -1.5) invisible(eList) } \ No newline at end of file diff --git a/R/calculateMonthlyResults.R b/R/calculateMonthlyResults.R index d99d37a7..0a60c71c 100644 --- a/R/calculateMonthlyResults.R +++ b/R/calculateMonthlyResults.R @@ -16,22 +16,22 @@ calculateMonthlyResults <- function(eList){ localDaily <- getDaily(eList) - nDays <- aggregate(localDaily$ConcDay, by=list(localDaily$MonthSeq), function(x) sum(!is.na(x)))$x + nDays <- stats::aggregate(localDaily$ConcDay, by=list(localDaily$MonthSeq), function(x) sum(!is.na(x)))$x - Q <- aggregate(localDaily$Q, by=list(localDaily$MonthSeq), mean)$x - DecYear <- aggregate(localDaily$DecYear, by=list(localDaily$MonthSeq), mean)$x + Q <- stats::aggregate(localDaily$Q, by=list(localDaily$MonthSeq), mean)$x + DecYear <- stats::aggregate(localDaily$DecYear, by=list(localDaily$MonthSeq), mean)$x Year <- trunc(DecYear) - Month <- aggregate(localDaily$Month, by=list(localDaily$MonthSeq), mean)$x - Conc <- aggregate(localDaily$ConcDay, by=list(localDaily$MonthSeq), mean)$x - Flux <- aggregate(localDaily$FluxDay, by=list(localDaily$MonthSeq), mean)$x - FNConc <- aggregate(localDaily$FNConc, by=list(localDaily$MonthSeq), mean)$x - FNFlux <- aggregate(localDaily$FNFlux, by=list(localDaily$MonthSeq), mean)$x + Month <- stats::aggregate(localDaily$Month, by=list(localDaily$MonthSeq), mean)$x + Conc <- stats::aggregate(localDaily$ConcDay, by=list(localDaily$MonthSeq), mean)$x + Flux <- stats::aggregate(localDaily$FluxDay, by=list(localDaily$MonthSeq), mean)$x + FNConc <- stats::aggregate(localDaily$FNConc, by=list(localDaily$MonthSeq), mean)$x + FNFlux <- stats::aggregate(localDaily$FNFlux, by=list(localDaily$MonthSeq), mean)$x kalman <- all(c("GenConc","GenFlux") %in% names(localDaily)) if(kalman){ - GenConc <- aggregate(localDaily$GenConc, by=list(localDaily$MonthSeq), mean)$x - GenFlux <- aggregate(localDaily$GenFlux, by=list(localDaily$MonthSeq), mean)$x + GenConc <- stats::aggregate(localDaily$GenConc, by=list(localDaily$MonthSeq), mean)$x + GenFlux <- stats::aggregate(localDaily$GenFlux, by=list(localDaily$MonthSeq), mean)$x MonthlyResults <- data.frame(Month, Year, nDays, DecYear, Q, diff --git a/R/compressData.r b/R/compressData.r index 109bce5d..dcbbed45 100644 --- a/R/compressData.r +++ b/R/compressData.r @@ -51,24 +51,28 @@ compressData <- function(data, verbose = TRUE){ i <- i + 1 } - names(data) <- c('dateTime', 'code', 'value') - returnDataFrame <- as.data.frame(matrix(ncol=3,nrow=nrow(data))) - names(returnDataFrame) <- c('dateTime', 'ConcLow', 'ConcHigh') + names(data)[1:3] <- c('dateTime', 'code', 'value') data$dateTime <- as.character(data$dateTime) if(dateFormatCheck(data$dateTime)){ - returnDataFrame$dateTime <- as.Date(data$dateTime) + data$dateTime <- as.Date(data$dateTime) } else { data$dateTime <- as.Date(data$dateTime,format="%m/%d/%Y") - returnDataFrame$dateTime <- as.Date(data$dateTime,format="%m/%d/%Y") } - returnDataFrame$ConcLow <- as.numeric(lowConcentration) - returnDataFrame$ConcHigh <- as.numeric(highConcentration) - Uncen1<-ifelse(returnDataFrame$ConcLow==returnDataFrame$ConcHigh,1,0) - returnDataFrame$Uncen<-ifelse(is.na(returnDataFrame$ConcLow)|is.na(returnDataFrame$ConcHigh),0,Uncen1) + + + data$ConcLow <- as.numeric(lowConcentration) + data$ConcHigh <- as.numeric(highConcentration) + Uncen1<-ifelse(data$ConcLow==data$ConcHigh,1,0) + data$Uncen<-ifelse(is.na(data$ConcLow)|is.na(data$ConcHigh),0,Uncen1) - flaggedData1 <- returnDataFrame[(returnDataFrame$ConcLow == 0 & returnDataFrame$ConcHigh == 0),] - returnDataFrame <- returnDataFrame[!(returnDataFrame$ConcLow == 0 & returnDataFrame$ConcHigh == 0),] + return(data) +} + + +remove_zeros <- function(data, verbose){ + flaggedData1 <- data[(data$ConcLow == 0 & data$ConcHigh == 0),] + data <- data[!(data$ConcLow == 0 & data$ConcHigh == 0),] if (nrow(flaggedData1) > 0){ WarningMessage <- paste("Deleted", nrow(flaggedData1), "rows of data because concentration was reported as 0.0, the program is unable to interpret that result and is therefore deleting it.") @@ -78,6 +82,5 @@ compressData <- function(data, verbose = TRUE){ print(flaggedData1) } } - - return(returnDataFrame) + return(data) } diff --git a/R/cumQdate.R b/R/cumQdate.R index 68dc555c..f7cd0b9e 100644 --- a/R/cumQdate.R +++ b/R/cumQdate.R @@ -27,7 +27,7 @@ #' annualFlow <- cumQdate(eList) #' head(annualFlow) #' plot(annualFlow) -#' mod1 <- lm(annualFlow[,2] ~ annualFlow[,1]) +#' mod1 <- stats::lm(annualFlow[,2] ~ annualFlow[,1]) #' summary(mod1) cumQdate <- function(eList, paStart = 10, paLong = 12, @@ -65,6 +65,6 @@ cumQdate <- function(eList, } } - annualSeries <- na.omit(annualSeries) + annualSeries <- stats::na.omit(annualSeries) return(annualSeries) } \ No newline at end of file diff --git a/R/errorStats.R b/R/errorStats.R index 7ae18517..2242d78a 100644 --- a/R/errorStats.R +++ b/R/errorStats.R @@ -22,7 +22,7 @@ errorStats <- function(eList) { eListR <- makeAugmentedSample(eList) Sample <- eListR$Sample - # n <- length(Sample$Date) + Sample$Pred <- log(Sample$rObserved) - Sample$rResid Sample$trueFlux <- Sample$rObserved * Sample$Q * 86.4 Sample$trueLogF <- log(Sample$trueFlux) diff --git a/R/estSurfaces.R b/R/estSurfaces.R index 21b376c3..0dc8f760 100644 --- a/R/estSurfaces.R +++ b/R/estSurfaces.R @@ -92,7 +92,7 @@ estSurfaces<-function(eList, surfaceStart=NA, surfaceEnd=NA, localSample=NA, sliceIndex <- which(vectorYear >= decimalDate(as.Date(surfaceStart)) & vectorYear <= decimalDate(as.Date(surfaceEnd))) - Year <- vectorYear[c(sliceIndex[1]-1, sliceIndex, tail(sliceIndex, n = 1)+1)] + Year <- vectorYear[c(sliceIndex[1]-1, sliceIndex, utils::tail(sliceIndex, n = 1)+1)] nVectorYear <- length(Year) estPtYear <- rep(Year,each=14) diff --git a/R/genericEGRETplot.R b/R/genericEGRETplot.R index 80617714..43dc6b26 100644 --- a/R/genericEGRETplot.R +++ b/R/genericEGRETplot.R @@ -84,9 +84,9 @@ genericEGRETDotPlot <- function(x,y, xlim, ylim, ylim=ylim,yaxs=yaxs,ylab=if(showYLabels) ylab else "", main=plotTitle,col=col,lwd=lwd, pch=pch,cex=cex,cex.main=cex.main,font.main=font.main,cex.lab=cex.lab,...) - box() - if (hLine) abline(h = 0) - if (oneToOneLine) abline(a=0,b=1) + graphics::box() + if (hLine) graphics::abline(h = 0) + if (oneToOneLine) graphics::abline(a=0,b=1) if(rmSciX){ xTicksLab <- prettyNum(xTicks) diff --git a/R/kalman_functions.R b/R/kalman_functions.R index 7a493c14..63523c24 100644 --- a/R/kalman_functions.R +++ b/R/kalman_functions.R @@ -106,7 +106,7 @@ WRTDSKalman <- function(eList, rho = 0.90, niter = 200, endFill <- zends[iGap]+1 nFill <- zz$length[iGap]+2 if(i == 1 | i == numGap) { - z <- rnorm(nFill - 2) + z <- stats::rnorm(nFill - 2) xfill <- c(xxP[startFill], z, xxP[endFill]) } else { xfill <- genmissing(xxP[startFill], xxP[endFill], rho, nFill) @@ -385,7 +385,7 @@ plotWRTDSKalman <- function(eList, sideBySide = FALSE, ylab = ylab, cex.main = 0.9, plotTitle = title2) - abline(a = 0, b = 1) + graphics::abline(a = 0, b = 1) if(sideBySide){ mtext(mainTitle, line = -1, side = 3, outer = TRUE, cex= 1) diff --git a/R/makeAnnualSeries.R b/R/makeAnnualSeries.R index 140431de..da4e99d5 100644 --- a/R/makeAnnualSeries.R +++ b/R/makeAnnualSeries.R @@ -97,7 +97,7 @@ makeAnnualSeries<-function(eList, edgeAdjust = TRUE) { if (goodDay > 26 * paLong) { annualSeries[1, 4:8, i] <- mean(yearDaily$DecYear, na.rm = TRUE) - annualSeries[2, 4, i] <- median(yearDaily$Q, na.rm = TRUE) + annualSeries[2, 4, i] <- stats::median(yearDaily$Q, na.rm = TRUE) annualSeries[2, 5, i] <- mean(yearDaily$Q, na.rm = TRUE) annualSeries[2, 6, i] <- max(yearDaily$Q30, na.rm = TRUE) annualSeries[2, 7, i] <- max(yearDaily$Q7, na.rm = TRUE) @@ -111,7 +111,7 @@ makeAnnualSeries<-function(eList, edgeAdjust = TRUE) { numYears <- length(x) xVec <- seq(1,numYears) xy <- data.frame(x,y,xVec) - xy <- na.omit(xy) + xy <- stats::na.omit(xy) goodYears <- length(xy$x) x <- xy$x x1 <- x[1] @@ -126,9 +126,9 @@ makeAnnualSeries<-function(eList, edgeAdjust = TRUE) { window } w <- triCube(x - xi, thisWindow) - mod <- lm(xy$y ~ x, weights = w) + mod <- stats::lm(xy$y ~ x, weights = w) new <- data.frame(x = x[i]) - z <- exp(predict(mod, new)) + z <- exp(stats::predict(mod, new)) iYear <- xy$xVec[i] annualSeries[3, istat, iYear] <- z } diff --git a/R/plot1of15.R b/R/plot1of15.R index 0c11e70b..1a954b10 100644 --- a/R/plot1of15.R +++ b/R/plot1of15.R @@ -50,5 +50,5 @@ plot1of15<-function(eList, yearStart, yearEnd, qf, istat, axis(2,tcl=0.5,at=yTicks,labels=FALSE) axis(3,tcl=0.5,at=xTicks,labels=FALSE) axis(4,tcl=0.5,at=yTicks,labels=FALSE) - box() + graphics::box() } diff --git a/R/plotConcQSmooth.R b/R/plotConcQSmooth.R index 8bd25adb..f5f4afe2 100644 --- a/R/plotConcQSmooth.R +++ b/R/plotConcQSmooth.R @@ -217,18 +217,18 @@ plotConcQSmooth<-function(eList, cols<-colorVal[index] legendLeft <- if(legendLeft == 0) { - grconvertX(0.05, from="npc", to="user") + graphics::grconvertX(0.05, from="npc", to="user") } else { legendLeft } legendTop <- if(legendTop == 0) { - grconvertY(0.3, from="npc", to="user") + graphics::grconvertY(0.3, from="npc", to="user") } else { legendTop } - if (printLegend) legend(legendLeft,legendTop ,legend=words,lty=ltys,col=cols,lwd=lwd,cex=cex.legend) + if (printLegend) graphics::legend(legendLeft,legendTop ,legend=words,lty=ltys,col=cols,lwd=lwd,cex=cex.legend) printResults<-rep(NA,48*4) dim(printResults)<-c(48,4) diff --git a/R/plotConcTimeSmooth.R b/R/plotConcTimeSmooth.R index d6db436c..85e6a170 100644 --- a/R/plotConcTimeSmooth.R +++ b/R/plotConcTimeSmooth.R @@ -222,16 +222,16 @@ plotConcTimeSmooth<-function (eList, q1, q2, q3, cols <- colorVal[index] legendLeft <- if(legendLeft == 0) { - grconvertX(0.05, from="npc", to="user") + graphics::grconvertX(0.05, from="npc", to="user") } else { legendLeft } if(legendTop == 0) { - legendTop <- grconvertY(0.3, from="npc", to="user") + legendTop <- graphics::grconvertY(0.3, from="npc", to="user") } - if (printLegend) legend(legendLeft,legendTop,legend=words,lty=ltys,col=cols,lwd=lwd,cex=cex.legend) + if (printLegend) graphics::legend(legendLeft,legendTop,legend=words,lty=ltys,col=cols,lwd=lwd,cex=cex.legend) printResults <- rep(NA, numX * 4) dim(printResults) <- c(numX, 4) diff --git a/R/plotContours.R b/R/plotContours.R index 75e32e3f..34a07ff5 100644 --- a/R/plotContours.R +++ b/R/plotContours.R @@ -61,7 +61,7 @@ #' contourLevels = clevel) #' plotContours(eList, yearStart, yearEnd, qBottom, qTop = 50, #' contourLevels = clevel, flowDuration = FALSE) -#' colors <- colorRampPalette(c("white","black")) +#' colors <- grDevices::colorRampPalette(c("white","black")) #' plotContours(eList, yearStart, yearEnd, qBottom, qTop = 50, #' contourLevels = clevel, color.palette = colors, #' flowDuration = FALSE) @@ -75,7 +75,7 @@ plotContours <- function(eList, yearStart, yearEnd, yTicks = NA, tick.lwd = 1, usgsStyle = FALSE, lwd = 2, cex.main = 1, cex.axis = 1, concLab = 1, - color.palette = colorRampPalette(c("white","gray","blue","red")), ...) { + color.palette = grDevices::colorRampPalette(c("white","gray","blue","red")), ...) { localINFO <- getInfo(eList) localDaily <- getDaily(eList) @@ -129,9 +129,9 @@ plotContours <- function(eList, yearStart, yearEnd, numX<-length(x) numY<-length(y) - qBottomT <- ifelse(is.na(qBottom), quantile(localDaily$Q, probs = 0.05)*qFactor, qBottom) + qBottomT <- ifelse(is.na(qBottom), stats::quantile(localDaily$Q, probs = 0.05)*qFactor, qBottom) - qTopT <- ifelse(is.na(qTop), quantile(localDaily$Q, probs = 0.95)*qFactor, qTop) + qTopT <- ifelse(is.na(qTop), stats::quantile(localDaily$Q, probs = 0.95)*qFactor, qTop) if(any(is.na(yTicks))){ @@ -212,28 +212,28 @@ plotContours <- function(eList, yearStart, yearEnd, yLab<-ifelse(usgsStyle,qUnit@unitUSGS,qUnit@qUnitExpress) logY <- log(y,10) - filled.contour(x,log(y,10),surft,levels=contourLevels,xlim=c(yearStart,yearEnd), + graphics::filled.contour(x,log(y,10),surft,levels=contourLevels,xlim=c(yearStart,yearEnd), ylim=c(log(yTicks[1],10),log(yTicks[nYTicks],10)), xaxs="i",yaxs="i", color.palette=color.palette, # ..., plot.axes={ - width <- grconvertX(par("usr")[2],from="user",to="inches") - grconvertX(par("usr")[1],from="user",to="inches") - height <- grconvertY(par("usr")[4],from="user",to="inches") - grconvertY(par("usr")[3],from="user",to="inches") + width <- graphics::grconvertX(par("usr")[2],from="user",to="inches") - graphics::grconvertX(par("usr")[1],from="user",to="inches") + height <- graphics::grconvertY(par("usr")[4],from="user",to="inches") - graphics::grconvertY(par("usr")[3],from="user",to="inches") axis(1,tcl=0,at=xTicks,labels=xlabels,cex.axis=cex.axis) axis(2,tcl=0,las=1,at=log(yTicks,10),labels=yTicks,cex.axis=cex.axis) axis(3, tcl = 0, at = xTicks, labels =FALSE,cex.axis=cex.axis) axis(4, tcl = 0, at = log(yTicks, 10), labels=FALSE,cex.axis=cex.axis) - if(flowDuration) contour(x,log(y,10),durSurf,add=TRUE,drawlabels=FALSE,levels=plevels,lwd=lwd) + if(flowDuration) graphics::contour(x,log(y,10),durSurf,add=TRUE,drawlabels=FALSE,levels=plevels,lwd=lwd) segments(v1[1],v1[2],v1[3],v1[4]) segments(v2[1],v2[2],v2[3],v2[4]) segments(h1[1],h1[2],h1[3],h1[4]) - segments(xTicks, rep(log(yTicks[1],10),length(xTicks)), xTicks, rep(grconvertY(grconvertY(par("usr")[3],from="user",to="inches")+tcl,from="inches",to="user"),length(xTicks)), lwd = tick.lwd) - segments(xTicks, rep(log(yTicks[nYTicks],10),length(xTicks)), xTicks, rep(grconvertY(grconvertY(par("usr")[4],from="user",to="inches")-tcl,from="inches",to="user"),length(xTicks)), lwd = tick.lwd) - segments(rep(yearStart,length(yTicks)), log(yTicks,10), rep(grconvertX(grconvertX(par("usr")[1],from="user",to="inches")+tcl,from="inches",to="user"),length(yTicks)),log(yTicks,10), lwd = tick.lwd) - segments(rep(grconvertX(grconvertX(par("usr")[2],from="user",to="inches")-tcl,from="inches",to="user"),length(yTicks)), log(yTicks,10), rep(yearEnd,length(yTicks)),log(yTicks,10), lwd = tick.lwd) + segments(xTicks, rep(log(yTicks[1],10),length(xTicks)), xTicks, rep(graphics::grconvertY(graphics::grconvertY(par("usr")[3],from="user",to="inches")+tcl,from="inches",to="user"),length(xTicks)), lwd = tick.lwd) + segments(xTicks, rep(log(yTicks[nYTicks],10),length(xTicks)), xTicks, rep(graphics::grconvertY(graphics::grconvertY(par("usr")[4],from="user",to="inches")-tcl,from="inches",to="user"),length(xTicks)), lwd = tick.lwd) + segments(rep(yearStart,length(yTicks)), log(yTicks,10), rep(graphics::grconvertX(graphics::grconvertX(par("usr")[1],from="user",to="inches")+tcl,from="inches",to="user"),length(yTicks)),log(yTicks,10), lwd = tick.lwd) + segments(rep(graphics::grconvertX(graphics::grconvertX(par("usr")[2],from="user",to="inches")-tcl,from="inches",to="user"),length(yTicks)), log(yTicks,10), rep(yearEnd,length(yTicks)),log(yTicks,10), lwd = tick.lwd) }, plot.title = { if(printTitle) { diff --git a/R/plotDiffContours.R b/R/plotDiffContours.R index 247e1b09..9f15a7d2 100644 --- a/R/plotDiffContours.R +++ b/R/plotDiffContours.R @@ -35,7 +35,7 @@ #' @param tcl numeric, length of tick marks in inches, default is 0.1 #' @param tick.lwd line width for axis ticks, default is 2 #' @param color.palette a function that creates a color palette for the contour plot. Default goes from blue to white to red -#' using the function \code{colorRampPalette(c("blue","white","red"))}. A few preset options are heat.colors, topo.colors, and terrain.colors. +#' using the function \code{grDevices::colorRampPalette(c("blue","white","red"))}. A few preset options are heat.colors, topo.colors, and terrain.colors. #' @param customPar logical defaults to FALSE. If TRUE, par() should be set by user before calling this function #' (for example, adjusting margins with par(mar=c(5,5,5,5))). If customPar FALSE, EGRET chooses the best margins. #' @param usgsStyle logical option to use USGS style guidelines. Setting this option @@ -67,7 +67,7 @@ plotDiffContours<-function (eList, year0, year1, vert1 = NA, vert2 = NA, horiz = NA, flowDuration = TRUE, yTicks=NA,tick.lwd=1, lwd=2,cex.main = 0.95, cex.axis = 1, customPar = FALSE, usgsStyle = FALSE, - color.palette = colorRampPalette(c("blue","white","red")), + color.palette = grDevices::colorRampPalette(c("blue","white","red")), concLab = 1, monthLab = 1, ...) { localINFO <- getInfo(eList) @@ -130,7 +130,7 @@ plotDiffContours<-function (eList, year0, year1, surfaceSpan <- range(maxDiff) } } else { - surfaceSpan <- quantile(difft, c(0.05,0.95)) + surfaceSpan <- stats::quantile(difft, c(0.05,0.95)) } contourLevels <- pretty(surfaceSpan, n = 15) @@ -142,9 +142,9 @@ plotDiffContours<-function (eList, year0, year1, numX <- length(x) numY <- length(y) - qBottomT <- ifelse(is.na(qBottom), quantile(localDaily$Q, probs = 0.05)*qFactor, qBottom) + qBottomT <- ifelse(is.na(qBottom), stats::quantile(localDaily$Q, probs = 0.05)*qFactor, qBottom) - qTopT <- ifelse(is.na(qTop), quantile(localDaily$Q, probs = 0.95)*qFactor, qTop) + qTopT <- ifelse(is.na(qTop), stats::quantile(localDaily$Q, probs = 0.95)*qFactor, qTop) if(any(is.na(yTicks))){ @@ -227,7 +227,7 @@ plotDiffContours<-function (eList, year0, year1, deltaX <- (1)/25 yLab <- ifelse(usgsStyle,qUnit@unitUSGS,qUnit@qUnitExpress) - filled.contour(x, log(y, 10), difft, levels = contourLevels, + graphics::filled.contour(x, log(y, 10), difft, levels = contourLevels, xlim = c(0,1), ylim = c(log(yTicks[1], 10), log(yTicks[nYTicks], 10)), #main = plotTitle, xaxs = "i", yaxs = "i", @@ -237,16 +237,16 @@ plotDiffContours<-function (eList, year0, year1, labels = yTicks, cex.axis=cex.axis) axis(3, tcl = 0, at = xTicks, labels =FALSE) axis(4, tcl = 0, at = log(yTicks, 10), labels=FALSE) - if(flowDuration) contour(x, log(y, 10), durSurf, add = TRUE, drawlabels = FALSE, + if(flowDuration) graphics::contour(x, log(y, 10), durSurf, add = TRUE, drawlabels = FALSE, levels = plevels,lwd=lwd) segments(v1[1], v1[2], v1[3], v1[4]) segments(v2[1], v2[2], v2[3], v2[4]) segments(h1[1], h1[2], h1[3], h1[4]) - segments(xTicks, rep(log(yTicks[1],10),length(xTicks)), xTicks, rep(grconvertY(grconvertY(par("usr")[3],from="user",to="inches")+tcl,from="inches",to="user"),length(xTicks)), lwd = tick.lwd) - segments(xTicks, rep(log(yTicks[nYTicks],10),length(xTicks)), xTicks, rep(grconvertY(grconvertY(par("usr")[4],from="user",to="inches")-tcl,from="inches",to="user"),length(xTicks)), lwd = tick.lwd) - segments(rep(0,length(yTicks)), log(yTicks,10), rep(grconvertX(grconvertX(par("usr")[1],from="user",to="inches")+tcl,from="inches",to="user"),length(yTicks)),log(yTicks,10), lwd = tick.lwd) - segments(rep(grconvertX(grconvertX(par("usr")[2],from="user",to="inches")-tcl,from="inches",to="user"),length(yTicks)), log(yTicks,10), rep(1,length(yTicks)),log(yTicks,10), lwd = tick.lwd) + segments(xTicks, rep(log(yTicks[1],10),length(xTicks)), xTicks, rep(graphics::grconvertY(graphics::grconvertY(par("usr")[3],from="user",to="inches")+tcl,from="inches",to="user"),length(xTicks)), lwd = tick.lwd) + segments(xTicks, rep(log(yTicks[nYTicks],10),length(xTicks)), xTicks, rep(graphics::grconvertY(graphics::grconvertY(par("usr")[4],from="user",to="inches")-tcl,from="inches",to="user"),length(xTicks)), lwd = tick.lwd) + segments(rep(0,length(yTicks)), log(yTicks,10), rep(graphics::grconvertX(graphics::grconvertX(par("usr")[1],from="user",to="inches")+tcl,from="inches",to="user"),length(yTicks)),log(yTicks,10), lwd = tick.lwd) + segments(rep(graphics::grconvertX(graphics::grconvertX(par("usr")[2],from="user",to="inches")-tcl,from="inches",to="user"),length(yTicks)), log(yTicks,10), rep(1,length(yTicks)),log(yTicks,10), lwd = tick.lwd) }, plot.title = { diff --git a/R/plotMonthTrend.R b/R/plotMonthTrend.R index 3dc42dd3..cbbfb6da 100644 --- a/R/plotMonthTrend.R +++ b/R/plotMonthTrend.R @@ -130,8 +130,8 @@ plotMonthTrend <- function(pairResults, yMax = NA, axis(2, at = NULL, labels = TRUE, tick = TRUE) axis(3, at = seq(1, 12), labels = FALSE, tick = TRUE) axis(4, at = NULL, labels = FALSE, tick = TRUE) - abline(h=0, col = "blue", lwd = 1) - box() + graphics::abline(h=0, col = "blue", lwd = 1) + graphics::box() par(new = TRUE) plot(1:12, z2, xlim = c(0.5,12.5), ylim = c(0, yMax), xlab = "", ylab = "", diff --git a/R/plotSDLogQ.R b/R/plotSDLogQ.R index 356c54cc..9799cd72 100644 --- a/R/plotSDLogQ.R +++ b/R/plotSDLogQ.R @@ -70,7 +70,7 @@ plotSDLogQ<-function(eList, yearStart=NA,yearEnd=NA,window=15,sdMax=NA, firstDay<-startDays[i] lastDay<-startDays[i]+window smallDaily<-localDaily[localDaily$DecYear >= firstDay & localDaily$DecYear <= lastDay,] - y[i]<-sd(smallDaily$LogQ,na.rm=TRUE) + y[i] <- stats::sd(smallDaily$LogQ,na.rm=TRUE) } diff --git a/R/populateDaily.r b/R/populateDaily.r index 73b698d8..4ec086aa 100644 --- a/R/populateDaily.r +++ b/R/populateDaily.r @@ -93,7 +93,7 @@ populateDaily <- function(rawData, qConvert, if (length(rawData$dateTime) < 30){ warning("This program requires at least 30 data points. Rolling means will not be calculated.") } else { - ma <- function(x,n=7){filter(x,rep(1/n,n), sides=1)} + ma <- function(x,n=7){stats::filter(x,rep(1/n,n), sides=1)} localDaily$Q7 <- as.numeric(ma(localDaily$Q)) localDaily$Q30 <- as.numeric(ma(localDaily$Q,30)) } diff --git a/R/populateSampleColumns.r b/R/populateSampleColumns.r index 6f2f92c2..02faacb1 100644 --- a/R/populateSampleColumns.r +++ b/R/populateSampleColumns.r @@ -14,8 +14,8 @@ #' dataInput <- data.frame(dateTime, ConcLow, ConcHigh, Uncen, stringsAsFactors=FALSE) #' Sample <- populateSampleColumns(dataInput) populateSampleColumns <- function(rawData){ # rawData is a dataframe with dateTime, ConcLow, ConcHigh, Uncen - Sample <- as.data.frame(matrix(ncol=3,nrow=length(rawData$dateTime))) - colnames(Sample) <- c('Date', 'ConcLow','ConcHigh') + Sample <- rawData + Sample$Date <- rawData$dateTime Sample$ConcLow <- rawData$ConcLow Sample$ConcHigh <- rawData$ConcHigh @@ -29,6 +29,7 @@ populateSampleColumns <- function(rawData){ # rawData is a dataframe with dateT Sample$SinDY <- sin(2*pi*Sample$DecYear) Sample$CosDY <- cos(2*pi*Sample$DecYear) - # Sample2 <- subset(Sample, (!is.na(Sample$ConcHigh))) # Was just ConcHigh..... + + Sample <- Sample[,names(Sample)[!names(Sample) %in% c("code", "value")]] return (Sample) } diff --git a/R/printSeries.R b/R/printSeries.R index 6c899216..f32309b8 100644 --- a/R/printSeries.R +++ b/R/printSeries.R @@ -59,7 +59,7 @@ printSeries<-function(eList, istat, qUnit = 1, runoff = FALSE) { digits = 4, width = 7) toPrint$qActual <- format(toPrint$qActual, digits = 3, width = 8) toPrint$qSmooth <- format(toPrint$qSmooth, digits=3, width = 8) - write.table(toPrint, file="", + utils::write.table(toPrint, file="", col.names=FALSE, row.names=FALSE, quote=FALSE) diff --git a/R/processQWData.r b/R/processQWData.r index c4233358..75e72905 100644 --- a/R/processQWData.r +++ b/R/processQWData.r @@ -12,9 +12,7 @@ #' @seealso \code{\link[dataRetrieval]{readWQPqw}} #' @examples #' \donttest{ -#' #library(dataRetrieval) -#' -#' #rawWQP <- readWQPqw('21FLEECO_WQX-IMPRGR80','Phosphorus', '', '') +#' #rawWQP <- dataRetrieval::readWQPqw('21FLEECO_WQX-IMPRGR80','Phosphorus', '', '') #' #Sample2 <- processQWData(rawWQP) #' } processQWData <- function(data){ @@ -32,7 +30,8 @@ processQWData <- function(data){ # qualifier[!(is.na(data$DetectionQuantitationLimitMeasure.MeasureValue)) & # data$ResultMeasureValue < data$DetectionQuantitationLimitMeasure.MeasureValue] <- "<" - correctedData <- ifelse((nchar(qualifier)==0),data$ResultMeasureValue,data$DetectionQuantitationLimitMeasure.MeasureValue) + correctedData <- ifelse((nchar(qualifier)==0),data$ResultMeasureValue, + data$DetectionQuantitationLimitMeasure.MeasureValue) test <- data.frame(data$CharacteristicName) @@ -56,7 +55,7 @@ processQWData <- function(data){ "value") test$USGSPCode <- data$USGSPCode - + test$ActivityStartDateTime <- data$ActivityStartDateTime test$ActivityMediaSubdivisionName <- data$ActivityMediaSubdivisionName test$ActivityMediaName <- data$ActivityMediaName test$ResultSampleFractionText <- data$ResultSampleFractionText diff --git a/R/readDataFromFile.r b/R/readDataFromFile.r index 65f3600b..a2a6d847 100644 --- a/R/readDataFromFile.r +++ b/R/readDataFromFile.r @@ -28,7 +28,7 @@ readDataFromFile <- function (filePath, fileName, format = "%m/%d/%Y"){ totalPath <- file.path(filePath,fileName) if(file.exists(totalPath)){ - retval <- read.delim( + retval <- utils::read.delim( totalPath, header = hasHeader, sep = separator, diff --git a/R/readMetaData.r b/R/readMetaData.r index 288b5adf..230af5ba 100644 --- a/R/readMetaData.r +++ b/R/readMetaData.r @@ -107,7 +107,7 @@ readWQPInfo <- function(siteNumber, parameterCd, interactive=TRUE){ siteInfo$constitAbbrev <- parameterData$parameter_cd } else { - siteInfo <- dataRetrieval::whatWQPsites(siteid=siteNumber, characteristicName=URLencode(parameterCd)) + siteInfo <- dataRetrieval::whatWQPsites(siteid=siteNumber, characteristicName=utils::URLencode(parameterCd)) siteInfo$param.nm <- parameterCd siteInfo$param.units <- "" @@ -233,7 +233,7 @@ readUserInfo <- function(filePath,fileName,hasHeader=TRUE,separator=",",interact totalPath <- file.path(filePath, fileName) if(file.exists(totalPath)){ - siteInfo <- read.delim( + siteInfo <- utils::read.delim( totalPath, header = hasHeader, sep=separator, diff --git a/R/readNWISSample.r b/R/readNWISSample.R similarity index 52% rename from R/readNWISSample.r rename to R/readNWISSample.R index 0b650eb1..331e8e16 100644 --- a/R/readNWISSample.r +++ b/R/readNWISSample.R @@ -45,67 +45,17 @@ readNWISSample <- function(siteNumber, startDate = "", endDate = "", verbose = TRUE){ - - - multi_pcodes <- length(parameterCd) > 1 - if(multi_pcodes){ - rawSample <- dataRetrieval::readNWISqw(siteNumber, - parameterCd, - startDate,endDate, - expanded = FALSE) - dataColumns <- grep("p\\d{5}",names(rawSample)) - remarkColumns <- grep("r\\d{5}",names(rawSample)) - totalColumns <-c(grep("sample_dt",names(rawSample)), - dataColumns, remarkColumns) - totalColumns <- totalColumns[order(totalColumns)] - extras <- rawSample[, c("medium_cd")] - } else { - rawSample <- dataRetrieval::readNWISqw(siteNumber, - parameterCd, - startDate,endDate, - expanded = TRUE) - totalColumns <- c("sample_dt", "remark_cd", "result_va") - - extras <- rawSample[, c("sample_dt", "medium_cd", "hyd_cond_cd", "samp_type_cd", - "hyd_event_cd", "dqi_cd", "rpt_lev_cd")] - - if(length(unique(rawSample$medium_cd)) > 1){ - message("More than one medium_cd returned") - } - - } - - if(nrow(rawSample) > 0){ - compressedData <- compressData(rawSample[,totalColumns], - verbose = verbose) - - Sample <- populateSampleColumns(compressedData) - if(!multi_pcodes){ - Sample <- merge(x = Sample, y = extras, - by.x = "Date", - by.y = "sample_dt", - all.x = TRUE) - } - - } else { - Sample <- data.frame(Date = as.Date(character()), - ConcLow = numeric(), - ConcHigh = numeric(), - Uncen = numeric(), - ConcAve = numeric(), - Julian = numeric(), - Month = numeric(), - Day = numeric(), - DecYear = numeric(), - MonthSeq = numeric(), - SinDY = numeric(), - CosDY = numeric(), - stringsAsFactors = FALSE) - } - + siteNumber <- paste0("USGS-", siteNumber) + + Sample <- readWQPSample(siteNumber = siteNumber, + characteristicName = parameterCd, + startDate = startDate, + endDate = endDate, + verbose = verbose) + return(Sample) + } - diff --git a/R/readUserSample.r b/R/readUserSample.r index cc2546f8..7146eeda 100644 --- a/R/readUserSample.r +++ b/R/readUserSample.r @@ -54,6 +54,12 @@ readUserSample <- function (filePath, fileName, format = format) compressedData <- compressData(data, verbose = verbose) + compressedData <- remove_zeros(compressedData, verbose = verbose) Sample <- populateSampleColumns(compressedData) + orig_Sample <- c("Date", "ConcLow", "ConcHigh", "Uncen", "ConcAve", + "Julian", "Month", "Day", "DecYear", "waterYear", "MonthSeq", + "SinDY", "CosDY") + Sample <- Sample[, c(orig_Sample, names(Sample)[!names(Sample) %in% orig_Sample])] + Sample <- Sample[order(Sample$Date), ] return(Sample) } diff --git a/R/readWQPSample.R b/R/readWQPSample.R index be5e23f3..ffdac5ce 100644 --- a/R/readWQPSample.R +++ b/R/readWQPSample.R @@ -44,24 +44,73 @@ readWQPSample <- function(siteNumber, endDate = "", verbose = TRUE){ - url <- dataRetrieval::constructWQPURL(siteNumber,characteristicName,startDate,endDate) - retval <- dataRetrieval::importWQP(url) - if(nrow(retval) > 0){ - - if(nrow(retval) > 0){ - data <- processQWData(retval) - } else { - data <- NULL + extra_cols <- c("ActivityStartDateTime", + "USGSPCode", + "ActivityMediaSubdivisionName", + "ActivityMediaName", + "ResultSampleFractionText", + "ResultStatusIdentifier", + "ResultValueTypeName") + + if(utils::packageVersion("dataRetrieval") >= "2.7.17"){ + data <- suppressMessages(dataRetrieval::readWQPqw(siteNumbers = siteNumber, + parameterCd = characteristicName, + startDate = startDate, + endDate = endDate, + ignore_attributes = TRUE, + legacy = FALSE) ) + + conversion_names <- data.frame(legacy_names = c("ResultDetectionConditionText", + "ResultMeasureValue", + "DetectionQuantitationLimitMeasure.MeasureValue", + "CharacteristicName", + "ActivityStartDate", + extra_cols), + new_names = c("Result_ResultDetectionCondition", + "Result_Measure", + "DetectionLimit_MeasureA", + "Result_Characteristic", + "Activity_StartDate", + "Activity_StartDateTime", + "USGSpcode", + "Activity_MediaSubdivisionName", + "Activity_Media", + "Result_SampleFraction", + "Result_MeasureStatusIdentifier", + "Result_MeasureType")) + + for(i in seq_len(nrow(conversion_names))){ + names(data)[which(names(data) == conversion_names$new_names[i])] <- conversion_names$legacy_names[i] } + + } else { + data <- dataRetrieval::readWQPqw(siteNumbers = siteNumber, + parameterCd = characteristicName, + startDate = startDate, + endDate = endDate) + } + + if(nrow(data) == 0){ + warning("No data returned") + } + + if(nrow(data) > 0){ + + data <- processQWData(data) + first_three <- c("dateTime", + "qualifier", + "value") + compressedData <- compressData(data[, first_three], + verbose = verbose) + combined_data <- cbind(compressedData, data[, names(data)[!names(data) %in% first_three]]) + combined_data <- remove_zeros(combined_data, verbose = verbose) - compressedData <- compressData(data[, c("dateTime", - "qualifier", - "value")], - verbose=verbose) - Sample <- populateSampleColumns(compressedData) - Sample <- cbind(Sample, data[, names(data)[!names(data) %in% c("dateTime", - "qualifier", - "value")]]) + Sample <- populateSampleColumns(combined_data) + orig_Sample <- c("Date", "ConcLow", "ConcHigh", "Uncen", "ConcAve", + "Julian", "Month", "Day", "DecYear", "waterYear", "MonthSeq", + "SinDY", "CosDY") + Sample <- Sample[, c(orig_Sample, names(Sample)[!names(Sample) %in% orig_Sample])] + Sample <- Sample[order(Sample$Date), ] } else { Sample <- data.frame(Date=as.Date(character()), ConcLow=numeric(), @@ -77,6 +126,6 @@ readWQPSample <- function(siteNumber, CosDY=numeric(), stringsAsFactors=FALSE) } - Sample <- Sample[order(Sample$Date), ] + return(Sample) } diff --git a/R/runGroups.R b/R/runGroups.R index 20c9d3d3..c242d890 100644 --- a/R/runGroups.R +++ b/R/runGroups.R @@ -172,6 +172,7 @@ runGroups <- function (eList, windowSide, paStart <- eList$INFO$paStart } else { paStart <- 10 + eList$INFO$paStart <- 10 } } else { eList$INFO$paStart <- paStart @@ -182,6 +183,7 @@ runGroups <- function (eList, windowSide, paLong <- eList$INFO$paLong } else { paLong <- 12 + eList$INFO$paLong <- 12 } } else { eList$INFO$paLong <- paLong diff --git a/R/runPairs.R b/R/runPairs.R index f8c38675..b31ef2dd 100644 --- a/R/runPairs.R +++ b/R/runPairs.R @@ -480,10 +480,10 @@ runPairs <- function(eList, year1, year2, windowSide, k <- c(31, 28.25, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31) eList1 <- as.egret(eList$INFO, DailyRS1FD1, eList$Sample) monthlyResults1 <- calculateMonthlyResults(eList1) - monthlyResults1 <- na.omit(monthlyResults1) + monthlyResults1 <- stats::na.omit(monthlyResults1) eList2 <- as.egret(eList$INFO, DailyRS2FD2, eList$Sample) monthlyResults2 <- calculateMonthlyResults(eList2) - monthlyResults2 <- na.omit(monthlyResults2) + monthlyResults2 <- stats::na.omit(monthlyResults2) monthlyResults1$monthFlux <- monthlyResults1$nDays * monthlyResults1$FNFlux / eList$INFO$drainSqKm monthlyResults1$monthConc <- monthlyResults1$FNConc diff --git a/R/runSurvReg.R b/R/runSurvReg.R index d5999d76..c894ce22 100644 --- a/R/runSurvReg.R +++ b/R/runSurvReg.R @@ -193,7 +193,7 @@ run_WRTDS <- function(estY, estLQ, if(inherits(x, "survreg")) { newdf<-data.frame(DecYear=estY,LogQ=estLQ,SinDY=sin(2*pi*estY),CosDY=cos(2*pi*estY)) # extract results at estimation point - yHat<-predict(x,newdf) + yHat<- stats::predict(x,newdf) SE<-x$scale bias<-exp((SE^2)/2) survReg[1]<-yHat @@ -227,11 +227,11 @@ run_WRTDS <- function(estY, estLQ, jitterSam <- function(Sam, V = 0.2) { SamR <- Sam n <- length(Sam$DecYear) - SamR$DecYear <- Sam$DecYear + rnorm(n,0,0.05) + SamR$DecYear <- Sam$DecYear + stats::rnorm(n,0,0.05) SamR$SinDY <- sin(SamR$DecYear * 2 * pi) SamR$CosDY <- cos(SamR$DecYear * 2 * pi) - sdLQ <- sd(Sam$LogQ) + sdLQ <- stats::sd(Sam$LogQ) s <- sdLQ * V - SamR$LogQ <- Sam$LogQ + rnorm(n,0,s) + SamR$LogQ <- Sam$LogQ + stats::rnorm(n,0,s) return(SamR) } diff --git a/R/stitch.R b/R/stitch.R index 2d8e8869..396c7808 100644 --- a/R/stitch.R +++ b/R/stitch.R @@ -115,7 +115,7 @@ stitch <- function(eList, DecLow <- highLow[["DecLow"]] sliceIndex <- which(vectorYear >= decimalDate(surfaceStart) & vectorYear <= decimalDate(surface1End)) - Year <- vectorYear[c(sliceIndex[1] - 1, sliceIndex, tail(sliceIndex, n = 1) + 1)] + Year <- vectorYear[c(sliceIndex[1] - 1, sliceIndex, utils::tail(sliceIndex, n = 1) + 1)] nVectorYear <- length(Year) Year1 <- Year estPtYear <- rep(Year, each = 14) @@ -138,7 +138,7 @@ stitch <- function(eList, DecLow <- highLow[["DecLow"]] sliceIndex <- which(vectorYear >= decimalDate(surface2Start) & vectorYear <= decimalDate(surfaceEnd)) - Year <- vectorYear[c(sliceIndex[1] - 1, sliceIndex, tail(sliceIndex, n = 1) + 1)] + Year <- vectorYear[c(sliceIndex[1] - 1, sliceIndex, utils::tail(sliceIndex, n = 1) + 1)] Year <- Year[!is.na(Year)] nVectorYear <- length(Year) Year2 <- Year diff --git a/R/tableResults.R b/R/tableResults.R index 1ac099af..4da6f39f 100644 --- a/R/tableResults.R +++ b/R/tableResults.R @@ -113,7 +113,7 @@ tableResults<-function(eList, qUnit = 2, fluxUnit = 9, localDaily = NA) { paste0("FN Flux [", fNameNoSpace, "]") ) } - write.table(results,file="",quote=FALSE,col.names=FALSE,row.names=FALSE) + utils::write.table(results,file="",quote=FALSE,col.names=FALSE,row.names=FALSE) origNames <- names(results) results <- data.frame(apply(results, 2, function(x) as.numeric(gsub(" ","", as.character(x))))) diff --git a/README.Rmd b/README.Rmd index 61d8a744..f2c7fdaf 100644 --- a/README.Rmd +++ b/README.Rmd @@ -26,15 +26,15 @@ Exploration and Graphics for RivEr Trends (`EGRET`): An R-package for the analysis of long-term changes in water quality and streamflow, including the water-quality method Weighted Regressions on Time, Discharge, and Season (WRTDS). Look for new and improved documentation here: -[https://rconnect.usgs.gov/EGRET/](https://rconnect.usgs.gov/EGRET/) + The link for the official USGS publication user guide is here: [https://pubs.usgs.gov/tm/04/a10/](https://pubs.usgs.gov/tm/04/a10/) -A companion package [`EGRETci`](https://rconnect.usgs.gov/EGRETci/) implements a set of approaches to the analysis of uncertainty associated with WRTDS trend analysis. +A companion package [`EGRETci`](https://doi-usgs.github.io/EGRETci/) implements a set of approaches to the analysis of uncertainty associated with WRTDS trend analysis. -If you are familiar with the traditional `EGRET` workflow, check out the [Overview and Updates](https://rconnect.usgs.gov/EGRET/articles/Overview.html) to see how all the latest updates relate. +If you are familiar with the traditional `EGRET` workflow, check out the [Overview and Updates](https://doi-usgs.github.io/EGRET/articles/Overview.html to see how all the latest updates relate. Recent introduction to WRTDS and the `EGRET` package at the 12th National Monitoring Conference April 19, 2021: @@ -67,7 +67,7 @@ The second is an application to nitrate data for 8 monitoring sites on the Missi For a thorough discussion of the generalized flow normalization method implemented in the EGRET enhancements, see the paper: "Tracking changes in nutrient delivery to western Lake Erie: Approaches to compensate for variability and trends in streamflow": -(https://www.sciencedirect.com/science/article/pii/S0380133018302235). +. ## Sample Workflow @@ -251,7 +251,7 @@ citation(package = "EGRET") See this list for WRTDS applications in print: -[https://rconnect.usgs.gov/EGRET/articles/References_WRTDS.html](https://rconnect.usgs.gov/EGRET/articles/References_WRTDS.html) + ```{r disclaimer, child="DISCLAIMER.md", eval=TRUE} diff --git a/README.md b/README.md index 812dc26d..eb82235a 100644 --- a/README.md +++ b/README.md @@ -11,20 +11,21 @@ including the water-quality method Weighted Regressions on Time, Discharge, and Season (WRTDS). Look for new and improved documentation here: - +https://doi-usgs.github.io/EGRET/\ The link for the official USGS publication user guide is here: -A companion package [`EGRETci`](https://rconnect.usgs.gov/EGRETci/) +A companion package [`EGRETci`](https://doi-usgs.github.io/EGRETci/) implements a set of approaches to the analysis of uncertainty associated with WRTDS trend analysis. If you are familiar with the traditional `EGRET` workflow, check out the -[Overview and -Updates](https://rconnect.usgs.gov/EGRET/articles/Overview.html) to see -how all the latest updates relate. +\[Overview and +Updates\]( to +see how all the latest updates relate. Recent introduction to WRTDS and the `EGRET` package at the 12th National Monitoring Conference April 19, 2021: @@ -93,7 +94,7 @@ implemented in the EGRET enhancements, see the paper: “Tracking changes in nutrient delivery to western Lake Erie: Approaches to compensate for variability and trends in streamflow”: -(). +. ## Sample Workflow @@ -201,7 +202,7 @@ plotConcTimeDaily(eList) ``` r plotFluxTimeDaily(eList) -#> plotGenConc = TRUE requires running WRTDSKalman +#> plotGenFlux = TRUE requires running WRTDSKalman #> on eList. Switching to WRTDS concentration. ``` @@ -327,11 +328,13 @@ siteID <- "01491000" #Choptank River at Greensboro, MD startDate <- "" # Get earliest date endDate <- "" # Get latest date Daily <- readNWISDaily(siteID, "00060", startDate, endDate) -#> There are 27427 data points, and 27427 days. +#> GET: https://waterservices.usgs.gov/nwis/dv/?site=01491000&format=rdb,1.0&ParameterCd=00060&StatCd=00003&startDT=1851-01-01 +#> There are 28058 data points, and 28058 days. # Gather site and parameter information: # Here user must input some values for # the default (interactive=TRUE) INFO <- readNWISInfo(siteID, "00060") +#> GET: https://waterservices.usgs.gov/nwis/site/?siteOutput=Expanded&format=rdb&site=01491000 #> Your site for streamflow data is: #> 01491000 . #> Your site name is CHOPTANK RIVER NEAR GREENSBORO, MD @@ -411,85 +414,74 @@ environments. sessioninfo::session_info() #> ─ Session info ─────────────────────────────────────────────────────────────── #> setting value -#> version R version 4.2.2 (2022-10-31 ucrt) -#> os Windows 10 x64 (build 19044) +#> version R version 4.4.1 (2024-06-14 ucrt) +#> os Windows 11 x64 (build 22631) #> system x86_64, mingw32 #> ui RTerm #> language (EN) #> collate English_United States.utf8 #> ctype English_United States.utf8 #> tz America/Chicago -#> date 2023-02-03 -#> pandoc 2.19.2 @ C:/Program Files/RStudio/resources/app/bin/quarto/bin/tools/ (via rmarkdown) +#> date 2024-10-26 +#> pandoc 3.2 @ C:/Program Files/RStudio/resources/app/bin/quarto/bin/tools/ (via rmarkdown) #> #> ─ Packages ─────────────────────────────────────────────────────────────────── #> package * version date (UTC) lib source -#> assertthat 0.2.1 2019-03-21 [1] CRAN (R 4.2.1) -#> bit 4.0.5 2022-11-15 [1] CRAN (R 4.2.2) -#> bit64 4.0.5 2020-08-30 [1] CRAN (R 4.2.2) -#> class 7.3-20 2022-01-16 [2] CRAN (R 4.2.2) -#> classInt 0.4-8 2022-09-29 [1] CRAN (R 4.2.1) -#> cli 3.6.0 2023-01-09 [1] CRAN (R 4.2.2) -#> colorspace 2.1-0 2023-01-23 [1] CRAN (R 4.2.2) -#> crayon 1.5.2 2022-09-29 [1] CRAN (R 4.2.1) -#> curl 5.0.0 2023-01-12 [1] CRAN (R 4.2.2) -#> dataRetrieval 2.7.12 2023-02-01 [1] local -#> DBI 1.1.3 2022-06-18 [1] CRAN (R 4.2.1) -#> digest 0.6.31 2022-12-11 [1] CRAN (R 4.2.2) -#> dotCall64 1.0-2 2022-10-03 [1] CRAN (R 4.2.1) -#> dplyr 1.0.10 2022-09-01 [1] CRAN (R 4.2.1) -#> e1071 1.7-12 2022-10-24 [1] CRAN (R 4.2.2) -#> EGRET * 3.0.8 2023-01-24 [1] local -#> ellipsis 0.3.2 2021-04-29 [1] CRAN (R 4.2.1) -#> evaluate 0.20 2023-01-17 [1] CRAN (R 4.2.2) -#> fansi 1.0.4 2023-01-22 [1] CRAN (R 4.2.2) -#> fastmap 1.1.0 2021-01-25 [1] CRAN (R 4.2.1) -#> fields 14.1 2022-08-12 [1] CRAN (R 4.2.1) -#> generics 0.1.3 2022-07-05 [1] CRAN (R 4.2.1) -#> ggplot2 3.4.0 2022-11-04 [1] CRAN (R 4.2.2) -#> glue 1.6.2 2022-02-24 [1] CRAN (R 4.1.3) -#> gridExtra 2.3 2017-09-09 [1] CRAN (R 4.2.1) -#> gtable 0.3.1 2022-09-01 [1] CRAN (R 4.2.1) -#> highr 0.10 2022-12-22 [1] CRAN (R 4.2.2) -#> hms 1.1.2 2022-08-19 [1] CRAN (R 4.2.1) -#> htmltools 0.5.4 2022-12-07 [1] CRAN (R 4.2.2) -#> httr 1.4.4 2022-08-17 [1] CRAN (R 4.2.2) -#> KernSmooth 2.23-20 2021-05-03 [2] CRAN (R 4.2.2) -#> knitr 1.42 2023-01-25 [1] CRAN (R 4.2.2) -#> lattice 0.20-45 2021-09-22 [2] CRAN (R 4.2.2) -#> lifecycle 1.0.3 2022-10-07 [1] CRAN (R 4.2.1) -#> magrittr 2.0.3 2022-03-30 [1] CRAN (R 4.1.3) -#> maps 3.4.1 2022-10-30 [1] CRAN (R 4.2.2) -#> Matrix 1.5-3 2022-11-11 [1] CRAN (R 4.2.2) -#> munsell 0.5.0 2018-06-12 [1] CRAN (R 4.2.1) -#> pillar 1.8.1 2022-08-19 [1] CRAN (R 4.2.1) -#> pkgconfig 2.0.3 2019-09-22 [1] CRAN (R 4.2.1) -#> proxy 0.4-27 2022-06-09 [1] CRAN (R 4.2.1) -#> R6 2.5.1 2021-08-19 [1] CRAN (R 4.2.1) -#> Rcpp 1.0.10 2023-01-22 [1] CRAN (R 4.2.2) -#> readr 2.1.3 2022-10-01 [1] CRAN (R 4.2.1) -#> rlang 1.0.6 2022-09-24 [1] CRAN (R 4.2.1) -#> rmarkdown 2.20 2023-01-19 [1] CRAN (R 4.2.2) -#> rstudioapi 0.14 2022-08-22 [1] CRAN (R 4.2.1) -#> scales 1.2.1 2022-08-20 [1] CRAN (R 4.2.1) -#> sessioninfo 1.2.2 2021-12-06 [1] CRAN (R 4.2.1) -#> sf 1.0-9 2022-11-08 [1] CRAN (R 4.2.2) -#> spam 2.9-1 2022-08-07 [1] CRAN (R 4.2.1) -#> survival 3.5-0 2023-01-09 [1] CRAN (R 4.2.2) -#> tibble 3.1.8 2022-07-22 [1] CRAN (R 4.2.1) -#> tidyselect 1.2.0 2022-10-10 [1] CRAN (R 4.2.1) -#> tzdb 0.3.0 2022-03-28 [1] CRAN (R 4.2.1) -#> units 0.8-1 2022-12-10 [1] CRAN (R 4.2.2) -#> utf8 1.2.2 2021-07-24 [1] CRAN (R 4.2.1) -#> vctrs 0.5.2 2023-01-23 [1] CRAN (R 4.2.2) -#> viridis 0.6.2 2021-10-13 [1] CRAN (R 4.2.1) -#> viridisLite 0.4.1 2022-08-22 [1] CRAN (R 4.2.1) -#> vroom 1.6.1 2023-01-22 [1] CRAN (R 4.2.2) -#> xfun 0.36 2022-12-21 [1] CRAN (R 4.2.2) -#> yaml 2.3.7 2023-01-23 [1] CRAN (R 4.2.2) +#> bit 4.5.0 2024-09-20 [1] CRAN (R 4.4.1) +#> bit64 4.5.2 2024-09-22 [1] CRAN (R 4.4.1) +#> class 7.3-22 2023-05-03 [2] CRAN (R 4.4.1) +#> classInt 0.4-10 2023-09-05 [1] CRAN (R 4.4.0) +#> cli 3.6.3 2024-06-21 [1] CRAN (R 4.4.1) +#> crayon 1.5.3 2024-06-20 [1] CRAN (R 4.4.1) +#> curl 5.2.3 2024-09-20 [1] CRAN (R 4.4.1) +#> dataRetrieval 2.7.17 2024-10-25 [1] local +#> DBI 1.2.3 2024-06-02 [1] CRAN (R 4.4.0) +#> digest 0.6.37 2024-08-19 [1] CRAN (R 4.4.1) +#> dotCall64 1.2 2024-10-04 [1] CRAN (R 4.4.1) +#> e1071 1.7-16 2024-09-16 [1] CRAN (R 4.4.1) +#> EGRET * 3.0.10 2024-10-26 [1] local +#> evaluate 1.0.1 2024-10-10 [1] CRAN (R 4.4.1) +#> fansi 1.0.6 2023-12-08 [1] CRAN (R 4.4.0) +#> fastmap 1.2.0 2024-05-15 [1] CRAN (R 4.4.0) +#> fields 16.3 2024-09-30 [1] CRAN (R 4.4.1) +#> glue 1.8.0 2024-09-30 [1] CRAN (R 4.4.1) +#> highr 0.11 2024-05-26 [1] CRAN (R 4.4.0) +#> hms 1.1.3 2023-03-21 [1] CRAN (R 4.4.0) +#> htmltools 0.5.8.1 2024-04-04 [1] CRAN (R 4.4.0) +#> httr 1.4.7 2023-08-15 [1] CRAN (R 4.4.0) +#> KernSmooth 2.23-24 2024-05-17 [2] CRAN (R 4.4.1) +#> knitr 1.48 2024-07-07 [1] CRAN (R 4.4.1) +#> lattice 0.22-6 2024-03-20 [1] CRAN (R 4.4.0) +#> lifecycle 1.0.4 2023-11-07 [1] CRAN (R 4.4.0) +#> magrittr 2.0.3 2022-03-30 [1] CRAN (R 4.4.0) +#> maps 3.4.2 2023-12-15 [1] CRAN (R 4.4.0) +#> Matrix 1.7-0 2024-04-26 [2] CRAN (R 4.4.1) +#> pillar 1.9.0 2023-03-22 [1] CRAN (R 4.4.0) +#> pkgconfig 2.0.3 2019-09-22 [1] CRAN (R 4.4.0) +#> proxy 0.4-27 2022-06-09 [1] CRAN (R 4.4.0) +#> R6 2.5.1 2021-08-19 [1] CRAN (R 4.4.0) +#> Rcpp 1.0.13 2024-07-17 [1] CRAN (R 4.4.1) +#> readr 2.1.5 2024-01-10 [1] CRAN (R 4.4.0) +#> rlang 1.1.4 2024-06-04 [1] CRAN (R 4.4.1) +#> rmarkdown 2.28 2024-08-17 [1] CRAN (R 4.4.1) +#> rstudioapi 0.17.1 2024-10-22 [1] CRAN (R 4.4.1) +#> sessioninfo 1.2.2 2021-12-06 [1] CRAN (R 4.4.0) +#> sf 1.0-18 2024-10-11 [1] CRAN (R 4.4.1) +#> spam 2.11-0 2024-10-03 [1] CRAN (R 4.4.1) +#> survival 3.6-4 2024-04-24 [2] CRAN (R 4.4.1) +#> tibble 3.2.1 2023-03-20 [1] CRAN (R 4.4.0) +#> tidyselect 1.2.1 2024-03-11 [1] CRAN (R 4.4.0) +#> tzdb 0.4.0 2023-05-12 [1] CRAN (R 4.4.0) +#> units 0.8-5 2023-11-28 [1] CRAN (R 4.4.0) +#> utf8 1.2.4 2023-10-22 [1] CRAN (R 4.4.0) +#> vctrs 0.6.5 2023-12-01 [1] CRAN (R 4.4.0) +#> viridisLite 0.4.2 2023-05-02 [1] CRAN (R 4.4.0) +#> vroom 1.6.5 2023-12-05 [1] CRAN (R 4.4.0) +#> xfun 0.48 2024-10-03 [1] CRAN (R 4.4.1) +#> yaml 2.3.10 2024-07-26 [1] CRAN (R 4.4.1) #> -#> [1] C:/Users/ldecicco/Documents/R/win-library/4.2 -#> [2] C:/Program Files/R/R-4.2.2/library +#> [1] C:/Users/ldecicco/AppData/Local/R/win-library/4.4 +#> [2] C:/Program Files/R/R-4.4.1/library #> #> ────────────────────────────────────────────────────────────────────────────── ``` @@ -533,25 +525,19 @@ date. ``` r citation(package = "EGRET") -#> #> To cite EGRET in publications, please use: #> -#> Hirsch, R.M., and De Cicco, L.A., 2015, User guide to Exploration and -#> Graphics for RivEr Trends (EGRET) and dataRetrieval: R packages for -#> hydrologic data (version 2.0, February 2015): U.S. Geological Survey -#> Techniques and Methods book 4, chap. A10, 93 p., doi:10.3133/tm4A10 +#> Hirsch, R.M., De Cicco, L.A., Murphy, J., 2024, Exploration and +#> Graphics for RivEr Trends (EGRET), version 3.0.10, +#> doi:10.5066/P9CC9JEX #> #> A BibTeX entry for LaTeX users is #> -#> @InBook{, -#> author = {Robert M. Hirsch and Laura A. {De Cicco}}, -#> title = {User guide to Exploration and Graphics for RivEr Trends (EGRET) and dataRetrieval: R packages for hydrologic data}, +#> @Manual{, +#> author = {Robert Hirsch and Laura DeCicco and Jennifer Murphy}, +#> title = {Exploration and Graphics for RivEr Trends (EGRET)}, #> publisher = {U.S. Geological Survey}, -#> address = {Reston, VA}, -#> booktitle = {Techniques and Methods}, -#> institution = {U.S. Geological Survey}, -#> year = {2015}, -#> chapter = {A10}, +#> year = {2024}, #> url = {https://pubs.usgs.gov/tm/04/a10/}, #> } ``` @@ -560,7 +546,9 @@ citation(package = "EGRET") See this list for WRTDS applications in print: - +https://doi-usgs.github.io/EGRET/articles/References_WRTDS.html\ # Disclaimer diff --git a/_pkgdown.yml b/_pkgdown.yml index 3f776272..ef8b0396 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -13,7 +13,10 @@ template: nav-link-color: "white" nav-link-hover-color: "#a9a9a9" navbar-light-brand-hover-color: "white" + navbar-light-brand-color: "white" navbar-light-hover-color: "white" + nav-text-color: "white" + nav-text-light-color: "white" text-muted: "white" pkgdown-nav-height: 125px diff --git a/inst/CITATION b/inst/CITATION index cc4a258c..c5aa5681 100644 --- a/inst/CITATION +++ b/inst/CITATION @@ -12,8 +12,8 @@ bibentry(bibtype = "Manual", comment=c(ORCID="0000-0002-0881-0919"))), title = "Exploration and Graphics for RivEr Trends (EGRET)", publisher = "U.S. Geological Survey", - year = 2023, + year = 2024, url = "https://pubs.usgs.gov/tm/04/a10/", - textVersion = "Hirsch, R.M., De Cicco, L.A., Murphy, J., 2023, Exploration and Graphics for RivEr Trends (EGRET), version 3.0.9, doi:10.5066/P9CC9JEX" + textVersion = "Hirsch, R.M., De Cicco, L.A., Murphy, J., 2024, Exploration and Graphics for RivEr Trends (EGRET), version 3.0.10, doi:10.5066/P9CC9JEX" ) diff --git a/man/Constants.Rd b/man/Constants.Rd index 256445e4..7fcdd2cc 100644 --- a/man/Constants.Rd +++ b/man/Constants.Rd @@ -9,10 +9,10 @@ \alias{concConst} \title{Constants included with EGRET} \description{ -\itemize{ - \item{fluxConst}{Flux conversion object} - \item{qConst}{Flow conversion object} - \item{monthInfo}{Month object} +\tabular{ll}{ +fluxConst \tab Flux conversion object\cr +qConst \tab Flow conversion object\cr +monthInfo \tab Month object\cr } } \examples{ diff --git a/man/EGRET-package.Rd b/man/EGRET-package.Rd index bbf3fa59..f0b303c6 100644 --- a/man/EGRET-package.Rd +++ b/man/EGRET-package.Rd @@ -2,6 +2,7 @@ % Please edit documentation in R/EGRET.R \docType{package} \name{EGRET-package} +\alias{EGRET} \alias{EGRET-package} \title{EGRET package includes WRTDS and flowHistory} \description{ @@ -25,11 +26,16 @@ Collection of functions to do WRTDS and flowHistory analysis, Hirsch, R.M., and De Cicco, L.A., 2014, User guide to Exploration and Graphics for RivEr Trends (EGRET) and dataRetrieval: R packages for hydrologic data: U.S. Geological Survey Techniques and Methods book 4, chap. A10, 94 p., \doi{10.3133/tm4A10} +} +\seealso{ +Useful links: +\itemize{ + \item \url{https://pubs.usgs.gov/tm/04/a10/} + \item Report bugs at \url{https://github.com/DOI-USGS/EGRET/issues} +} + } \author{ Robert M. Hirsch \email{rhirsch@usgs.gov}, Laura De Cicco \email{ldecicco@usgs.gov} } -\keyword{graphics} -\keyword{statistics} -\keyword{streamflow} -\keyword{water-quality} +\keyword{internal} diff --git a/man/boxConcMonth.Rd b/man/boxConcMonth.Rd index c582aa75..9ccb981e 100644 --- a/man/boxConcMonth.Rd +++ b/man/boxConcMonth.Rd @@ -21,7 +21,7 @@ boxConcMonth(eList, printTitle = TRUE, cex = 0.8, cex.axis = 1.1, \item{cex.main}{magnification to be used for main titles relative to the current setting of cex} -\item{las}{numeric in {0,1,2,3}; the style of axis labels, see ?par} +\item{las}{numeric in c(0,1,2,3); the style of axis labels, see ?par} \item{logScale}{logical if TRUE y plotted in log axis} diff --git a/man/boxQTwice.Rd b/man/boxQTwice.Rd index 52c51246..a081b048 100644 --- a/man/boxQTwice.Rd +++ b/man/boxQTwice.Rd @@ -25,7 +25,7 @@ boxQTwice(eList, printTitle = TRUE, qUnit = 2, cex = 0.8, \item{tcl}{number defaults to 0.5, specifies length of tick marks as fraction of height of a line of text} -\item{las}{numeric in {0,1,2,3}; the style of axis labels, see ?par} +\item{las}{numeric in c(0,1,2,3); the style of axis labels, see ?par} \item{tinyPlot}{logical variable, if TRUE plot is designed to be plotted small as part of a multi-plot figure, default is FALSE.} diff --git a/man/boxResidMonth.Rd b/man/boxResidMonth.Rd index ccc30a1c..2e631196 100644 --- a/man/boxResidMonth.Rd +++ b/man/boxResidMonth.Rd @@ -14,7 +14,7 @@ boxResidMonth(eList, stdResid = FALSE, las = 1, printTitle = TRUE, \item{stdResid}{logical variable, if TRUE it uses the standardized residual, if FALSE it uses the actual, default is FALSE} -\item{las}{numeric in {0,1,2,3}; the style of axis labels} +\item{las}{numeric in c(0,1,2,3); the style of axis labels} \item{printTitle}{logical variable if TRUE title is printed, if FALSE not printed (this is best for a multi-plot figure)} diff --git a/man/cumQdate.Rd b/man/cumQdate.Rd index fd8e26ae..a5cb1c5f 100644 --- a/man/cumQdate.Rd +++ b/man/cumQdate.Rd @@ -42,6 +42,6 @@ eList <- Choptank_eList annualFlow <- cumQdate(eList) head(annualFlow) plot(annualFlow) -mod1 <- lm(annualFlow[,2] ~ annualFlow[,1]) +mod1 <- stats::lm(annualFlow[,2] ~ annualFlow[,1]) summary(mod1) } diff --git a/man/figures/README-plotFours-1.png b/man/figures/README-plotFours-1.png index 65034630..3ba30e3f 100644 Binary files a/man/figures/README-plotFours-1.png and b/man/figures/README-plotFours-1.png differ diff --git a/man/figures/README-plotFours-2.png b/man/figures/README-plotFours-2.png index f7af2e61..dfbc47b5 100644 Binary files a/man/figures/README-plotFours-2.png and b/man/figures/README-plotFours-2.png differ diff --git a/man/figures/README-unnamed-chunk-4-1.png b/man/figures/README-unnamed-chunk-4-1.png index 2308c634..761f0d21 100644 Binary files a/man/figures/README-unnamed-chunk-4-1.png and b/man/figures/README-unnamed-chunk-4-1.png differ diff --git a/man/figures/README-unnamed-chunk-4-2.png b/man/figures/README-unnamed-chunk-4-2.png index a0d7466e..f5d4afc2 100644 Binary files a/man/figures/README-unnamed-chunk-4-2.png and b/man/figures/README-unnamed-chunk-4-2.png differ diff --git a/man/figures/README-unnamed-chunk-4-3.png b/man/figures/README-unnamed-chunk-4-3.png index c676586a..0189d0c1 100644 Binary files a/man/figures/README-unnamed-chunk-4-3.png and b/man/figures/README-unnamed-chunk-4-3.png differ diff --git a/man/plotContours.Rd b/man/plotContours.Rd index a3dc8dfb..1bc3c154 100644 --- a/man/plotContours.Rd +++ b/man/plotContours.Rd @@ -9,8 +9,9 @@ plotContours(eList, yearStart, yearEnd, qBottom = NA, qTop = NA, pval = 0.05, printTitle = TRUE, vert1 = NA, vert2 = NA, horiz = NA, tcl = 0.03, flowDuration = TRUE, customPar = FALSE, yTicks = NA, tick.lwd = 1, usgsStyle = FALSE, lwd = 2, cex.main = 1, - cex.axis = 1, concLab = 1, color.palette = colorRampPalette(c("white", - "gray", "blue", "red")), ...) + cex.axis = 1, concLab = 1, + color.palette = grDevices::colorRampPalette(c("white", "gray", "blue", + "red")), ...) } \arguments{ \item{eList}{named list with at least the Daily and INFO dataframes, and surfaces matrix} @@ -98,7 +99,7 @@ plotContours(eList, yearStart, yearEnd, qBottom, qTop, contourLevels = clevel) plotContours(eList, yearStart, yearEnd, qBottom, qTop = 50, contourLevels = clevel, flowDuration = FALSE) -colors <- colorRampPalette(c("white","black")) +colors <- grDevices::colorRampPalette(c("white","black")) plotContours(eList, yearStart, yearEnd, qBottom, qTop = 50, contourLevels = clevel, color.palette = colors, flowDuration = FALSE) diff --git a/man/plotDiffContours.Rd b/man/plotDiffContours.Rd index 84180435..0a2f45f4 100644 --- a/man/plotDiffContours.Rd +++ b/man/plotDiffContours.Rd @@ -10,8 +10,8 @@ plotDiffContours(eList, year0, year1, qBottom = NA, qTop = NA, vert2 = NA, horiz = NA, flowDuration = TRUE, yTicks = NA, tick.lwd = 1, lwd = 2, cex.main = 0.95, cex.axis = 1, customPar = FALSE, usgsStyle = FALSE, - color.palette = colorRampPalette(c("blue", "white", "red")), concLab = 1, - monthLab = 1, ...) + color.palette = grDevices::colorRampPalette(c("blue", "white", "red")), + concLab = 1, monthLab = 1, ...) } \arguments{ \item{eList}{named list with at least the Daily and INFO dataframes, and surfaces matrix} @@ -66,7 +66,7 @@ to TRUE does NOT guarantee USGS compliance. It will only change automatically generated labels.} \item{color.palette}{a function that creates a color palette for the contour plot. Default goes from blue to white to red -using the function \code{colorRampPalette(c("blue","white","red"))}. A few preset options are heat.colors, topo.colors, and terrain.colors.} +using the function \code{grDevices::colorRampPalette(c("blue","white","red"))}. A few preset options are heat.colors, topo.colors, and terrain.colors.} \item{concLab}{object of concUnit class, or numeric represented the short code, or character representing the descriptive name. By default, this argument sets diff --git a/man/processQWData.Rd b/man/processQWData.Rd index 26f1262a..7c491de7 100644 --- a/man/processQWData.Rd +++ b/man/processQWData.Rd @@ -20,9 +20,7 @@ conditions to determine if a value is left censored or not. Censored values are } \examples{ \donttest{ -#library(dataRetrieval) - -#rawWQP <- readWQPqw('21FLEECO_WQX-IMPRGR80','Phosphorus', '', '') +#rawWQP <- dataRetrieval::readWQPqw('21FLEECO_WQX-IMPRGR80','Phosphorus', '', '') #Sample2 <- processQWData(rawWQP) } } diff --git a/man/readNWISSample.Rd b/man/readNWISSample.Rd index d1bb905a..7a6dcd52 100644 --- a/man/readNWISSample.Rd +++ b/man/readNWISSample.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/readNWISSample.r +% Please edit documentation in R/readNWISSample.R \name{readNWISSample} \alias{readNWISSample} \title{Import NWIS Sample Data for EGRET analysis} diff --git a/tests/testthat/Rplots.pdf b/tests/testthat/Rplots.pdf index 832e89d5..c0c5ad36 100644 Binary files a/tests/testthat/Rplots.pdf and b/tests/testthat/Rplots.pdf differ diff --git a/tests/testthat/tests_imports.R b/tests/testthat/tests_imports.R index 16bafc9c..3ae55039 100644 --- a/tests/testthat/tests_imports.R +++ b/tests/testthat/tests_imports.R @@ -27,25 +27,25 @@ test_that("External NWIS Sample tests", { SampleNames <- c("Date","ConcLow","ConcHigh","Uncen","ConcAve","Julian","Month", "Day","DecYear","MonthSeq","waterYear","SinDY","CosDY") - expect_warning(Sample_01075 <- readNWISSample('01594440', + Sample_01075 <- readNWISSample('01594440', '01075', '1985-01-01', - '1985-03-31')) + '1985-03-31') expect_true(all(SampleNames %in% names(Sample_01075))) - expect_warning(Sample_All2 <- readNWISSample('05114000', + Sample_All2 <- readNWISSample('05114000', c('00915','00931'), '1985-01-01', - '1985-03-31')) + '1985-03-31') expect_true(all(SampleNames %in% names(Sample_All2))) - Sample_Select <- expect_warning(readNWISSample('05114000', + Sample_Select <- readNWISSample('05114000', c('00915','00931'), - '', '')) + '', '') - expect_true(all(names(Sample_Select) %in% SampleNames)) + expect_true(all(SampleNames %in% names(Sample_Select))) expect_is(Sample_Select$Date, 'Date') expect_is(Sample_Select$ConcAve, 'numeric') @@ -73,16 +73,15 @@ test_that("External INFO tests", { INFO <- readNWISInfo('05114000','00010',interactive=FALSE) expect_true(all(requiredColumns %in% names(INFO))) - # nameToUse <- 'Specific conductance' - # pcodeToUse <- '00095' - # - # INFO_WQP <- readWQPInfo('USGS-04024315',pcodeToUse,interactive=FALSE) - # expect_true(all(requiredColumns %in% names(INFO_WQP))) - # - # INFO2 <- readWQPInfo('WIDNR_WQX-10032762',nameToUse,interactive=FALSE) - # expect_true(all(requiredColumns %in% names(INFO2))) - # - # + nameToUse <- 'Specific conductance' + pcodeToUse <- '00095' + + INFO_WQP <- readWQPInfo('USGS-04024315',pcodeToUse,interactive=FALSE) + expect_true(all(requiredColumns %in% names(INFO_WQP))) + + INFO2 <- readWQPInfo('WIDNR_WQX-10032762',nameToUse,interactive=FALSE) + expect_true(all(requiredColumns %in% names(INFO2))) + }) test_that("User tests", { @@ -105,7 +104,7 @@ test_that("User tests", { SampleNames <- c("Date","ConcLow","ConcHigh","Uncen","ConcAve","Julian","Month", "Day","DecYear","MonthSeq","waterYear","SinDY","CosDY") - expect_true(all(names(Sample_user) %in% SampleNames)) + expect_true(all(SampleNames %in% names(Sample_user))) }) diff --git a/tests/testthat/tests_utils.R b/tests/testthat/tests_utils.R index 21ba0cae..02c8f3de 100644 --- a/tests/testthat/tests_utils.R +++ b/tests/testthat/tests_utils.R @@ -69,15 +69,15 @@ test_that("data functions work", { compressed <- compressData(dataInput) expect_is(compressed, "data.frame") expect_gt(nrow(compressed), 1) - expect_equal(names(compressed), c("dateTime", "ConcLow", "ConcHigh", - "Uncen")) + expect_true(all(c("dateTime", "ConcLow", "ConcHigh", "Uncen") %in% + names(compressed))) #mergeReport siteNumber <- '01594440' pCode <- '01075' Daily <- readNWISDaily(siteNumber,'00060', '1985-01-01', '1990-03-31') - expect_warning(Sample <- readNWISSample(siteNumber,pCode, '1985-01-01', '1990-03-31')) + Sample <- readNWISSample(siteNumber,pCode, '1985-01-01', '1990-03-31') INFO <- readNWISInfo(siteNumber,pCode,interactive=FALSE) eList <- mergeReport(INFO, Daily, Sample) expect_equal(names(eList), c("INFO", "Daily", "Sample", "surfaces")) diff --git a/vignettes/Overview.Rmd b/vignettes/Overview.Rmd index 22c2a6fd..a97b6d6c 100644 --- a/vignettes/Overview.Rmd +++ b/vignettes/Overview.Rmd @@ -18,7 +18,7 @@ Evaluating long-term changes in river conditions (water quality and discharge) i However, several major enhancements and extensions of the method have been made since the User Guide was published in 2015. This EGRET Update Overview is designed to help a user decide which of EGRET’s capabilities they want to apply, and then point them to the relevant documents that describe those in detail. These include various journal articles that explain motivations for these enhancements, provide the mathematical formulations for them, and show examples of their application. It also includes references to various supporting vignettes that explain how to apply these enhancements to the EGRET package. There are also several special applications for which R scripts have been written that depend on the EGRET package, this EGRET Overview and Update will describe them and point to those scripts. -There is an additional R package that users of EGRET should be aware of, called **EGRETci** (which stands for confidence intervals). The EGRETci package is designed to provide a variety of approaches to uncertainty analysis related to the water quality trend results computed in EGRET. EGRETci is tightly linked to EGRET, such that output dataframes or other objects produced by EGRET serve as inputs to functions in EGRETci. Throughout this EGRET Update and Overview we will make mention of the relevant functions of EGRETci. There is a home page for [EGRETci](https://rconnect.usgs.gov/EGRETci/). At the end of this document there is a brief description in the recent changes that have been made to EGRETci. +There is an additional R package that users of EGRET should be aware of, called **EGRETci** (which stands for confidence intervals). The EGRETci package is designed to provide a variety of approaches to uncertainty analysis related to the water quality trend results computed in EGRET. EGRETci is tightly linked to EGRET, such that output dataframes or other objects produced by EGRET serve as inputs to functions in EGRETci. Throughout this EGRET Update and Overview we will make mention of the relevant functions of EGRETci. There is a home page for [EGRETci](https://doi-usgs.github.io/EGRETci/). At the end of this document there is a brief description in the recent changes that have been made to EGRETci. # General Introduction to the EGRET package @@ -34,103 +34,103 @@ There are analyses in EGRET that work only with discharge data (we call them Flo # 1. EGRET overview and data entry -These topics are covered extensively both in the [Introduction to the EGRET package](https://rconnect.usgs.gov/EGRET/) and in more detail in the [EGRET User Guide](https://pubs.usgs.gov/tm/04/a10/pdf/tm4A10.pdf). +These topics are covered extensively both in the [Introduction to the EGRET package](https://doi-usgs.github.io/EGRET) and in more detail in the [EGRET User Guide](https://pubs.usgs.gov/tm/04/a10/pdf/tm4A10.pdf). # 2. Exploration of trends in discharge -EGRET has many tabular and graphical approaches to exploring trends in discharge. These are described in the Flow History component (pages 15 - 28) of the [EGRET User Guide](https://pubs.usgs.gov/tm/04/a10/pdf/tm4A10.pdf)(pages 15 – 28) and section 5 of [Introduction to the EGRET package](https://rconnect.usgs.gov/EGRET/). +EGRET has many tabular and graphical approaches to exploring trends in discharge. These are described in the Flow History component (pages 15 - 28) of the [EGRET User Guide](https://pubs.usgs.gov/tm/04/a10/pdf/tm4A10.pdf)(pages 15 – 28) and section 5 of [Introduction to the EGRET package](https://doi-usgs.github.io/EGRET/articles/EGRET.html). -In addition, a script is available with some new capabilities. It is called [Daily Streamflow Trend Analysis](https://rconnect.usgs.gov/EGRET/articles/streamflow_trend.html). This script includes the graphical technique for exploring trends across the entire frequency distribution: "The Quantile Kendall Plot". This technique is described in [Choquette et al., 2019](https://doi.org/10.1016/j.jglr.2018.11.012). One new function, called [cumQdate( )](https://rconnect.usgs.gov/EGRET/reference/cumQdate.html) has been added to the EGRET package, it is designed to describe trends in the timing of annual runoff. Examples of its application are in [Annual Hydrograph Timing](https://rconnect.usgs.gov/EGRET/articles/Annual_Hydrograph_Timing.html). +In addition, a script is available with some new capabilities. It is called [Daily Streamflow Trend Analysis](https://doi-usgs.github.io/EGRET/articles/streamflow_trend.html). This script includes the graphical technique for exploring trends across the entire frequency distribution: "The Quantile Kendall Plot". This technique is described in [Choquette et al., 2019](https://doi.org/10.1016/j.jglr.2018.11.012). One new function, called `cumQdate` has been added to the EGRET package, it is designed to describe trends in the timing of annual runoff. Examples of its application are in [Annual Hydrograph Timing](https://doi-usgs.github.io/EGRET/articles/Annual_Hydrograph_Timing.html). # 3. Describing water quality without using the WRTDS model. -In some situations, the analyst may want to simply display a set of water quality data without any use of models or modeling assumptions. This can be a useful addition to showing results derived from the WRTDS statistical model. These are described in section 6 of [Introduction to the EGRET package](https://rconnect.usgs.gov/EGRET/) as well as on pages 29 -37 of the [EGRET User Guide](https://pubs.usgs.gov/tm/04/a10/pdf/tm4A10.pdf). +In some situations, the analyst may want to simply display a set of water quality data without any use of models or modeling assumptions. This can be a useful addition to showing results derived from the WRTDS statistical model. These are described in section 6 of [Introduction to the EGRET package](https://doi-usgs.github.io/EGRET) as well as on pages 29 -37 of the [EGRET User Guide](https://pubs.usgs.gov/tm/04/a10/pdf/tm4A10.pdf). ### Improved graphical treatment of censored data. An enhancement of the EGRET packages provides an additional way to graph the data when there are censored values in the data set (typically values reported as "less than" the laboratory reporting limit). The standard way that EGRET depicts less-than values is by showing a vertical line that extends from the reporting limit value all the way to the bottom of the graph. This is not the most visually effective way of showing the data even though it is a more honest approach than simply representing them by plotting them at their reporting limit. The vertical lines tend to draw a great amount of attention to the less-than values. -The enhancement now in the EGRET package is called [Random Residuals](https://rconnect.usgs.gov/EGRET/articles/rResid.html). What is done here is to take each censored value in the data set and randomly select a value that lies between the reporting limit and zero and show it on various plots as an open circle (as opposed to actual measured values, which are shown as a closed circle). +The enhancement now in the EGRET package is called [Random Residuals](https://doi-usgs.github.io/EGRET/articles/rResid.html). What is done here is to take each censored value in the data set and randomly select a value that lies between the reporting limit and zero and show it on various plots as an open circle (as opposed to actual measured values, which are shown as a closed circle). -The function that accomplishes this is called [makeAugmentedSample( )](https://rconnect.usgs.gov/EGRET/reference/makeAugmentedSample.html). These random values are not used in computing any of the WRTDS results (trends, mean concentrations or fluxes) but are only used for graphical representations. They are very valuable for visual presentation but have the drawbacks that: 1) there is no unique "correct" representation of the data. Multiple implementations will result in different random values. 2) the graphs of the data are no longer free from the influence of any statistical model, the computation of these random values depends on an assumption about the distribution of the true value below the reporting limit, and that is based on the assumptions of the fitted WRTDS model. +The function that accomplishes this is called `makeAugmentedSample()`. These random values are not used in computing any of the WRTDS results (trends, mean concentrations or fluxes) but are only used for graphical representations. They are very valuable for visual presentation but have the drawbacks that: 1) there is no unique "correct" representation of the data. Multiple implementations will result in different random values. 2) the graphs of the data are no longer free from the influence of any statistical model, the computation of these random values depends on an assumption about the distribution of the true value below the reporting limit, and that is based on the assumptions of the fitted WRTDS model. Having said that, we should recognize that the purpose of many of these graphs of the data is to present a general idea of how the data behave (as a function of time or of discharge) and this approach will provide an appropriate impression of the data. Many of the graphical functions in EGRET have an argument called **randomCensored** and it should be set to **TRUE** for this feature to be implemented. # 4. Making the best possible estimates of concentration or flux for some specific day, month, or year. -Although the primary purpose for the development of the WRTDS method and EGRET software was to evaluate long term trends, they can also be used for this different purpose: creating the best possible estimate of conditions for any specific day, month, season, or year. For trend analysis (which is discussed in item 5 below) our objective is to remove the confounding influence of the year-to-year variations in discharge in order to see more clearly the underlying trend in water quality. The results from the WRTDS method that are used for the trend analysis purpose are the "Flow-Normalized" values. But here we are considering a different kind of purpose. Here, the question we are focused on is something like: "What’s our best estimate of the flux of total phosphorus into the lake during the month of May 2020?" or "What’s our best estimate of the chloride concentration on February 2, 2019?" For these kinds of estimates we can use a new method called "WRTDS Kalman" or [WRTDS_K](https://rconnect.usgs.gov/EGRET/articles/WRTDSK.html). In addition there are two publications that describe the concept and the mathematics. [Lee, Hirsch and Crawford, 2019](https://pubs.er.usgs.gov/publication/sir20195084) and [Zhang and Hirsch, 2019](https://agupubs.onlinelibrary.wiley.com/doi/full/10.1029/2019WR025338). +Although the primary purpose for the development of the WRTDS method and EGRET software was to evaluate long term trends, they can also be used for this different purpose: creating the best possible estimate of conditions for any specific day, month, season, or year. For trend analysis (which is discussed in item 5 below) our objective is to remove the confounding influence of the year-to-year variations in discharge in order to see more clearly the underlying trend in water quality. The results from the WRTDS method that are used for the trend analysis purpose are the "Flow-Normalized" values. But here we are considering a different kind of purpose. Here, the question we are focused on is something like: "What’s our best estimate of the flux of total phosphorus into the lake during the month of May 2020?" or "What’s our best estimate of the chloride concentration on February 2, 2019?" For these kinds of estimates we can use a new method called "WRTDS Kalman" or [WRTDS_K](https://doi-usgs.github.io/EGRET/articles/WRTDSK.html). In addition there are two publications that describe the concept and the mathematics. [Lee, Hirsch and Crawford, 2019](https://pubs.er.usgs.gov/publication/sir20195084) and [Zhang and Hirsch, 2019](https://agupubs.onlinelibrary.wiley.com/doi/full/10.1029/2019WR025338). WRTDS_K is based on this simple idea. On any given sampled day, the measured concentration will almost certainly differ from the value that WRTDS would predict. The measured value is always a better value to use for that day than is the WRTDS estimate for that day. Furthermore, days surrounding the day of measurement are likely to have values not too different from the sampled day. For any given day, the WRTDS_K method uses a mixture of the WRTDS model’s estimated value and the measured value on the nearest sampled day prior and nearest sampled day after the given day to create an optimal estimate for that day. The mathematics of the method uses an auto-regressive, lag-one day, stochastic model to make these estimates of concentration (and hence flux) for each day in the record. -The new functions in `EGRET` that are used in this process are [WRTDSKalman( )](https://rconnect.usgs.gov/EGRET/reference/wrtdsK.html), [plotWRTDSKalman( )](https://rconnect.usgs.gov/EGRET/reference/plotWRTDSKalman.html), and [plotTimeSlice( )](https://rconnect.usgs.gov/EGRET/reference/plotTimeSlice.html). The `EGRETci` package also has new capabilities to estimate the uncertainty of these WRTDS_K estimates. See [Graphics for Prediction Intervals](https://rconnect.usgs.gov/EGRETci/articles/prediction.html). +The new functions in `EGRET` that are used in this process are `WRTDSKalman()`, `plotWRTDSKalman()`, and `plotTimeSlice()`. The `EGRETci` package also has new capabilities to estimate the uncertainty of these WRTDS_K estimates. See [Graphics for Prediction Intervals](https://doi-usgs.github.io/EGRETci/articles/prediction.html). # 5. Analysis of water quality trends using WRTDS. -This topic is discussed extensively in the [EGRET User Guide](https://pubs.usgs.gov/tm/04/a10/pdf/tm4A10.pdf) (pages 38-78) and in the "WRTDS results" section of [Introduction to the EGRET package](https://rconnect.usgs.gov/EGRET/articles/EGRET.html#wrtds-results). All of these descriptions of the WRTDS flow normalization method are built on the assumption that for any given day of the year, the probability distribution of discharge is stationary over all the years being considered. +This topic is discussed extensively in the [EGRET User Guide](https://pubs.usgs.gov/tm/04/a10/pdf/tm4A10.pdf) (pages 38-78) and in the "WRTDS results" section of [Introduction to the EGRET package](https://doi-usgs.github.io/EGRET/articles/EGRET.html#wrtdsResults). All of these descriptions of the WRTDS flow normalization method are built on the assumption that for any given day of the year, the probability distribution of discharge is stationary over all the years being considered. What that means is that we assume that the probability distribution of discharge on, for example, March 5, 1985 was the same as the probability distribution on, for example, March 5, 2021. It doesn’t mean that we actually know that distribution exactly for those dates, but rather it means that we assume it to be unchanged from one year to another year. In other words, we are willing to assume that discharge is free of any long-term trend. We all recognize that in the real world this assumption is never perfectly correct. We know that many factors may be influencing the probability distribution of discharge. These include for example: land-use change (such as urban development or land drainage), groundwater depletion (influencing base flow to the stream), climate change (influencing precipitation amount and type as well as temperature), or changes in storage or diversion of water upstream. The probability distribution of discharge can also respond to quasi-periodic oscillations of the regional climate causing a region to experience decadal or longer periods of persistently dry or persistently wet conditions. These oscillations can be very difficult to distinguish from long-term trends. All of the applications of WRTDS up to 2019 were built on this assumption of discharge stationarity. Starting in 2019, with the publication of [Choquette et al., 2019](https://doi.org/10.1016/j.jglr.2018.11.012), a different approach was considered for flow normalization. This is known as **Generalized Flow Normalization** (GFN) in contrast with **Stationary Flow Normalization** (SFN) which was the original assumption. ### 5a. Trends based on Stationary Flow Normalization (SFN). -The concepts and functions from earlier versions of the EGRET software remain in the new version as they were. The primary function for doing these analyses continues to be [modelEstimation( )](https://rconnect.usgs.gov/EGRET/reference/modelEstimation.html) and the functions for viewing trend results continue to be [plotConcHist( )](https://rconnect.usgs.gov/EGRET/reference/plotConcHist.html), [plotFluxHist( )](https://rconnect.usgs.gov/EGRET/reference/plotFluxHist.html), [tableChange( )](https://rconnect.usgs.gov/EGRET/reference/tableChange.html), [tableResulsts( )](https://rconnect.usgs.gov/EGRET/reference/tableResults.html), [plotContours( )](https://rconnect.usgs.gov/EGRET/reference/plotContours.html), and [plotDiffContours( )](https://rconnect.usgs.gov/EGRET/reference/plotDiffContours.html). When the water quality data set is shorter than about 20 years the SFN approach is really the only viable approach. A time period this short is just simply not amenable to characterizing the magnitude and nature of the discharge trend. Also, when the data sets are longer than 20 years and evaluation of the discharge record does not reveal any substantial monotonic trend over the record, the Stationary Flow Normalization approach should be the preferred approach. Trends in discharge that are in the range of 10% change over the period of the water quality record should use SFN. EGRET contains tools that can quantify [streamflow trends](https://rconnect.usgs.gov/EGRET/articles/streamflow_trend.html). +The concepts and functions from earlier versions of the EGRET software remain in the new version as they were. The primary function for doing these analyses continues to be `modelEstimation()` and the functions for viewing trend results continue to be `plotConcHist()`, `plotFluxHist()`, `tableChange()`, `tableResulsts()`, `plotContours()`, and `plotDiffContours()`. When the water quality data set is shorter than about 20 years the SFN approach is really the only viable approach. A time period this short is just simply not amenable to characterizing the magnitude and nature of the discharge trend. Also, when the data sets are longer than 20 years and evaluation of the discharge record does not reveal any substantial monotonic trend over the record, the Stationary Flow Normalization approach should be the preferred approach. Trends in discharge that are in the range of 10% change over the period of the water quality record should use SFN. EGRET contains tools that can quantify [streamflow trends](https://doi-usgs.github.io/EGRET/articles/streamflow_trend.html). There has been some new functionality added for trend analysis added to EGRET that can provide flexibility to undertake Generalized Flow Normalization (addressed in section 5b. below) but can also enable the analyst to ask some more specific questions about the trend. These three new functions are the following: -#### 5ai. runPairs( ) +#### 5ai. runPairs -[runPairs( )](https://rconnect.usgs.gov/EGRET/reference/runPairs.html) is designed to address the specific question of how much has the flow-normalized concentration or flow-normalized flux changed from some selected starting year to some selected ending year. The exact same information can be gleaned from [modelEstimation( )](https://rconnect.usgs.gov/EGRET/reference/modelEstimation.html) and then [tableChange( )](https://rconnect.usgs.gov/EGRET/reference/tableChange.html). The advantage of runPairs( ) is that the analysis can take significantly less computer time, because it is not attempting to statistically model all the years between the starting and ending year. The output of runPairs( ) can then be used as input to [runPairsBoot( )](https://rconnect.usgs.gov/EGRETci/reference/runPairsBoot.html) in the EGRETci package to evaluate the uncertainty of the trend. +`runPairs()` is designed to address the specific question of how much has the flow-normalized concentration or flow-normalized flux changed from some selected starting year to some selected ending year. The exact same information can be gleaned from `modelEstimation()` and then `tableChange()`. The advantage of `runPairs()` is that the analysis can take significantly less computer time, because it is not attempting to statistically model all the years between the starting and ending year. The output of `runPairs()` can then be used as input to [EGRETci::runPairsBoot()](https://doi-usgs.github.io/EGRETci/reference/runPairsBoot.html) in the EGRETci package to evaluate the uncertainty of the trend. -#### 5aii. runGroups( ) +#### 5aii. runGroups -The concept in group analysis is that we wish to compare not just two different years as we did in runPairs( ) but rather, to compare one group of years to another group of years. For example, there may be a strategy for nutrient reduction that calls for decreases in average concentrations, or average fluxes, for some period after the strategy went into effect compared to the time before it went into effect. Or perhaps we want to evaluate the consequences of a large investment in pollution control that went into effect fairly abruptly at some point in time and we want to do a "before and after" analysis. The evaluations of trends for these kinds of analyses can’t be gleaned from modelEstimation( ) or runPairs( ). See [runGroups( )](https://rconnect.usgs.gov/EGRET/reference/runGroups.html) for details about the function. Also, the outputs of runGroups( ) can be used as input to [runGroupsBoot( )](https://rconnect.usgs.gov/EGRETci/reference/runGroupsBoot.html) in the EGRETci package to evaluate the uncertainty of the trend. +The concept in group analysis is that we wish to compare not just two different years as we did in `runPairs()` but rather, to compare one group of years to another group of years. For example, there may be a strategy for nutrient reduction that calls for decreases in average concentrations, or average fluxes, for some period after the strategy went into effect compared to the time before it went into effect. Or perhaps we want to evaluate the consequences of a large investment in pollution control that went into effect fairly abruptly at some point in time and we want to do a "before and after" analysis. The evaluations of trends for these kinds of analyses can’t be gleaned from `modelEstimation()` or `runPairs()`. See `runGroups()` for details about the function. Also, the outputs of `runGroups` can be used as input to [EGRETci::runGroupsBoot()](https://doi-usgs.github.io/EGRETci/reference/runGroupsBoot.html) in the EGRETci package to evaluate the uncertainty of the trend. -#### 5aiii. runSeries( ) +#### 5aiii. runSeries -This function produces annual flow-normalized concentrations and fluxes for the entire period being analyzed. This function produces the same type of output as modelEstimation( ). It simply has more options available to it than modelEstimation( ). See [runSeries( )](https://rconnect.usgs.gov/EGRET/reference/runSeries.html) for details about the function. The outputs of runSeries( ) can be used in conjunction with [ciCalculations( )](https://rconnect.usgs.gov/EGRETci/reference/ciCalculations.html) and [plotConcHistBoot( )](https://rconnect.usgs.gov/EGRETci/reference/plotConcHistBoot.html), and [plotFluxHistBoot( )](https://rconnect.usgs.gov/EGRETci/reference/plotFluxHistBoot.html) in the EGRETci package to show confidence intervals on the annual flow-normalized values. +This function produces annual flow-normalized concentrations and fluxes for the entire period being analyzed. This function produces the same type of output as `modelEstimation()`. It simply has more options available to it than `modelEstimation()`. See `runSeries()` for details about the function. The outputs of `runSeries` can be used in conjunction with [EGRETci::ciCalculations()](https://doi-usgs.github.io/EGRETci/reference/ciCalculations.html) and [EGRETci::plotConcHistBoot()](https://doi-usgs.github.io/EGRETci/reference/plotConcHistBoot.html), and [EGRETci::plotFluxHistBoot()](https://doi-usgs.github.io/EGRETci/reference/plotFluxHistBoot.html) in the EGRETci package to show confidence intervals on the annual flow-normalized values. ### 5b. Trends based on Generalized Flow Normalization (GFN) -As discussed above, GFN is designed to account for the role of trends in discharge in the analysis of trends in concentration or flux. See [GFN approach](https://rconnect.usgs.gov/EGRET/articles/Enhancements.html#generalized-flow-normalization-gfn-) for details about how it is implemented. The discussion of the motivations and the mathematics of it are in [Choquette, et al. (2019)](https://doi.org/10.1016/j.jglr.2018.11.012). When GFN is used, any trends that are reported are partitioned into two components. One is the concentration versus discharge trend component (CQTC). The other is the discharge trend component (QTC). The two components are additive, and sum to the total trend. In the case of SFN the QTC is defined as equal to zero and thus the entire trend can be considered the QCTC. +As discussed above, GFN is designed to account for the role of trends in discharge in the analysis of trends in concentration or flux. See [GFN approach](https://doi-usgs.github.io/EGRET/articles/Enhancements.html#generalized-flow-normalization-gfn) for details about how it is implemented. The discussion of the motivations and the mathematics of it are in [Choquette, et al. (2019)](https://doi.org/10.1016/j.jglr.2018.11.012). When GFN is used, any trends that are reported are partitioned into two components. One is the concentration versus discharge trend component (CQTC). The other is the discharge trend component (QTC). The two components are additive, and sum to the total trend. In the case of SFN the QTC is defined as equal to zero and thus the entire trend can be considered the QCTC. -One particular thing to note about implementing GFN is that in preparing the data for use in the analysis it is valuable to make use of the daily discharge for many years both before and after the period of water quality data, to the extent possible. This is different from how the data should be prepared for SFN, where it is suggested that the daily discharge record extend no more than a year before the first water quality sample and no more than a year after the last water quality sample. The functions used for GFN are the same three functions mentioned above: [runPairs( )](https://rconnect.usgs.gov/EGRET/reference/runPairs.html), [runGroups( )](https://rconnect.usgs.gov/EGRET/reference/runGroups.html), and [runSeries( )](https://rconnect.usgs.gov/EGRET/reference/runSeries.html). Each of these functions contains arguments that are used to implement GFN. Uncertainty analysis for these functions can be found in EGRETci in the functions [runPairsBoot( )](https://rconnect.usgs.gov/EGRETci/reference/runPairsBoot.html), [runGroupsBoot( )](https://rconnect.usgs.gov/EGRETci/reference/runGroupsBoot.html), and [ciCalculations( )](https://rconnect.usgs.gov/EGRETci/reference/ciCalculations.html). +One particular thing to note about implementing GFN is that in preparing the data for use in the analysis it is valuable to make use of the daily discharge for many years both before and after the period of water quality data, to the extent possible. This is different from how the data should be prepared for SFN, where it is suggested that the daily discharge record extend no more than a year before the first water quality sample and no more than a year after the last water quality sample. The functions used for GFN are the same three functions mentioned above: `runPairs()`, `runGroups()`, and `runSeries()`. Each of these functions contains arguments that are used to implement GFN. Uncertainty analysis for these functions can be found in EGRETci in the functions [EGRETci::runPairsBoot()](https://doi-usgs.github.io/EGRETci/reference/runPairsBoot.htmll), [EGRETci::runGroupsBoot()](https://doi-usgs.github.io/EGRETci/reference/runGroupsBoot.html), and [EGRETci::ciCalculations()](https://doi-usgs.github.io/EGRETci/reference/ciCalculations.html). ### 5c. Generalized flow normalization with a flow break. -This is used for the situation where there is some singular engineered action that results in a change in the probability distribution of streamflow at some particular time. The new EGRET code allows us to treat discharge as stationary within each of two periods in the record but allows the distribution for the first period to be different from the second period. We call this a [flow break](https://rconnect.usgs.gov/EGRET/articles/Enhancements.html#abrupt-change-in-the-discharge-distribution-1). The most obvious examples would be the completion of a dam upstream of the monitoring site. This needs to be a dam that has a clear impact on discharges at the monitoring site (e.g. decreasing the peak discharges of high flow and/or increasing the low flows). Other changes could include: the removal of a dam, the institution of a new operating policy for the dam (e.g. increasing the size of minimum flows to support habitat), or major new diversions of water into or out of the watershed. There are no well-defined criteria for the magnitude of the change that should trigger the use of a flow break except to say that it should be big enough that comparisons of flow duration curves before and after it show an easily discernible difference. Only use this technique when the change can be clearly seen in the data and is based on some known human action. Even a large dam or diversion, if it only affects the flows from less than half of the watershed area, is probably not a good reason to use this feature. An abrupt change in streamflow conditions that has no clear human driver should not be the basis for using this approach. Again the same three trend functions mentioned above (runPairs( ), runGroups( ), and runSeries( ) ) all have arguments that make it possible to include a flow break in the analysis. +This is used for the situation where there is some singular engineered action that results in a change in the probability distribution of streamflow at some particular time. The new EGRET code allows us to treat discharge as stationary within each of two periods in the record but allows the distribution for the first period to be different from the second period. We call this a [flow break](https://doi-usgs.github.io/EGRET/articles/Enhancements.html#abrupt-change-in-the-discharge-distribution). The most obvious examples would be the completion of a dam upstream of the monitoring site. This needs to be a dam that has a clear impact on discharges at the monitoring site (e.g. decreasing the peak discharges of high flow and/or increasing the low flows). Other changes could include: the removal of a dam, the institution of a new operating policy for the dam (e.g. increasing the size of minimum flows to support habitat), or major new diversions of water into or out of the watershed. There are no well-defined criteria for the magnitude of the change that should trigger the use of a flow break except to say that it should be big enough that comparisons of flow duration curves before and after it show an easily discernible difference. Only use this technique when the change can be clearly seen in the data and is based on some known human action. Even a large dam or diversion, if it only affects the flows from less than half of the watershed area, is probably not a good reason to use this feature. An abrupt change in streamflow conditions that has no clear human driver should not be the basis for using this approach. Again the same three trend functions mentioned above (`runPairs()`, `runGroups()`, and `runSeries()`) all have arguments that make it possible to include a flow break in the analysis. # 6. Abrupt change in water quality. -We refer to this as the **wall**. The idea of the [wall](https://rconnect.usgs.gov/EGRET/articles/Enhancements.html#the-wall-) is to appropriately handle events that you believe would result in a sharp discontinuity in the way that concentrations behave as a function of discharge, year, and season. WRTDS was designed with a working assumption that changes in the concentration-discharge relationship are gradual, responding to changes in behavior of many actors in the watershed. The use of statistical smoothing in time, which is central to WRTDS, is predicated on the idea that the changes in the system are gradual. The gradual changes could be driven by changes in population (and hence wasteloads), changes in land use or land use practices by many landowners, or many changes in point source controls implemented by many dischargers. But we know that there can be situations that depart from that assumption of gradual change. Some obvious ones are: upgrades to a single dominant point source discharge, large infrastructure changes in storm-water management (e.g. tunnel projects in cities that significantly curtail combined sewer overflows), construction or removal of a major dam (causing the pollutant of interest to mix with a large volume of water in the reservoir significantly changing the concentration-discharge relationship and in the most extreme cases virtually eliminating any relationship between concentration and discharge). There is another category of abrupt change that could also be considered, and that is a "reset" of river conditions that may be the result of an extreme flood or extreme drought. The hypothesis is that the behavior of water quality has changed as a result of this extreme event and that this change is not a short-term thing (i.e. the duration of the event) but rather is something that persists for a number of years. The new "wall" concept can provide an effective way to perform a hypothesis test that the event in question brought about a lasting change, and the approach allows us to describe the nature of the change that took place. +We refer to this as the **wall**. The idea of the [wall](https://doi-usgs.github.io/EGRET/articles/Enhancements.html#the-wall) is to appropriately handle events that you believe would result in a sharp discontinuity in the way that concentrations behave as a function of discharge, year, and season. WRTDS was designed with a working assumption that changes in the concentration-discharge relationship are gradual, responding to changes in behavior of many actors in the watershed. The use of statistical smoothing in time, which is central to WRTDS, is predicated on the idea that the changes in the system are gradual. The gradual changes could be driven by changes in population (and hence wasteloads), changes in land use or land use practices by many landowners, or many changes in point source controls implemented by many dischargers. But we know that there can be situations that depart from that assumption of gradual change. Some obvious ones are: upgrades to a single dominant point source discharge, large infrastructure changes in storm-water management (e.g. tunnel projects in cities that significantly curtail combined sewer overflows), construction or removal of a major dam (causing the pollutant of interest to mix with a large volume of water in the reservoir significantly changing the concentration-discharge relationship and in the most extreme cases virtually eliminating any relationship between concentration and discharge). There is another category of abrupt change that could also be considered, and that is a "reset" of river conditions that may be the result of an extreme flood or extreme drought. The hypothesis is that the behavior of water quality has changed as a result of this extreme event and that this change is not a short-term thing (i.e. the duration of the event) but rather is something that persists for a number of years. The new "wall" concept can provide an effective way to perform a hypothesis test that the event in question brought about a lasting change, and the approach allows us to describe the nature of the change that took place. -Conceptually the approach is simple, the analyst specifies the date on which this change takes place, and then the smoothing process involved in estimating the WRTDS model places a "wall" at that specific time. What this means is that estimates of the concentration for any time, discharge and season, that lies prior to the time of the wall, is estimated only from data collected before the wall. Conversely the estimates after the wall are only based on data collected after the wall. The result of this process is that the contour surface seen in [plotContours( )](https://rconnect.usgs.gov/EGRET/reference/plotContours.html) can have a sharp break at a vertical line where the wall is located. +Conceptually the approach is simple, the analyst specifies the date on which this change takes place, and then the smoothing process involved in estimating the WRTDS model places a "wall" at that specific time. What this means is that estimates of the concentration for any time, discharge and season, that lies prior to the time of the wall, is estimated only from data collected before the wall. Conversely the estimates after the wall are only based on data collected after the wall. The result of this process is that the contour surface seen in `plotContours()` can have a sharp break at a vertical line where the wall is located. -The idea of using this as a way of testing if some specific action brought about a statistically significant change in water quality can be accomplished by using the [runGroups( )](https://rconnect.usgs.gov/EGRET/reference/runGroups.html) function and letting the two groups be distinguished by being either before or after the wall. The confidence level or uncertainty of this before and after difference can then be determined in using [runGroupsBoot( )](https://rconnect.usgs.gov/EGRETci/reference/runGroupsBoot.html) in the EGRETci package. The wall can also be implemented in the [runPairs( )](https://rconnect.usgs.gov/EGRET/reference/runPairs.html) and [runSeries( )](https://rconnect.usgs.gov/EGRET/reference/runSeries.html) functions as well. +The idea of using this as a way of testing if some specific action brought about a statistically significant change in water quality can be accomplished by using the `runGroups()` function and letting the two groups be distinguished by being either before or after the wall. The confidence level or uncertainty of this before and after difference can then be determined in using [EGRETci::runGroupsBoot()](https://doi-usgs.github.io/EGRETci/reference/runGroupsBoot.html) in the EGRETci package. The wall can also be implemented in the `runPairs()` and `runSeries()` functions as well. # 7. Seasonal analysis of trends -Sometimes it is of interest to understand if there may be trends in water quality in some seasons and not in other seasons, or even trends in opposite directions for different seasons. There are scripts that can be used to evaluate the water quality [trends in different seasons](https://rconnect.usgs.gov/EGRET/articles/SeasonalFraction.html) or to show a graph of the months displaying the seasonal pattern of fluxes by month and the change over several years of these [monthly fluxes](https://rconnect.usgs.gov/EGRET/articles/TrendsByMonth.html). +Sometimes it is of interest to understand if there may be trends in water quality in some seasons and not in other seasons, or even trends in opposite directions for different seasons. There are scripts that can be used to evaluate the water quality [trends in different seasons](https://doi-usgs.github.io/EGRET/articles/SeasonalFraction.html) or to show a graph of the months displaying the seasonal pattern of fluxes by month and the change over several years of these [monthly fluxes](https://doi-usgs.github.io/EGRET/articles/TrendsByMonth.html). # 8. Parallel computing -Because EGRET can be computationally intensive, and EGRETci even more intensive, there are a set of techniques provided to run EGRET processes in parallel and thus greatly compress the amount of time required to complete a large analysis that covers many sites and many analytes. EGRET and EGRETci allow for [parallel computing](https://rconnect.usgs.gov/EGRET/articles/parallel.html). These techniques can be executed on a single computer with several cores, or they can be executed across a large array of connected computers. +Because EGRET can be computationally intensive, and EGRETci even more intensive, there are a set of techniques provided to run EGRET processes in parallel and thus greatly compress the amount of time required to complete a large analysis that covers many sites and many analytes. EGRET and EGRETci allow for [parallel computing](https://doi-usgs.github.io/EGRET/articles/parallel.html). These techniques can be executed on a single computer with several cores, or they can be executed across a large array of connected computers. -# 9. errorStats( ) to describe the overall accuracy of a WRTDS model +# 9. errorStats to describe the overall accuracy of a WRTDS model -Sometimes it is useful to have statistics that describe the magnitude of the errors in a WRTDS model, the way we would for a multiple linear regression. A function called [errorStats( )](https://rconnect.usgs.gov/EGRET/reference/errorStats.html) has been added to the EGRET package. It computes the equivalent of an R-squared value (like in multiple regression). The R-squared is computed on the log of the concentration as well as on the log of the flux. It also provides a root mean squared error and a standard error of prediction in percent. It can provide a useful tool for comparison to similar water quality statistical models, or for comparing different settings for the three window parameters of the WRTDS model (windowY, windowS, and windowQ). +Sometimes it is useful to have statistics that describe the magnitude of the errors in a WRTDS model, the way we would for a multiple linear regression. A function called `errorStats()` has been added to the EGRET package. It computes the equivalent of an R-squared value (like in multiple regression). The R-squared is computed on the log of the concentration as well as on the log of the flux. It also provides a root mean squared error and a standard error of prediction in percent. It can provide a useful tool for comparison to similar water quality statistical models, or for comparing different settings for the three window parameters of the WRTDS model (windowY, windowS, and windowQ). # 10. Dealing with problems of model convergence -On rare occasions the WRTDS estimation process fails to converge numerically, or results in highly unreasonable results (e.g. estimated concentrations that are far beyond the limits of those observed in the record). These problems are very rare in EGRET, but they can be a little more common in EGRETci, because of the odd properties that the bootstrap samples can have. A fix for these rare cases has been developed for the EGRET package, and it is also used in the EGRETci package. Because these problems are sometimes related to multicollinearity in the Sample data, the idea is to add some "jitter" (small amounts of random noise) to the time and discharge data. This often solves the numerical problems. It should only be used if there is a clear problem with the results. The function used is called [jitterSam( )](https://rconnect.usgs.gov/EGRET/reference/jitterSam.html). Its use is primarily in functions in the EGRETci package. +On rare occasions the WRTDS estimation process fails to converge numerically, or results in highly unreasonable results (e.g. estimated concentrations that are far beyond the limits of those observed in the record). These problems are very rare in EGRET, but they can be a little more common in EGRETci, because of the odd properties that the bootstrap samples can have. A fix for these rare cases has been developed for the EGRET package, and it is also used in the EGRETci package. Because these problems are sometimes related to multicollinearity in the Sample data, the idea is to add some "jitter" (small amounts of random noise) to the time and discharge data. This often solves the numerical problems. It should only be used if there is a clear problem with the results. The function used is called `jitterSam()`. Its use is primarily in functions in the EGRETci package. # 11. Alternative discharge variables in the WRTDS model -Sometimes the usual formulation of WRTDS is not ideal because we believe that the daily discharge on the sampling day is not a very good explanatory variable and we have an idea of a better variable we might use. Dams and reservoirs create situations where this may be an issue. It may turn out that a better explanatory variable model for the WRTDS model might be a rolling-mean of discharges over some period of many days up to (and including) the sampled day instead of the daily discharge on the sampling day. There is an article describing this concept and a script for making such an analysis using an [alternative Q variable](https://rconnect.usgs.gov/EGRET/articles/AlternativeQMethod.html). +Sometimes the usual formulation of WRTDS is not ideal because we believe that the daily discharge on the sampling day is not a very good explanatory variable and we have an idea of a better variable we might use. Dams and reservoirs create situations where this may be an issue. It may turn out that a better explanatory variable model for the WRTDS model might be a rolling-mean of discharges over some period of many days up to (and including) the sampled day instead of the daily discharge on the sampling day. There is an article describing this concept and a script for making such an analysis using an [alternative Q variable](https://doi-usgs.github.io/EGRET/articles/AlternativeQMethod.html). # **Enhancements of EGRETci** -As mentioned above EGRETci is an R package, closely related to EGRET. It runs a variety of analyses that can provide information about the uncertainty of any of the trend results that are run in EGRET. These outputs include p-values that can be used for hypothesis tests, confidence intervals on the magnitude of annual flow-normalized values, and also likelihood measures that can provide an indication of how confident we should be that the sign of the estimated change is actually the correct sign (e.g. our estimate of trend said it was upward, what's the chance it might actually be downward?). These techniques, for evaluating trend results are described in detail in the [Guide to EGRETci 2.0 enhancements](https://rconnect.usgs.gov/EGRETci/articles/Enhancements.html). +As mentioned above EGRETci is an R package, closely related to EGRET. It runs a variety of analyses that can provide information about the uncertainty of any of the trend results that are run in EGRET. These outputs include p-values that can be used for hypothesis tests, confidence intervals on the magnitude of annual flow-normalized values, and also likelihood measures that can provide an indication of how confident we should be that the sign of the estimated change is actually the correct sign (e.g. our estimate of trend said it was upward, what's the chance it might actually be downward?). These techniques, for evaluating trend results are described in detail in the [Guide to EGRETci 2.0 enhancements](https://doi-usgs.github.io/EGRET/articles/Enhancements.html). -In addition, there is now a set of functions in EGRETci which allow one to quantify the uncertainty about individual values (not flow-normalized) of average concentration or average flux. Here's an example of how these results might be used. A colleague has a deterministic model of a particular lake that predicts the summertime chlorophyl a concentration based on the nutrient input over recent months as well as air temperature, sunlight, precipitation and other variables relevant to the processes involved. The colleague asks for your estimates of the actual time series of N and P inputs to the lake at a monthly time step for a period of several years. You provide your colleague with a time series of the WRTDSKalman estimates of the flux for each of these months. They say "Thanks, but can you quantify your uncertainty about those values. Can you place confidence intervals around those values. Is the 90% confidence interval on the order of +/- 5%, or more like 20% or even worse 50%?" These techniques are designed to provide answers to those kinds of questions. They are designed to calculate prediction intervals for daily, monthly, or annual averages of concentration or flux. These methods are described in detail in [Graphics for Prediction Intervals](https://rconnect.usgs.gov/EGRETci/articles/prediction.html). They also provide the means to graphically depict the proability of concentration values exceeding some regulatory threshold value. +In addition, there is now a set of functions in EGRETci which allow one to quantify the uncertainty about individual values (not flow-normalized) of average concentration or average flux. Here's an example of how these results might be used. A colleague has a deterministic model of a particular lake that predicts the summertime chlorophyl a concentration based on the nutrient input over recent months as well as air temperature, sunlight, precipitation and other variables relevant to the processes involved. The colleague asks for your estimates of the actual time series of N and P inputs to the lake at a monthly time step for a period of several years. You provide your colleague with a time series of the WRTDSKalman estimates of the flux for each of these months. They say "Thanks, but can you quantify your uncertainty about those values. Can you place confidence intervals around those values. Is the 90% confidence interval on the order of +/- 5%, or more like 20% or even worse 50%?" These techniques are designed to provide answers to those kinds of questions. They are designed to calculate prediction intervals for daily, monthly, or annual averages of concentration or flux. These methods are described in detail in [Graphics for Prediction Intervals](https://doi-usgs.github.io/EGRETci/articles/prediction.html). They also provide the means to graphically depict the probability of concentration values exceeding some regulatory threshold value.