From 88cf130615a6cde0c4e65d14db32fed7f6e43085 Mon Sep 17 00:00:00 2001 From: Johannes Ranke Date: Sat, 12 Jun 2021 11:05:24 +0200 Subject: Small cosmetics --- DESCRIPTION | 2 +- R/dimethenamid_2018.R | 25 +++++++++++++++++++++++++ R/nlmixr.R | 20 +++++++++----------- tests/testthat/test_mixed.R | 2 +- 4 files changed, 36 insertions(+), 13 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index e81fcb32..c6151839 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -2,7 +2,7 @@ Package: mkin Type: Package Title: Kinetic Evaluation of Chemical Degradation Data Version: 1.0.5 -Date: 2021-06-03 +Date: 2021-06-11 Authors@R: c( person("Johannes", "Ranke", role = c("aut", "cre", "cph"), email = "jranke@uni-bremen.de", diff --git a/R/dimethenamid_2018.R b/R/dimethenamid_2018.R index 189da618..79018c11 100644 --- a/R/dimethenamid_2018.R +++ b/R/dimethenamid_2018.R @@ -18,4 +18,29 @@ #' \url{http://registerofquestions.efsa.europa.eu/roqFrontend/outputLoader?output=ON-5211} #' @examples #' print(dimethenamid_2018) +#' dmta_ds <- lapply(1:8, function(i) { +#' ds_i <- dimethenamid_2018$ds[[i]]$data +#' ds_i[ds_i$name == "DMTAP", "name"] <- "DMTA" +#' ds_i$time <- ds_i$time * dimethenamid_2018$f_time_norm[i] +#' ds_i +#' }) +#' names(dmta_ds) <- sapply(dimethenamid_2018$ds, function(ds) ds$title) +#' dmta_ds[["Borstel"]] <- rbind(dmta_ds[["Borstel 1"]], dmta_ds[["Borstel 2"]]) +#' dmta_ds[["Borstel 1"]] <- NULL +#' dmta_ds[["Borstel 2"]] <- NULL +#' dmta_ds[["Elliot"]] <- rbind(dmta_ds[["Elliot 1"]], dmta_ds[["Elliot 2"]]) +#' dmta_ds[["Elliot 1"]] <- NULL +#' dmta_ds[["Elliot 2"]] <- NULL +#' dfop_sfo3_plus <- mkinmod( +#' DMTA = mkinsub("DFOP", c("M23", "M27", "M31")), +#' M23 = mkinsub("SFO"), +#' M27 = mkinsub("SFO"), +#' M31 = mkinsub("SFO", "M27", sink = FALSE), +#' quiet = TRUE +#' ) +#' f_dmta_mkin_tc <- mmkin( +#' list("DFOP-SFO3+" = dfop_sfo3_plus), +#' dmta_ds, quiet = TRUE, error_model = "tc") +#' nlmixr_model(f_dmta_mkin_tc) # incomplete +#' # nlmixr(f_dmta_mkin_tc, est = "saem") # not supported (yet) "dimethenamid_2018" diff --git a/R/nlmixr.R b/R/nlmixr.R index 98783ca7..6e0b5128 100644 --- a/R/nlmixr.R +++ b/R/nlmixr.R @@ -43,11 +43,11 @@ nlmixr::nlmixr #' ds <- lapply(experimental_data_for_UBA_2019[6:10], #' function(x) subset(x$data[c("name", "time", "value")])) #' names(ds) <- paste("Dataset", 6:10) -#' +#' #' f_mmkin_parent <- mmkin(c("SFO", "FOMC", "DFOP", "HS"), ds, quiet = TRUE, cores = 1) #' f_mmkin_parent_tc <- mmkin(c("SFO", "FOMC", "DFOP"), ds, error_model = "tc", #' cores = 1, quiet = TRUE) -#' +#' #' f_nlmixr_sfo_saem <- nlmixr(f_mmkin_parent["SFO", ], est = "saem") #' f_nlmixr_sfo_focei <- nlmixr(f_mmkin_parent["SFO", ], est = "focei") #' @@ -278,20 +278,18 @@ nlmixr_model <- function(object, conf.level = conf.level, random = TRUE) degparms_optim <- degparms_mmkin$fixed - - degparms_optim <- degparms_mmkin$fixed + degparms_optim_back <- backtransform_odeparms(degparms_optim, + object[[1]]$mkinmod, + object[[1]]$transform_rates, + object[[1]]$transform_fractions) + degparms_optim_back_names <- names(degparms_optim_back) + names(degparms_optim_back_names) <- names(degparms_optim) if (degparms_start[1] == "auto") { degparms_start <- degparms_optim } degparms_fixed <- object[[1]]$bparms.fixed - degparms_optim_back_names <- names(backtransform_odeparms(degparms_optim, - object[[1]]$mkinmod, - object[[1]]$transform_rates, - object[[1]]$transform_fractions)) - names(degparms_optim_back_names) <- names(degparms_optim) - odeini_optim_parm_names <- grep('_0$', names(degparms_optim), value = TRUE) odeini_fixed_parm_names <- grep('_0$', names(degparms_fixed), value = TRUE) @@ -307,7 +305,7 @@ nlmixr_model <- function(object, ini_block <- "ini({" # Initial values for all degradation parameters - for (parm_name in names(degparms_optim)) { + for (parm_name in names(degparms_start)) { # As initials for state variables are not transformed, # we need to modify the name here as we want to # use the original name in the model block diff --git a/tests/testthat/test_mixed.R b/tests/testthat/test_mixed.R index 5d15530b..9c8a84d7 100644 --- a/tests/testthat/test_mixed.R +++ b/tests/testthat/test_mixed.R @@ -113,7 +113,7 @@ test_that("nlme results are reproducible to some degree", { expect_known_output(print(test_summary, digits = 1), "summary_nlme_biphasic_s.txt") - # k1 just fails the first test (lower bound of the ci), so we need to excluded it + # k1 just fails the first test (lower bound of the ci), so we need to exclude it dfop_no_k1 <- c("parent_0", "k_m1", "f_parent_to_m1", "k2", "g") dfop_sfo_pop_no_k1 <- as.numeric(dfop_sfo_pop[dfop_no_k1]) dfop_sfo_pop <- as.numeric(dfop_sfo_pop) -- cgit v1.2.1