From 9b947f0358d3a1b1fc922bfd0187ca444ce5811d Mon Sep 17 00:00:00 2001 From: Johannes Ranke Date: Thu, 24 Jul 2014 14:42:59 +0200 Subject: Bump version, better default for state.ini --- DESCRIPTION | 2 +- NEWS.md | 6 ++++++ R/mkinfit.R | 10 ++++++++-- man/mkinfit.Rd | 1 + 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 2da7f1c1..bf0fa09a 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -2,7 +2,7 @@ Package: mkin Type: Package Title: Routines for fitting kinetic models with one or more state variables to chemical degradation data -Version: 0.9-32 +Version: 0.9-33 Date: 2014-07-24 Authors@R: c(person("Johannes", "Ranke", role = c("aut", "cre", "cph"), email = "jranke@uni-bremen.de"), diff --git a/NEWS.md b/NEWS.md index 02c7c661..4c45a0d1 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,9 @@ +# CHANGES in mkin VERSION 0.9-33 + +## NEW FEATURES + +- The initial value (state.ini) for the observed variable with the highest observed residue is set to 100 in case it has no time zero observation and `state.ini = "auto"` + # CHANGES in mkin VERSION 0.9-32 ## NEW FEATURES diff --git a/R/mkinfit.R b/R/mkinfit.R index 39d084cb..c98c7586 100644 --- a/R/mkinfit.R +++ b/R/mkinfit.R @@ -154,8 +154,14 @@ mkinfit <- function(mkinmod, observed, # Set default for state.ini if appropriate if (state.ini[1] == "auto") { - state.ini = c(mean(subset(observed, time == 0 & name == presumed_parent_name)$value), - rep(0, length(mkinmod$diffs) - 1)) + 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)) { + 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)) + } } # Name the inital state variable values if they are not named yet diff --git a/man/mkinfit.Rd b/man/mkinfit.Rd index 581d63f4..4e331e2a 100644 --- a/man/mkinfit.Rd +++ b/man/mkinfit.Rd @@ -71,6 +71,7 @@ mkinfit(mkinmod, observed, (see \code{map} component of \code{\link{mkinmod}}). The default is to set the initial value of the first model variable to the mean of the time zero values for the variable with the maximum observed value, and all others to 0. + If this variable has no time zero observations, its initial value is set to 100. } \item{fixed_parms}{ The names of parameters that should not be optimised but rather kept at the -- cgit v1.2.1