Skip to content

Commit 07901f2

Browse files
committed
Update for renamed smwr pacakges
1 parent 6606c1d commit 07901f2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+159
-95
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
src-i386
22
src-x64
3+
.Rbuildignore

DESCRIPTION

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
Package: rloadest
22
Type: Package
33
Title: River Load Estimation
4-
Version: 0.3.0
5-
Date: 2014-08-08
4+
Version: 0.4.0
5+
Date: 2015-02-27
66
Author: Dave Lorenz, Rob Runkel, Laura De Cicco
77
Maintainer: Dave Lorenz <[email protected]>
88
Description: Collection of functions to make constituent load estimations
99
based on the LOADEST program.
1010
License: File LICENSE
1111
Depends:
1212
R (>= 3.0.0),
13-
USGSwsGraphs,
14-
USGSwsStats,
15-
USGSwsQW
13+
smwrGraphs,
14+
smwrStats,
15+
smwrQW
1616
Imports:
1717
stats
1818
Suggests:
19-
USGSwsBase
19+
smwrBase,
20+
dataRetrieval
2021
LazyLoad: yes
2122
LazyData: yes

NAMESPACE

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Generated by roxygen2 (4.0.1): do not edit by hand
1+
# Generated by roxygen2 (4.0.2): do not edit by hand
22

33
S3method(coef,loadReg)
44
S3method(fitted,loadReg)
@@ -27,9 +27,9 @@ export(predLoad)
2727
export(resampleUVdata)
2828
export(selBestModel)
2929
export(selBestSubset)
30-
import(USGSwsGraphs)
31-
import(USGSwsQW)
32-
import(USGSwsStats)
30+
import(smwrGraphs)
31+
import(smwrQW)
32+
import(smwrStats)
3333
importFrom(stats,logLik)
3434
importFrom(stats,makepredictcall)
3535
importFrom(stats,step)

R/loadReg.R

+15-4
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@
2020
#'flow column.
2121
#' @param dates character string indicating the name of the
2222
#'date column.
23-
#' @param flow.units character string describing the flow units.
23+
#' @param flow.units character string describing the flow units. See \bold{Details}.
2424
#' @param conc.units character string describing the concentration
25-
#'unit.
26-
#' @param load.units character string describing the load unit.
25+
#'unit. See \bold{Details}.
26+
#' @param load.units character string describing the load unit. See \bold{Details}.
2727
#' @param time.step character string describing the time step of
2828
#'the calibration data. Must be one of "instantaneous," "2 hours," "3 hours,"
2929
#'"4 hours," "6 hours," "12 hours," or "day." The default is "day."
@@ -45,7 +45,7 @@
4545
#' station="Illinois River at Marseilles, Ill.")
4646
#'print(app1.lr)
4747
#'
48-
#' @import USGSwsQW
48+
#' @import smwrQW
4949
#' @export
5050
loadReg <- function(formula, data, subset, na.action, flow, dates,
5151
flow.units="cfs", conc.units="", load.units="kg",
@@ -62,6 +62,12 @@ loadReg <- function(formula, data, subset, na.action, flow, dates,
6262
"8 hours", "12 hours", "day"))
6363
call <- match.call()
6464
m <- match.call(expand.dots = FALSE)
65+
Terms <- attr(m, "terms")
66+
## Make sure that the formula is a formula and not a symbol--this
67+
# improves output and subsequent formula references
68+
if (typeof(call$formula) == "symbol") {
69+
call$formula <- formula(Terms)
70+
}
6571
## remove components not needed for model.frame
6672
m$flow <- m$dates <- m$flow.units <- m$conc.units <- NULL
6773
m$load.units <- m$time.step <- m$station <- NULL
@@ -246,6 +252,11 @@ loadReg <- function(formula, data, subset, na.action, flow, dates,
246252
lfit$xlevels <- xlevels
247253
class(lfit) <- "censReg"
248254
## Construct the evaluation data frame
255+
## Capture errors
256+
if(lfit$IERR > 0L) {
257+
lfit$AIC <- lfit$SPPC <- Inf
258+
lfit$LLR <- -Inf
259+
}
249260
MEC <- data.frame(model=model.no, AIC=lfit$AIC, SPCC=lfit$SPPC)
250261
retval <- list(station=station, constituent=ynam,
251262
flow=flow, dates=dates, Qadj=Qadj,

R/plot.loadReg.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
#'# Produce the full suite of diagnostic plots
4040
#'plot(app1.lr)
4141
#'}
42-
#' @import USGSwsGraphs
42+
#' @import smwrGraphs
4343
#' @export
4444
#' @method plot loadReg
4545
plot.loadReg <- function(x, which='All', set.up=TRUE, span=1.0, ...) {

R/predConc.R

+6-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
#'are not permitted in any column in \code{newdata}. Observations with
2121
#'missing values \code{NAs} must be removed before prediction. Columns that
2222
#'are not needed for prediction that contain missing values can be removed
23-
#'before removing all rows with missing values.
23+
#'before removing all rows with missing values. The maximum number of rows
24+
#'permitted in \code{newdata} is 176000.
2425
#' @param by the time frame for estimates. See \code{Details}.
2526
#' @param allow.incomplete compute loads for periods withing
2627
#'missing values or incomplete record? See \code{Details}.
@@ -47,6 +48,8 @@ predConc <- function(fit, newdata, by="day",
4748
## By options and other preliminary code
4849
if(any(is.na(newdata)))
4950
stop("newdata contains missing values, remove before prediction")
51+
if(nrow(newdata) > 176000L)
52+
stop("newdata has too many rows, the size limit is 176000")
5053
ByOpt <- c("unit", "day")
5154
Qadj <- fit$Qadj
5255
Tadj <- fit$Tadj
@@ -194,7 +197,7 @@ predConc <- function(fit, newdata, by="day",
194197
## Preserve flow for later
195198
Flow <- newdata[[flow]]
196199
if(time.step == "day") {
197-
KDate <- as.Date(newdata[[dates]])
200+
KDate <- as.Date(as.POSIXlt(newdata[[dates]]))
198201
KDays <- seq(nrow(model.inp))
199202
KinAll <- KDays
200203
## Exclude NAs and presumably 0 flows
@@ -204,7 +207,7 @@ predConc <- function(fit, newdata, by="day",
204207
} else {
205208
Kin <- seq(nrow(model.inp))
206209
Kin <- Kin[is.finite(rowSums(model.inp))]
207-
KDate <- as.Date(newdata[[dates]])
210+
KDate <- as.Date(as.POSIXlt(newdata[[dates]]))
208211
Kdy <- as.integer(KDate)
209212
KDate <- unique(KDate)
210213
Kdy <- Kdy - Kdy[1L] + 1L # make relative to first day (Index)

R/predLoad.R

+7-4
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,12 @@
2121
#'the prediction intervals, computed from the SEP.
2222
#'
2323
#' @param fit the output from \code{loadReg}.
24-
#' @param newdata a data frame of the prediction variables. MIssing values
24+
#' @param newdata a data frame of the prediction variables. Missing values
2525
#'are not permitted in any column in \code{newdata}. Observations with
2626
#'missing values \code{NAs} must be removed before prediction. Columns that
2727
#'are not needed for prediction that contain missing values can be removed
28-
#'before removing all rows with missing values.
28+
#'before removing all rows with missing values. The maximum number of rows
29+
#'permitted in \code{newdata} is 176000.
2930
#' @param load.units a character string indicating the units of the
3031
#'predicted loads/fluxes. By default, uses the value specified in
3132
#'\code{loadReg}. See \code{\link{loadReg}} for a complete list of options.
@@ -64,6 +65,8 @@ predLoad <- function(fit, newdata, load.units=fit$load.units, by="total",
6465
## By options and other preliminary code
6566
if(any(is.na(newdata)))
6667
stop("newdata contains missing values, remove before prediction")
68+
if(nrow(newdata) > 176000L)
69+
stop("newdata has too many rows, the size limit is 176000")
6770
ByOpt <- c("unit", "day", "month", "water year", "calendar year", "total")
6871
load.units
6972
seopt <- match.arg(seopt, c("exact", "approximate"))
@@ -222,7 +225,7 @@ predLoad <- function(fit, newdata, load.units=fit$load.units, by="total",
222225
## Preserve flow for later
223226
Flow <- newdata[[flow]]
224227
if(time.step == "day") {
225-
KDate <- as.Date(newdata[[dates]])
228+
KDate <- as.Date(as.POSIXlt(newdata[[dates]]))
226229
KDays <- seq(nrow(model.inp))
227230
KinAll <- KDays
228231
## Exclude NAs and presumably 0 flows
@@ -232,7 +235,7 @@ predLoad <- function(fit, newdata, load.units=fit$load.units, by="total",
232235
} else {
233236
Kin <- seq(nrow(model.inp))
234237
Kin <- Kin[is.finite(rowSums(model.inp))]
235-
KDate <- as.Date(newdata[[dates]])
238+
KDate <- as.Date(as.POSIXlt(newdata[[dates]]))
236239
Kdy <- as.integer(KDate)
237240
KDate <- unique(KDate)
238241
Kdy <- Kdy - Kdy[1L] + 1L # make relative to first day (Index)

R/print.loadReg.R

+19
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#' @note The printed output includes the call, the coefficent table, the
1212
#'estimated residual standard error, the log-likelihood of the model and
1313
#'null model with the attained p-value, and the computational method.
14+
#' NEED more details about what is printed and the difference in output due to arguments
1415
#' @seealso \code{\link{loadReg}}
1516
#' @keywords utilities
1617
#'
@@ -30,6 +31,24 @@ print.loadReg <- function(x, digits=4, brief=TRUE, load.only=brief, ...) {
3031
## Print the results of the input data and model evaluation.
3132
## to nearly match the output from LOADEST if brief is FALSE
3233
load.only
34+
## Catch errors/warnings
35+
if(x$lfit$IERR == -201L) {
36+
warning("Excessive censoring, greater than 80%")
37+
} else if(x$lfit$IERR == -202L) {
38+
warning("Excessive censoring, fewer than 3 uncensored values for each parameter")
39+
} else if(x$lfit$IERR == 1L) {
40+
stop("Too many parameters")
41+
} else if(x$lfit$IERR == 2L) {
42+
stop("Too many observations")
43+
} else if(x$lfit$IERR == 201L) {
44+
stop("Excessive censoring, greater than 90%")
45+
} else if(x$lfit$IERR == 202L) {
46+
stop("Excessive censoring, fewer than 1.5 uncensored values for each parameter")
47+
} else if(x$lfit$IERR == 203L) {
48+
stop("Variance of uncensored values is 0")
49+
} else if(x$lfit$IERR > 0L) {
50+
stop("\nFatal error in censReg, error code: ", x$IERR, "\n")
51+
}
3352
if(brief)
3453
cat("*** Load Estimation ***\n\n")
3554
else {

R/rloadest-package.R

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
#' \tabular{ll}{
44
#' Package: \tab LOADEST\cr
55
#' Type: \tab Package\cr
6-
#' Version: \tab 0.3.0\cr
7-
#' Date: \tab 2014-08-08\cr
8-
#' License: \tab GPL 2\cr
6+
#' Version: \tab 0.4.0\cr
7+
#' Date: \tab 2015-02-27\cr
8+
#' License: \tab File\cr
99
#' LazyLoad: \tab yes\cr
1010
#' }
1111
#'

R/rmse.loadReg.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#' flow = "FLOW", dates = "DATES", conc.units="mg/L",
1919
#' station="Illinois River at Marseilles, Ill.")
2020
#'rmse(app1.lr)
21-
#' @import USGSwsStats
21+
#' @import smwrStats
2222
#' @export
2323
#' @method rmse loadReg
2424
rmse.loadReg <- function(x, model=c("load", "concentration"), ...) {

R/selBestModel.R

+4
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ selBestModel <- function(constituent, data, subset, na.action, flow, dates,
6464
}
6565
}
6666
options(warn)
67+
## But warn if fewer N than 70
68+
if(model$lfit$NOBSC < 70L)
69+
warning("Selected model may be over fit: only ",
70+
model$lfit$NOBSC, " observations.")
6771
## Replace model.eval with complete list
6872
retval$model.eval <- model.eval
6973
return(retval)

R/selBestSubset.R

+6-2
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,15 @@ selBestSubset <- function(formula, min.formula=~1, data, subset, na.action, flow
9191
m$dist <- "lognormal"
9292
k <- if(criterion == "AIC") 2 else log(nrow(df))
9393
m <- eval(m)
94-
best <- step(m, scope=min.formula, direction="both", trace=0, k=k)
94+
## Warn if fewer N than 10*potential params
95+
if(m$NOBSC < 10L * (m$NPAR - 1L))
96+
warning("Selected model may be over fit: only ",
97+
m$NOBSC, " observations for ", m$NPAR, " possible parameters.")
98+
best <- step(m, scope=min.formula, direction="both", trace=0, k=k)
9599
# retain the step wise model selections
96100
model.eval <- best$anova
97101
names(model.eval)[[6L]] <- criterion # Fix this to represent what was really done
98-
# No build the load model
102+
# Now build the load model
99103
m <- call
100104
m[[1L]] <- as.name("loadReg")
101105
m$min.formula <- m$criterion <- NULL

R/vif.loadReg.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#' station="Illinois River at Marseilles, Ill.")
1616
#'vif(app1.lr, app1.calib)
1717
#' @keywords regression
18-
#' @import USGSwsStats
18+
#' @import smwrStats
1919
#' @export
2020
#' @method vif loadReg
2121
vif.loadReg <- function(model, ...) {

demo/BatchLoad.r

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ ld.unt <- "kg"
1515
# ** End of user input **
1616

1717
# Set the required libraries
18+
library(dataRetrieval)
1819
library(rloadest)
1920

2021
# Loop for each station
@@ -27,7 +28,7 @@ for(sta in Staids) {
2728
# Get the flow and water-quality data--use temporary dataset
2829
# names that can be overwritten to manipulate and then save
2930
# in the names provided above.
30-
Qtmp <- renCol(readNWIS(sta, begin.date=Start, end.date=End))
31+
Qtmp <- renameNWISColumns(readNWISdv(sta, "00060", startDate=Start, endDate=End))
3132
QWtmp <- importNWISqw(sta, params=Params, begin.date=Start,
3233
end.date=End, use.pnames=TRUE)
3334
# Make sure that the recorded values are daily averages

inst/doc/app3.pdf

1.27 KB
Binary file not shown.

man/AICc.Rd

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
% Generated by roxygen2 (4.0.1): do not edit by hand
1+
% Generated by roxygen2 (4.0.2): do not edit by hand
22
\name{AICc}
33
\alias{AICc}
44
\title{Akaike's An Information Criterion with Correction}

man/Atrazine.Rd

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
% Generated by roxygen2 (4.0.1): do not edit by hand
1+
% Generated by roxygen2 (4.0.2): do not edit by hand
22
\docType{data}
33
\name{Atrazine}
44
\alias{Atrazine}

man/LOADEST-package.Rd

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
% Generated by roxygen2 (4.0.1): do not edit by hand
1+
% Generated by roxygen2 (4.0.2): do not edit by hand
22
\docType{package}
33
\name{LOADEST-package}
44
\alias{LOADEST-package}
@@ -7,9 +7,9 @@
77
\tabular{ll}{
88
Package: \tab LOADEST\cr
99
Type: \tab Package\cr
10-
Version: \tab 0.3.0\cr
11-
Date: \tab 2014-08-08\cr
12-
License: \tab GPL 2\cr
10+
Version: \tab 0.4.0\cr
11+
Date: \tab 2015-02-27\cr
12+
License: \tab File\cr
1313
LazyLoad: \tab yes\cr
1414
}
1515
}

man/c2load.Rd

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
% Generated by roxygen2 (4.0.1): do not edit by hand
1+
% Generated by roxygen2 (4.0.2): do not edit by hand
22
\name{c2load}
33
\alias{c2load}
44
\title{Loads}

man/center.Rd

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
% Generated by roxygen2 (4.0.1): do not edit by hand
1+
% Generated by roxygen2 (4.0.2): do not edit by hand
22
\name{center}
33
\alias{center}
44
\title{Centered Linear Terms}

man/coef.loadReg.Rd

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
% Generated by roxygen2 (4.0.1): do not edit by hand
1+
% Generated by roxygen2 (4.0.2): do not edit by hand
22
\name{coef.loadReg}
33
\alias{coef.loadReg}
44
\title{Extract Model Coefficients}

man/dailyAg.Rd

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
% Generated by roxygen2 (4.0.1): do not edit by hand
1+
% Generated by roxygen2 (4.0.2): do not edit by hand
22
\name{dailyAg}
33
\alias{dailyAg}
44
\title{Daily Mean}

man/fitted.loadReg.Rd

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
% Generated by roxygen2 (4.0.1): do not edit by hand
1+
% Generated by roxygen2 (4.0.2): do not edit by hand
22
\name{fitted.loadReg}
33
\alias{fitted.loadReg}
44
\title{Extract Model Fitted Values}

man/loadConvFactor.Rd

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
% Generated by roxygen2 (4.0.1): do not edit by hand
1+
% Generated by roxygen2 (4.0.2): do not edit by hand
22
\name{loadConvFactor}
33
\alias{loadConvFactor}
44
\title{Unit Conversion}

man/loadReg.Rd

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
% Generated by roxygen2 (4.0.1): do not edit by hand
1+
% Generated by roxygen2 (4.0.2): do not edit by hand
22
\name{loadReg}
33
\alias{loadReg}
44
\title{Load Estimation}
@@ -21,12 +21,12 @@ flow column.}
2121
\item{dates}{character string indicating the name of the
2222
date column.}
2323

24-
\item{flow.units}{character string describing the flow units.}
24+
\item{flow.units}{character string describing the flow units. See \bold{Details}.}
2525

2626
\item{conc.units}{character string describing the concentration
27-
unit.}
27+
unit. See \bold{Details}.}
2828

29-
\item{load.units}{character string describing the load unit.}
29+
\item{load.units}{character string describing the load unit. See \bold{Details}.}
3030

3131
\item{time.step}{character string describing the time step of
3232
the calibration data. Must be one of "instantaneous," "2 hours," "3 hours,"

man/loadReport.Rd

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
% Generated by roxygen2 (4.0.1): do not edit by hand
1+
% Generated by roxygen2 (4.0.2): do not edit by hand
22
\name{loadReport}
33
\alias{loadReport}
44
\title{Create Load Report}

man/loadStats.Rd

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
% Generated by roxygen2 (4.0.1): do not edit by hand
1+
% Generated by roxygen2 (4.0.2): do not edit by hand
22
\name{loadStats}
33
\alias{loadStats}
44
\title{Summary Statistics}

0 commit comments

Comments
 (0)