From 7875935fdfc3c55e0ef328b3c3a4512a30011df1 Mon Sep 17 00:00:00 2001 From: Johannes Ranke Date: Wed, 23 Mar 2016 17:03:09 +0100 Subject: Added 'from_max_mean' to 'mkinfit'. - Now it is easier to do decline kinetics from the maximum occurrence - Static documentation rebuilt by staticdocs::build_site() - Fixed an URL in the README, thanks to the win-builder check with R-devel --- R/mkinfit.R | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'R/mkinfit.R') diff --git a/R/mkinfit.R b/R/mkinfit.R index 4a5be20a..929c73f0 100644 --- a/R/mkinfit.R +++ b/R/mkinfit.R @@ -1,4 +1,4 @@ -# Copyright (C) 2010-2015 Johannes Ranke +# Copyright (C) 2010-2016 Johannes Ranke # Portions of this code are copyright (C) 2013 Eurofins Regulatory AG # Contact: jranke@uni-bremen.de # The summary function is an adapted and extended version of summary.modFit @@ -26,6 +26,7 @@ mkinfit <- function(mkinmod, observed, state.ini = "auto", fixed_parms = NULL, fixed_initials = names(mkinmod$diffs)[-1], + from_max_mean = FALSE, solution_type = c("auto", "analytical", "eigen", "deSolve"), method.ode = "lsoda", use_compiled = "auto", @@ -79,6 +80,18 @@ mkinfit <- function(mkinmod, observed, # Subset observed data with names of observed data in the model observed <- subset(observed, name %in% obs_vars) + # Obtain data for decline from maximum mean value if requested + if (from_max_mean) { + # This is only used for simple decline models + if (length(obs_vars) > 1) + stop("Decline from maximum is only implemented for models with a single observed variable") + + means <- aggregate(value ~ time, data = observed, mean, na.rm=TRUE) + t_of_max <- means[which.max(means$value), "time"] + observed <- subset(observed, time >= t_of_max) + observed$time <- observed$time - t_of_max + } + # Define starting values for parameters where not specified by the user if (parms.ini[[1]] == "auto") parms.ini = vector() -- cgit v1.2.1