From 2ab822d51c4c7e29d62076336d7a3f02a46e41a5 Mon Sep 17 00:00:00 2001 From: Johannes Ranke Date: Thu, 19 Jan 2017 11:41:19 +0100 Subject: Corrections in the documentation --- ChangeLog | 12 ++++++++++++ R/twa.R | 26 ++++++++++++++++---------- docs/reference/one_box.html | 25 ++++++++++++++++++------- man/one_box.Rd | 20 ++++++++++++++------ 4 files changed, 60 insertions(+), 23 deletions(-) diff --git a/ChangeLog b/ChangeLog index bcb7553..0a73e39 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +commit 46883a0c3a3c00127a563a7befa0af440573baaa +Author: Johannes Ranke +Date: 2017-01-19 11:22:08 +0100 + + Correct default y axis label for plot.one_box + +commit 3947731a5a8c3598271b26f5201dea4bcb13ef6d +Author: Johannes Ranke +Date: 2017-01-19 10:47:09 +0100 + + Fix one_box for ini = 1, use in sawtooth examples + commit dd30f0d0ff1d8d0cc46aaef6e0917c51fe798f52 Author: Johannes Ranke Date: 2017-01-19 10:36:19 +0100 diff --git a/R/twa.R b/R/twa.R index 7fa6241..75aaf85 100644 --- a/R/twa.R +++ b/R/twa.R @@ -18,15 +18,20 @@ #' Create a time series of decline data #' -#' The time series starts with the amount specified for the first application. -#' This does not create objects of type \code{\link{ts}}. -#' #' @param x When numeric, this is the half-life to be used for an exponential -#' decline. If x is an mkinfit object, the decline is calculated from this object -#' @param ini The initial amount for each compound +#' decline. When a character string specifying a parent decline model is given +#' e.g. \code{FOMC}, \code{parms} must contain the corresponding paramters. +#' If x is an \code{\link{mkinfit}} object, the decline is calculated from this +#' object. +#' @param ini The initial amount for the parent compound. If x is an +#' \code{\link{mkinfit}} object, and ini is 'model', the fitted initial +#' concentrations are used. Otherwise, ini must be numeric. If it has +#' length one, it is used for the parent and initial values of metabolites +#' are zero, otherwise, it must give values for all observed variables. #' @param t_end End of the time series #' @param res Resolution of the time series #' @param ... Further arguments passed to methods +#' @return An object of class \code{one_box}, inheriting from \code{\link{ts}}. #' @importFrom stats filter frequency time ts #' @export #' @examples @@ -59,7 +64,7 @@ one_box.numeric <- function(x, ini = 1, ..., half_life = x k = log(2)/half_life t_out <- seq(0, t_end, by = res) - raw <- matrix(exp( - k * t_out), ncol = 1) + raw <- matrix(ini * exp( - k * t_out), ncol = 1) dimnames(raw) <- list(NULL, "parent") result <- ts(raw, 0, t_end, frequency = 1/res) class(result) <- c("one_box", "ts") @@ -87,7 +92,7 @@ one_box.character <- function(x, ini = 1, parms, ..., } 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 = ini), outtimes = t_out, solution_type = "analytical")[-1] result <- ts(pred, 0, t_end, frequency = 1/res) class(result) <- c("one_box", "ts") @@ -97,13 +102,14 @@ one_box.character <- function(x, ini = 1, parms, ..., #' @rdname one_box #' @importFrom mkin mkinpredict #' @export -one_box.mkinfit <- function(x, ini = c("model", 1), ..., t_end = 100, res = 0.01) { +one_box.mkinfit <- function(x, ini = "model", ..., t_end = 100, res = 0.01) { fit <- x if (ini[1] == "model") { odeini = x$bparms.state } else { - if (ini[1] != 1) stop ("Argument ini can only be 'model' or 1") - odeini <- c(1, rep(0, length(fit$mkinmod$spec) - 1)) + if (!is.numeric(ini[1])) stop ("Argument ini can only be 'model' or numeric") + if (length(ini) == 1) odeini <- c(ini[1], rep(0, length(fit$mkinmod$spec) - 1)) + else odeini = ini names(odeini) <- names(fit$mkinmod$spec) } diff --git a/docs/reference/one_box.html b/docs/reference/one_box.html index 853f892..4e60143 100644 --- a/docs/reference/one_box.html +++ b/docs/reference/one_box.html @@ -70,8 +70,7 @@ -

The time series starts with the amount specified for the first application. -This does not create objects of type ts.

+

Create a time series of decline data

one_box(x, ini, ..., t_end = 100, res = 0.01)
@@ -84,16 +83,22 @@ This does not create objects of type ts.

res = 0.01) # S3 method for mkinfit -one_box(x, ini = c("model", 1), ..., t_end = 100, - res = 0.01)
+one_box(x, ini = "model", ..., t_end = 100, res = 0.01)

Arguments

x
When numeric, this is the half-life to be used for an exponential -decline. If x is an mkinfit object, the decline is calculated from this object
+decline. When a character string specifying a parent decline model is given +e.g. FOMC, parms must contain the corresponding paramters. +If x is an mkinfit object, the decline is calculated from this +object.
ini
-
The initial amount for each compound
+
The initial amount for the parent compound. If x is an +mkinfit object, and ini is 'model', the fitted initial +concentrations are used. Otherwise, ini must be numeric. If it has +length one, it is used for the parent and initial values of metabolites +are zero, otherwise, it must give values for all observed variables.
...
Further arguments passed to methods
t_end
@@ -104,6 +109,10 @@ decline. If x is an mkinfit object, the decline is calculated from this objectA named numeric vector containing the model parameters
+

Value

+ +

An object of class one_box, inheriting from ts.

+

Examples

# Only use a half-life @@ -123,7 +132,9 @@ decline. If x is an mkinfit object, the decline is calculated from this objectContents diff --git a/man/one_box.Rd b/man/one_box.Rd index 1bdc791..134b206 100644 --- a/man/one_box.Rd +++ b/man/one_box.Rd @@ -14,14 +14,20 @@ one_box(x, ini, ..., t_end = 100, res = 0.01) \method{one_box}{character}(x, ini = 1, parms, ..., t_end = 100, res = 0.01) -\method{one_box}{mkinfit}(x, ini = c("model", 1), ..., t_end = 100, - res = 0.01) +\method{one_box}{mkinfit}(x, ini = "model", ..., t_end = 100, res = 0.01) } \arguments{ \item{x}{When numeric, this is the half-life to be used for an exponential -decline. If x is an mkinfit object, the decline is calculated from this object} +decline. When a character string specifying a parent decline model is given +e.g. \code{FOMC}, \code{parms} must contain the corresponding paramters. +If x is an \code{\link{mkinfit}} object, the decline is calculated from this +object.} -\item{ini}{The initial amount for each compound} +\item{ini}{The initial amount for the parent compound. If x is an +\code{\link{mkinfit}} object, and ini is 'model', the fitted initial +concentrations are used. Otherwise, ini must be numeric. If it has +length one, it is used for the parent and initial values of metabolites +are zero, otherwise, it must give values for all observed variables.} \item{...}{Further arguments passed to methods} @@ -31,9 +37,11 @@ decline. If x is an mkinfit object, the decline is calculated from this object} \item{parms}{A named numeric vector containing the model parameters} } +\value{ +An object of class \code{one_box}, inheriting from \code{\link{ts}}. +} \description{ -The time series starts with the amount specified for the first application. -This does not create objects of type \code{\link{ts}}. +Create a time series of decline data } \examples{ # Only use a half-life -- cgit v1.2.1