From 81dc12a8c149e11d57190ebf59f3f7e9c7b99af7 Mon Sep 17 00:00:00 2001 From: Johannes Ranke Date: Wed, 20 Aug 2014 14:42:20 +0200 Subject: Fix mkinfit for a special situation See NEWS.md: When the parent was not the (only) variable with the highest value out of all variables in the observed data, it could happen that the initial value (state.ini) was not initialised. --- DESCRIPTION | 2 +- NEWS.md | 2 ++ R/mkinfit.R | 14 +++++++------- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 3898f69a..e8b7195d 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -3,7 +3,7 @@ Type: Package Title: Routines for fitting kinetic models with one or more state variables to chemical degradation data Version: 0.9-33 -Date: 2014-08-19 +Date: 2014-08-20 Authors@R: c(person("Johannes", "Ranke", role = c("aut", "cre", "cph"), email = "jranke@uni-bremen.de"), person("Katrin", "Lindenberger", role = "ctb"), diff --git a/NEWS.md b/NEWS.md index a24c31bc..d05c2095 100644 --- a/NEWS.md +++ b/NEWS.md @@ -8,6 +8,8 @@ - `mkinfit()`: The internally fitted parameter for `g` was named `g_ilr` even when `transform_fractions=FALSE` +- `mkinfit()`: The initial value (state.ini) for the parent compound was not set when the parent was not the (only) variable with the highest value in the observed data. + ## MINOR CHANGES - The formatting of differential equations in the summary was improved by wrapping overly long lines diff --git a/R/mkinfit.R b/R/mkinfit.R index 92c8f8bf..0f488ec8 100644 --- a/R/mkinfit.R +++ b/R/mkinfit.R @@ -41,11 +41,11 @@ mkinfit <- function(mkinmod, observed, trace_parms = FALSE, ...) { - # Check mkinmod and generate a model for the variable whithe the highest value + # Check mkinmod and generate a model for the variable whith the highest value # if a suitable string is given parent_models_available = c("SFO", "FOMC", "DFOP", "HS", "SFORB") - presumed_parent_name = observed[which.max(observed$value), "name"] if (class(mkinmod) != "mkinmod") { + presumed_parent_name = observed[which.max(observed$value), "name"] if (mkinmod[[1]] %in% parent_models_available) { speclist <- list(list(type = mkinmod, sink = TRUE)) names(speclist) <- presumed_parent_name @@ -153,14 +153,14 @@ mkinfit <- function(mkinmod, observed, } # Set default for state.ini if appropriate + parent_name = names(mkinmod$spec)[[1]] if (state.ini[1] == "auto") { - presumed_parent_time_0 = subset(observed, - time == 0 & name == presumed_parent_name)$value - presumed_parent_time_0_mean = mean(presumed_parent_time_0, na.rm = TRUE) - if (is.na(presumed_parent_time_0_mean)) { + parent_time_0 = subset(observed, time == 0 & name == parent_name)$value + parent_time_0_mean = mean(parent_time_0, na.rm = TRUE) + if (is.na(parent_time_0_mean)) { state.ini = c(100, rep(0, length(mkinmod$diffs) - 1)) } else { - state.ini = c(presumed_parent_time_0_mean, rep(0, length(mkinmod$diffs) - 1)) + state.ini = c(parent_time_0_mean, rep(0, length(mkinmod$diffs) - 1)) } } -- cgit v1.2.1