From fb014522ddc1057e85d3c08ab2cd753bd79bd857 Mon Sep 17 00:00:00 2001 From: jranke Date: Mon, 31 May 2010 21:17:58 +0000 Subject: - Added a test based on the KinGUI paper "complex case" - Fix the DT50 calculation for the SFORB model - Added a bit more of a description git-svn-id: svn+ssh://svn.r-forge.r-project.org/svnroot/kinfit/pkg/mkin@11 edb9625f-4e0d-4859-8d74-9fd3b1da38cb --- DESCRIPTION | 18 ++++++++++++------ R/mkinfit.R | 6 +++--- data/schaefer07_complex_case.RData | Bin 371 -> 828 bytes inst/unitTests/runit.mkinfit.R | 35 +++++++++++++++++++++++++++++++++++ man/mkinfit.Rd | 7 ++++++- 5 files changed, 56 insertions(+), 10 deletions(-) create mode 100644 inst/unitTests/runit.mkinfit.R diff --git a/DESCRIPTION b/DESCRIPTION index e518d6d..24fbc57 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,14 +1,20 @@ Package: mkin Type: Package Title: Routines for fitting kinetic models with one or more state - variables to chemical degradation data -Version: 0.7-3 -Date: 2010-05-20 + variables to chemical degradation data +Version: 0.7-4 +Date: 2010-05-22 Author: Johannes Ranke Maintainer: Johannes Ranke -Description: Calculation routines based on the FOCUS Kinetics Report - (2006) -Depends: FME +Description: Calculation routines based on the FOCUS Kinetics Report (2006). Includes + a function for conveniently defining differential equation models, choice of + the optimisation methods made available by the FME package (default is a + Levenberg-Marquardt variant). Initial values for parameters of the differential + equations and time zero values of the state values can be defaults, user defined + or a combination of a fit for the parent compound carried out by the kinfit + package and defaults. DT50 and DT90 values are calculated as well as the + chi2 error level as defined by the FOCUS Kinetics Group. +Depends: FME, kinfit License: GPL LazyLoad: yes LazyData: yes diff --git a/R/mkinfit.R b/R/mkinfit.R index 9e872fc..f8285fc 100644 --- a/R/mkinfit.R +++ b/R/mkinfit.R @@ -188,9 +188,9 @@ mkinfit <- function(mkinmod, observed, # FOCUS kinetics (2006), p. 60 f k_out_names = grep(paste("k", obs_var, "free", sep="_"), names(parms.all), value=TRUE) k_out_names = setdiff(k_out_names, paste("k", obs_var, "free", "bound", sep="_")) - k_1output = sum(parms.all[[k_out_names]]) - k_12 = parms.all[[paste("k", obs_var, "free", "bound", sep="_")]] - k_21 = parms.all[[paste("k", obs_var, "bound", "free", sep="_")]] + k_1output = sum(parms.all[k_out_names]) + k_12 = parms.all[paste("k", obs_var, "free", "bound", sep="_")] + k_21 = parms.all[paste("k", obs_var, "bound", "free", sep="_")] sqrt_exp = sqrt(1/4 * (k_12 + k_21 + k_1output)^2 + k_12 * k_21 - (k_12 + k_1output) * k_21) b1 = 0.5 * (k_12 + k_21 + k_1output) + sqrt_exp diff --git a/data/schaefer07_complex_case.RData b/data/schaefer07_complex_case.RData index 0e3b3af..d58aedd 100644 Binary files a/data/schaefer07_complex_case.RData and b/data/schaefer07_complex_case.RData differ diff --git a/inst/unitTests/runit.mkinfit.R b/inst/unitTests/runit.mkinfit.R new file mode 100644 index 0000000..6dbd11f --- /dev/null +++ b/inst/unitTests/runit.mkinfit.R @@ -0,0 +1,35 @@ +test.mkinmod.schaefer07_complex_example <- function() +{ + schaefer07_complex_model <- mkinmod( + parent = list(type = "SFO", to = c("A1", "B1", "C1"), sink = FALSE), + A1 = list(type = "SFO", to = "A2"), + B1 = list(type = "SFO"), + C1 = list(type = "SFO"), + A2 = list(type = "SFO")) + + fit <- mkinfit(schaefer07_complex_model, + mkin_wide_to_long(schaefer07_complex_case, time = "time"), + parms.ini = c(0.1, 0.1, 0.1, 0.01, 0.1, 0.1, 0.1, 0.1)) + s <- summary(fit) + attach(as.list(fit$par)) + k_parent <- sum(k_parent_A1, k_parent_B1, k_parent_C1) + r <- schaefer07_complex_results + r$mkin <- c( + k_parent, + s$distimes["parent", "DT50"], + k_parent_A1/k_parent, + sum(k_A1_sink, k_A1_A2), + s$distimes["A1", "DT50"], + k_parent_B1/k_parent, + k_B1_sink, + s$distimes["B1", "DT50"], + k_parent_C1/k_parent, + k_C1_sink, + s$distimes["C1", "DT50"], + k_A1_A2/(k_A1_A2 + k_A1_sink), + k_A2_sink, + s$distimes["A2", "DT50"]) + r$means <- (r$KinGUI + r$ModelMaker)/2 + r$mkin.deviation <- abs(round(100 * ((r$mkin - r$means)/r$means), digits=1)) + checkTrue(r$mkin.deviation < 10) +} diff --git a/man/mkinfit.Rd b/man/mkinfit.Rd index 0e381af..0ec2d21 100644 --- a/man/mkinfit.Rd +++ b/man/mkinfit.Rd @@ -10,7 +10,12 @@ values. } \usage{ -mkinfit(mkinmod, observed, parms.ini = rep(0.1, length(mkinmod$parms)), state.ini = c(100, rep(0, length(mkinmod$diffs) - 1)), lower = 0, upper = Inf, fixed_parms = NULL, fixed_initials = names(mkinmod$diffs)[-1], plot = FALSE, quiet = FALSE, err = NULL, weight = "none", scaleVar = FALSE, ...) +mkinfit(mkinmod, observed, + parms.ini = rep(0.1, length(mkinmod$parms)), + state.ini = c(100, rep(0, length(mkinmod$diffs) - 1)), + lower = 0, upper = Inf, + fixed_parms = NULL, fixed_initials = names(mkinmod$diffs)[-1], + plot = FALSE, quiet = FALSE, err = NULL, weight = "none", scaleVar = FALSE, ...) } \arguments{ \item{mkinmod}{ -- cgit v1.2.1