diff options
Diffstat (limited to 'R')
-rw-r--r-- | R/nlme.mmkin.R | 37 | ||||
-rw-r--r-- | R/plot.nlme.mmkin.R | 5 |
2 files changed, 10 insertions, 32 deletions
diff --git a/R/nlme.mmkin.R b/R/nlme.mmkin.R index d4720e79..22a70f18 100644 --- a/R/nlme.mmkin.R +++ b/R/nlme.mmkin.R @@ -53,6 +53,7 @@ get_deg_func <- function() { #' f_nlme_dfop <- nlme(f["DFOP", ]) #' AIC(f_nlme_sfo, f_nlme_dfop) #' print(f_nlme_dfop) +#' plot(f_nlme_dfop) #' endpoints(f_nlme_dfop) #' \dontrun{ #' f_nlme_2 <- nlme(f["SFO", ], start = c(parent_0 = 100, log_k_parent = 0.1)) @@ -63,58 +64,36 @@ get_deg_func <- function() { #' A1 = mkinsub("SFO"), use_of_ff = "min", quiet = TRUE) #' m_sfo_sfo_ff <- mkinmod(parent = mkinsub("SFO", "A1"), #' A1 = mkinsub("SFO"), use_of_ff = "max", quiet = TRUE) -#' m_fomc_sfo <- mkinmod(parent = mkinsub("FOMC", "A1"), -#' A1 = mkinsub("SFO"), quiet = TRUE) #' m_dfop_sfo <- mkinmod(parent = mkinsub("DFOP", "A1"), #' A1 = mkinsub("SFO"), quiet = TRUE) #' #' f_2 <- mmkin(list("SFO-SFO" = m_sfo_sfo, #' "SFO-SFO-ff" = m_sfo_sfo_ff, -#' "FOMC-SFO" = m_fomc_sfo, #' "DFOP-SFO" = m_dfop_sfo), #' ds_2, quiet = TRUE) -#' plot(f_2["SFO-SFO", 3:4]) # Separate fits for datasets 3 and 4 #' #' f_nlme_sfo_sfo <- nlme(f_2["SFO-SFO", ]) -#' # plot(f_nlme_sfo_sfo) # not feasible with pkgdown figures -#' plot(f_nlme_sfo_sfo, 3:4) # Global mixed model: Fits for datasets 3 and 4 +#' plot(f_nlme_sfo_sfo) #' #' # With formation fractions #' f_nlme_sfo_sfo_ff <- nlme(f_2["SFO-SFO-ff", ]) -#' plot(f_nlme_sfo_sfo_ff, 3:4) # chi2 different due to different df attribution +#' plot(f_nlme_sfo_sfo_ff) #' -#' # For more parameters, we need to increase pnlsMaxIter and the tolerance +#' # For the following fit we need to increase pnlsMaxIter and the tolerance #' # to get convergence -#' f_nlme_fomc_sfo <- nlme(f_2["FOMC-SFO", ], -#' control = list(pnlsMaxIter = 100, tolerance = 1e-4), verbose = TRUE) #' f_nlme_dfop_sfo <- nlme(f_2["DFOP-SFO", ], #' control = list(pnlsMaxIter = 120, tolerance = 5e-4), verbose = TRUE) -#' plot(f_2["FOMC-SFO", 3:4]) -#' plot(f_nlme_fomc_sfo, 3:4) #' -#' plot(f_2["DFOP-SFO", 3:4]) -#' plot(f_nlme_dfop_sfo, 3:4) +#' plot(f_nlme_dfop_sfo) #' -#' anova(f_nlme_dfop_sfo, f_nlme_fomc_sfo, f_nlme_sfo_sfo) -#' anova(f_nlme_dfop_sfo, f_nlme_sfo_sfo) # if we ignore FOMC +#' anova(f_nlme_dfop_sfo, f_nlme_sfo_sfo) #' #' endpoints(f_nlme_sfo_sfo) #' endpoints(f_nlme_dfop_sfo) #' #' if (length(findFunction("varConstProp")) > 0) { # tc error model for nlme available -#' # Attempts to fit metabolite kinetics with the tc error model -#' #f_2_tc <- mmkin(list("SFO-SFO" = m_sfo_sfo, -#' # "SFO-SFO-ff" = m_sfo_sfo_ff, -#' # "FOMC-SFO" = m_fomc_sfo, -#' # "DFOP-SFO" = m_dfop_sfo), -#' # ds_2, quiet = TRUE, -#' # error_model = "tc") -#' #f_nlme_sfo_sfo_tc <- nlme(f_2_tc["SFO-SFO", ], control = list(maxIter = 100)) -#' #f_nlme_dfop_sfo_tc <- nlme(f_2_tc["DFOP-SFO", ]) -#' #f_nlme_dfop_sfo_tc <- update(f_nlme_dfop_sfo, weights = varConstProp(), -#' # control = list(sigma = 1, msMaxIter = 100, pnlsMaxIter = 15)) -#' # Fitting metabolite kinetics with nlme.mmkin and the two-component -#' # error model currently does not work, at least not with these data. +#' # Attempts to fit metabolite kinetics with the tc error model are possible, +#' # but need tweeking of control values and sometimes do not converge #' #' f_tc <- mmkin(c("SFO", "DFOP"), ds, quiet = TRUE, error_model = "tc") #' f_nlme_sfo_tc <- nlme(f_tc["SFO", ]) diff --git a/R/plot.nlme.mmkin.R b/R/plot.nlme.mmkin.R index 2356070e..223aba68 100644 --- a/R/plot.nlme.mmkin.R +++ b/R/plot.nlme.mmkin.R @@ -99,7 +99,7 @@ plot.nlme.mmkin <- function(x, i = 1:ncol(x$mmkin_orig), transform_fractions = fit_1$transform_fractions) odeini <- degparms_all[ds_i, odeini_names] - names(odeini) <- gsub("_0", "", names(odeini)) + names(odeini) <- gsub("_0", "", odeini_names) out <- mkinpredict(x$mkinmod, odeparms, odeini, outtimes, solution_type = solution_type, @@ -116,7 +116,7 @@ plot.nlme.mmkin <- function(x, i = 1:ncol(x$mmkin_orig), transform_fractions = fit_1$transform_fractions) odeini_pop <- degparms_all_pop[odeini_names] - names(odeini_pop) <- gsub("_0", "", names(odeini_pop)) + names(odeini_pop) <- gsub("_0", "", odeini_names) pred_pop <- as.data.frame( mkinpredict(x$mkinmod, odeparms_pop, odeini_pop, @@ -171,7 +171,6 @@ plot.nlme.mmkin <- function(x, i = 1:ncol(x$mmkin_orig), maxabs = max(abs(observed_row$residual), na.rm = TRUE) } - if (identical(resplot, "time")) { plot(0, type = "n", xlim = xlim, xlab = "Time", ylim = c(-1.2 * maxabs, 1.2 * maxabs), |