aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog12
-rw-r--r--R/twa.R16
-rw-r--r--man/max_twa.Rd6
3 files changed, 30 insertions, 4 deletions
diff --git a/ChangeLog b/ChangeLog
index 318f3c2..3aff70c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+commit 74ed85b07f09ea99476208749cd274a476ba4536
+Author: Johannes Ranke <jranke@uni-bremen.de>
+Date: 2017-01-19 09:27:36 +0100
+
+ Documentation updates
+
+commit a6d61c06d573574cf574ed893cc13808a9e8b785
+Author: Johannes Ranke <jranke@uni-bremen.de>
+Date: 2017-01-19 09:20:22 +0100
+
+ Fix order of arguments to one_box, correct docs
+
commit b8ac1393b9e1bef8c48b26b790cf5759ccd69fed
Author: Johannes Ranke <jranke@uni-bremen.de>
Date: 2017-01-19 09:10:37 +0100
diff --git a/R/twa.R b/R/twa.R
index dd3196a..fcf49c0 100644
--- a/R/twa.R
+++ b/R/twa.R
@@ -79,14 +79,14 @@ one_box.character <- function(x, parms, ...,
"x has to be one of\n ",
paste(parent_models_available, collapse = ", "))
}
-
+
if (!setequal(names(parms), m$par)) {
stop("Please supply the parameters\n",
paste(m$par, collapse = ", "))
}
t_out <- seq(0, t_end, by = res)
- pred <- mkinpredict(m, odeparms = parms, odeini = c(parent = 1),
+ pred <- mkinpredict(m, odeparms = parms, odeini = c(parent = 1),
outtimes = t_out, solution_type = "analytical")[-1]
result <- ts(pred, 0, t_end, frequency = 1/res)
class(result) <- c("one_box", "ts")
@@ -130,7 +130,7 @@ one_box.mkinfit <- function(x, ..., t_end = 100, res = 0.01) {
#' dfop_pred <- one_box("DFOP", parms = c(k1 = 0.2, k2 = 0.02, g = 0.7))
#' plot(dfop_pred)
#' plot(sawtooth(dfop_pred, 3, 7), max_twa = 21)
-#'
+#'
#' # Use a fitted mkinfit model
#' m_2 <- mkinmod(parent = mkinsub("SFO", "m1"), m1 = mkinsub("SFO"))
#' fit_2 <- mkinfit(m_2, FOCUS_2006_D, quiet = TRUE)
@@ -227,6 +227,11 @@ twa <- function(x, window = 21) UseMethod("twa")
#' @export
twa.one_box <- function(x, window = 21)
{
+ length_ts <- end(x) - start(x)
+ if (window >= length_ts[1]) {
+ stop("The window must be smaller than the length of the time series")
+ }
+
resolution = 1/frequency(x)
n_filter = window/resolution
result = filter(x, rep(1/n_filter, n_filter), method = "convolution", sides = 1)
@@ -237,6 +242,11 @@ twa.one_box <- function(x, window = 21)
#' The maximum time weighted average concentration for a moving window
#'
+#' If you generate your time series using \code{\link{sawtooth}},
+#' you need to make sure that the length of the time series allows
+#' for finding the maximum. It is therefore recommended to check this using
+#' \code{\link{plot.one_box}} using the window size for the argument
+#' \code{max_twa}.
#' @seealso \code{\link{twa}}
#' @inheritParams twa
#' @export
diff --git a/man/max_twa.Rd b/man/max_twa.Rd
index 86cc174..e39165a 100644
--- a/man/max_twa.Rd
+++ b/man/max_twa.Rd
@@ -12,7 +12,11 @@ max_twa(x, window = 21)
\item{window}{The size of the moving window}
}
\description{
-The maximum time weighted average concentration for a moving window
+If you generate your time series using \code{\link{sawtooth}},
+you need to make sure that the length of the time series allows
+for finding the maximum. It is therefore recommended to check this using
+\code{\link{plot.one_box}} using the window size for the argument
+\code{max_twa}.
}
\seealso{
\code{\link{twa}}

Contact - Imprint