diff options
author | Johannes Ranke <jranke@uni-bremen.de> | 2020-10-24 02:18:59 +0200 |
---|---|---|
committer | Johannes Ranke <jranke@uni-bremen.de> | 2020-10-24 02:18:59 +0200 |
commit | 60270e2849ebd48eaf57b83eb1aa9fbe53281f8b (patch) | |
tree | 644904ea42e6d35d6e43bb88733619b25347fcbb | |
parent | 6ad4e443b662e8c61b1b350d3e639e821a8ff764 (diff) |
Fix a bug for nlme with parent only, improve examples
-rw-r--r-- | R/nlme.mmkin.R | 37 | ||||
-rw-r--r-- | R/plot.nlme.mmkin.R | 5 | ||||
-rw-r--r-- | docs/dev/pkgdown.yml | 2 | ||||
-rw-r--r-- | docs/dev/reference/Rplot001.png | bin | 27839 -> 48355 bytes | |||
-rw-r--r-- | docs/dev/reference/Rplot002.png | bin | 64132 -> 62018 bytes | |||
-rw-r--r-- | docs/dev/reference/Rplot003.png | bin | 26194 -> 62243 bytes | |||
-rw-r--r-- | docs/dev/reference/Rplot004.png | bin | 26783 -> 63952 bytes | |||
-rw-r--r-- | docs/dev/reference/nlme.mmkin-1.png | bin | 79142 -> 135400 bytes | |||
-rw-r--r-- | docs/dev/reference/nlme.mmkin-2.png | bin | 79539 -> 171122 bytes | |||
-rw-r--r-- | docs/dev/reference/nlme.mmkin-3.png | bin | 79703 -> 171684 bytes | |||
-rw-r--r-- | docs/dev/reference/nlme.mmkin-4.png | bin | 82209 -> 175495 bytes | |||
-rw-r--r-- | docs/dev/reference/nlme.mmkin.html | 101 | ||||
-rw-r--r-- | man/nlme.mmkin.Rd | 37 |
13 files changed, 32 insertions, 150 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), diff --git a/docs/dev/pkgdown.yml b/docs/dev/pkgdown.yml index 61fa6e5d..d6c3d6c9 100644 --- a/docs/dev/pkgdown.yml +++ b/docs/dev/pkgdown.yml @@ -10,7 +10,7 @@ articles: web_only/NAFTA_examples: NAFTA_examples.html web_only/benchmarks: benchmarks.html web_only/compiled_models: compiled_models.html -last_built: 2020-10-23T23:38Z +last_built: 2020-10-24T00:14Z urls: reference: https://pkgdown.jrwb.de/mkin/reference article: https://pkgdown.jrwb.de/mkin/articles diff --git a/docs/dev/reference/Rplot001.png b/docs/dev/reference/Rplot001.png Binary files differindex cfc5bc2b..bf7c274a 100644 --- a/docs/dev/reference/Rplot001.png +++ b/docs/dev/reference/Rplot001.png diff --git a/docs/dev/reference/Rplot002.png b/docs/dev/reference/Rplot002.png Binary files differindex cffa10c1..965d4620 100644 --- a/docs/dev/reference/Rplot002.png +++ b/docs/dev/reference/Rplot002.png diff --git a/docs/dev/reference/Rplot003.png b/docs/dev/reference/Rplot003.png Binary files differindex 89ba6c49..057b525f 100644 --- a/docs/dev/reference/Rplot003.png +++ b/docs/dev/reference/Rplot003.png diff --git a/docs/dev/reference/Rplot004.png b/docs/dev/reference/Rplot004.png Binary files differindex 7d30a181..2b5ba960 100644 --- a/docs/dev/reference/Rplot004.png +++ b/docs/dev/reference/Rplot004.png diff --git a/docs/dev/reference/nlme.mmkin-1.png b/docs/dev/reference/nlme.mmkin-1.png Binary files differindex 564f7e2b..d0a1d7d4 100644 --- a/docs/dev/reference/nlme.mmkin-1.png +++ b/docs/dev/reference/nlme.mmkin-1.png diff --git a/docs/dev/reference/nlme.mmkin-2.png b/docs/dev/reference/nlme.mmkin-2.png Binary files differindex a9ce4636..b68dc3e0 100644 --- a/docs/dev/reference/nlme.mmkin-2.png +++ b/docs/dev/reference/nlme.mmkin-2.png diff --git a/docs/dev/reference/nlme.mmkin-3.png b/docs/dev/reference/nlme.mmkin-3.png Binary files differindex 0b7ce0f6..77804b2c 100644 --- a/docs/dev/reference/nlme.mmkin-3.png +++ b/docs/dev/reference/nlme.mmkin-3.png diff --git a/docs/dev/reference/nlme.mmkin-4.png b/docs/dev/reference/nlme.mmkin-4.png Binary files differindex d7c68dd5..96717087 100644 --- a/docs/dev/reference/nlme.mmkin-4.png +++ b/docs/dev/reference/nlme.mmkin-4.png diff --git a/docs/dev/reference/nlme.mmkin.html b/docs/dev/reference/nlme.mmkin.html index 6e83b700..3c84abe2 100644 --- a/docs/dev/reference/nlme.mmkin.html +++ b/docs/dev/reference/nlme.mmkin.html @@ -286,7 +286,8 @@ with additional elements</p> #> StdDev: 2.488249 0.8447273 1.32965 0.3289311 2.321364 #> #> Number of Observations: 90 -#> Number of Groups: 5 </div><div class='input'><span class='fu'><a href='endpoints.html'>endpoints</a></span><span class='op'>(</span><span class='va'>f_nlme_dfop</span><span class='op'>)</span> +#> Number of Groups: 5 </div><div class='input'><span class='fu'><a href='https://rdrr.io/r/graphics/plot.default.html'>plot</a></span><span class='op'>(</span><span class='va'>f_nlme_dfop</span><span class='op'>)</span> +</div><div class='img'><img src='nlme.mmkin-1.png' alt='' width='700' height='433' /></div><div class='input'><span class='fu'><a href='endpoints.html'>endpoints</a></span><span class='op'>(</span><span class='va'>f_nlme_dfop</span><span class='op'>)</span> </div><div class='output co'>#> $distimes #> DT50 DT90 DT50back DT50_k1 DT50_k2 #> parent 10.79857 100.7937 30.34193 4.193938 43.85443 @@ -313,82 +314,24 @@ with additional elements</p> A1 <span class='op'>=</span> <span class='fu'><a href='mkinsub.html'>mkinsub</a></span><span class='op'>(</span><span class='st'>"SFO"</span><span class='op'>)</span>, use_of_ff <span class='op'>=</span> <span class='st'>"min"</span>, quiet <span class='op'>=</span> <span class='cn'>TRUE</span><span class='op'>)</span> <span class='va'>m_sfo_sfo_ff</span> <span class='op'><-</span> <span class='fu'><a href='mkinmod.html'>mkinmod</a></span><span class='op'>(</span>parent <span class='op'>=</span> <span class='fu'><a href='mkinsub.html'>mkinsub</a></span><span class='op'>(</span><span class='st'>"SFO"</span>, <span class='st'>"A1"</span><span class='op'>)</span>, A1 <span class='op'>=</span> <span class='fu'><a href='mkinsub.html'>mkinsub</a></span><span class='op'>(</span><span class='st'>"SFO"</span><span class='op'>)</span>, use_of_ff <span class='op'>=</span> <span class='st'>"max"</span>, quiet <span class='op'>=</span> <span class='cn'>TRUE</span><span class='op'>)</span> - <span class='va'>m_fomc_sfo</span> <span class='op'><-</span> <span class='fu'><a href='mkinmod.html'>mkinmod</a></span><span class='op'>(</span>parent <span class='op'>=</span> <span class='fu'><a href='mkinsub.html'>mkinsub</a></span><span class='op'>(</span><span class='st'>"FOMC"</span>, <span class='st'>"A1"</span><span class='op'>)</span>, - A1 <span class='op'>=</span> <span class='fu'><a href='mkinsub.html'>mkinsub</a></span><span class='op'>(</span><span class='st'>"SFO"</span><span class='op'>)</span>, quiet <span class='op'>=</span> <span class='cn'>TRUE</span><span class='op'>)</span> <span class='va'>m_dfop_sfo</span> <span class='op'><-</span> <span class='fu'><a href='mkinmod.html'>mkinmod</a></span><span class='op'>(</span>parent <span class='op'>=</span> <span class='fu'><a href='mkinsub.html'>mkinsub</a></span><span class='op'>(</span><span class='st'>"DFOP"</span>, <span class='st'>"A1"</span><span class='op'>)</span>, A1 <span class='op'>=</span> <span class='fu'><a href='mkinsub.html'>mkinsub</a></span><span class='op'>(</span><span class='st'>"SFO"</span><span class='op'>)</span>, quiet <span class='op'>=</span> <span class='cn'>TRUE</span><span class='op'>)</span> <span class='va'>f_2</span> <span class='op'><-</span> <span class='fu'><a href='mmkin.html'>mmkin</a></span><span class='op'>(</span><span class='fu'><a href='https://rdrr.io/r/base/list.html'>list</a></span><span class='op'>(</span><span class='st'>"SFO-SFO"</span> <span class='op'>=</span> <span class='va'>m_sfo_sfo</span>, <span class='st'>"SFO-SFO-ff"</span> <span class='op'>=</span> <span class='va'>m_sfo_sfo_ff</span>, - <span class='st'>"FOMC-SFO"</span> <span class='op'>=</span> <span class='va'>m_fomc_sfo</span>, <span class='st'>"DFOP-SFO"</span> <span class='op'>=</span> <span class='va'>m_dfop_sfo</span><span class='op'>)</span>, <span class='va'>ds_2</span>, quiet <span class='op'>=</span> <span class='cn'>TRUE</span><span class='op'>)</span> - <span class='fu'><a href='https://rdrr.io/r/graphics/plot.default.html'>plot</a></span><span class='op'>(</span><span class='va'>f_2</span><span class='op'>[</span><span class='st'>"SFO-SFO"</span>, <span class='fl'>3</span><span class='op'>:</span><span class='fl'>4</span><span class='op'>]</span><span class='op'>)</span> <span class='co'># Separate fits for datasets 3 and 4</span> -</div><div class='img'><img src='nlme.mmkin-1.png' alt='' width='700' height='433' /></div><div class='input'> + <span class='va'>f_nlme_sfo_sfo</span> <span class='op'><-</span> <span class='fu'><a href='https://rdrr.io/pkg/nlme/man/nlme.html'>nlme</a></span><span class='op'>(</span><span class='va'>f_2</span><span class='op'>[</span><span class='st'>"SFO-SFO"</span>, <span class='op'>]</span><span class='op'>)</span> - <span class='co'># plot(f_nlme_sfo_sfo) # not feasible with pkgdown figures</span> - <span class='fu'><a href='https://rdrr.io/r/graphics/plot.default.html'>plot</a></span><span class='op'>(</span><span class='va'>f_nlme_sfo_sfo</span>, <span class='fl'>3</span><span class='op'>:</span><span class='fl'>4</span><span class='op'>)</span> <span class='co'># Global mixed model: Fits for datasets 3 and 4</span> + <span class='fu'><a href='https://rdrr.io/r/graphics/plot.default.html'>plot</a></span><span class='op'>(</span><span class='va'>f_nlme_sfo_sfo</span><span class='op'>)</span> </div><div class='img'><img src='nlme.mmkin-2.png' alt='' width='700' height='433' /></div><div class='input'> <span class='co'># With formation fractions</span> <span class='va'>f_nlme_sfo_sfo_ff</span> <span class='op'><-</span> <span class='fu'><a href='https://rdrr.io/pkg/nlme/man/nlme.html'>nlme</a></span><span class='op'>(</span><span class='va'>f_2</span><span class='op'>[</span><span class='st'>"SFO-SFO-ff"</span>, <span class='op'>]</span><span class='op'>)</span> - <span class='fu'><a href='https://rdrr.io/r/graphics/plot.default.html'>plot</a></span><span class='op'>(</span><span class='va'>f_nlme_sfo_sfo_ff</span>, <span class='fl'>3</span><span class='op'>:</span><span class='fl'>4</span><span class='op'>)</span> <span class='co'># chi2 different due to different df attribution</span> + <span class='fu'><a href='https://rdrr.io/r/graphics/plot.default.html'>plot</a></span><span class='op'>(</span><span class='va'>f_nlme_sfo_sfo_ff</span><span class='op'>)</span> </div><div class='img'><img src='nlme.mmkin-3.png' alt='' width='700' height='433' /></div><div class='input'> - <span class='co'># For more parameters, we need to increase pnlsMaxIter and the tolerance</span> + <span class='co'># For the following fit we need to increase pnlsMaxIter and the tolerance</span> <span class='co'># to get convergence</span> - <span class='va'>f_nlme_fomc_sfo</span> <span class='op'><-</span> <span class='fu'><a href='https://rdrr.io/pkg/nlme/man/nlme.html'>nlme</a></span><span class='op'>(</span><span class='va'>f_2</span><span class='op'>[</span><span class='st'>"FOMC-SFO"</span>, <span class='op'>]</span>, - control <span class='op'>=</span> <span class='fu'><a href='https://rdrr.io/r/base/list.html'>list</a></span><span class='op'>(</span>pnlsMaxIter <span class='op'>=</span> <span class='fl'>100</span>, tolerance <span class='op'>=</span> <span class='fl'>1e-4</span><span class='op'>)</span>, verbose <span class='op'>=</span> <span class='cn'>TRUE</span><span class='op'>)</span> -</div><div class='output co'>#> -#> **Iteration 1 -#> LME step: Loglik: -394.1603, nlminb iterations: 3 -#> reStruct parameters: -#> ds1 ds2 ds3 ds4 ds5 -#> -0.2079793 0.8563830 1.7454105 1.0917354 1.2756825 -#> Beginning PNLS step: .. completed fit_nlme() step. -#> PNLS step: RSS = 643.8803 -#> fixed effects: 94.17379 -5.473193 -0.6970236 -0.2025091 2.103883 -#> iterations: 100 -#> Convergence crit. (must all become <= tolerance = 0.0001): -#> fixed reStruct -#> 0.7960134 0.1447728 -#> -#> **Iteration 2 -#> LME step: Loglik: -396.3824, nlminb iterations: 7 -#> reStruct parameters: -#> ds1 ds2 ds3 ds4 ds5 -#> -1.712404e-01 -2.432655e-05 1.842120e+00 1.073975e+00 1.322925e+00 -#> Beginning PNLS step: .. completed fit_nlme() step. -#> PNLS step: RSS = 643.8035 -#> fixed effects: 94.17385 -5.473487 -0.6970404 -0.2025137 2.103871 -#> iterations: 100 -#> Convergence crit. (must all become <= tolerance = 0.0001): -#> fixed reStruct -#> 5.382757e-05 1.236667e-03 -#> -#> **Iteration 3 -#> LME step: Loglik: -396.3825, nlminb iterations: 7 -#> reStruct parameters: -#> ds1 ds2 ds3 ds4 ds5 -#> -0.1712499044 -0.0001499831 1.8420971364 1.0739799123 1.3229167796 -#> Beginning PNLS step: .. completed fit_nlme() step. -#> PNLS step: RSS = 643.7948 -#> fixed effects: 94.17386 -5.473521 -0.6970422 -0.2025144 2.10387 -#> iterations: 100 -#> Convergence crit. (must all become <= tolerance = 0.0001): -#> fixed reStruct -#> 6.072817e-06 1.400857e-04 -#> -#> **Iteration 4 -#> LME step: Loglik: -396.3825, nlminb iterations: 7 -#> reStruct parameters: -#> ds1 ds2 ds3 ds4 ds5 -#> -0.1712529502 -0.0001641277 1.8420957542 1.0739797181 1.3229173076 -#> Beginning PNLS step: .. completed fit_nlme() step. -#> PNLS step: RSS = 643.7936 -#> fixed effects: 94.17386 -5.473526 -0.6970426 -0.2025146 2.103869 -#> iterations: 100 -#> Convergence crit. (must all become <= tolerance = 0.0001): -#> fixed reStruct -#> 1.027451e-06 2.275704e-05 </div><div class='input'> <span class='va'>f_nlme_dfop_sfo</span> <span class='op'><-</span> <span class='fu'><a href='https://rdrr.io/pkg/nlme/man/nlme.html'>nlme</a></span><span class='op'>(</span><span class='va'>f_2</span><span class='op'>[</span><span class='st'>"DFOP-SFO"</span>, <span class='op'>]</span>, + <span class='va'>f_nlme_dfop_sfo</span> <span class='op'><-</span> <span class='fu'><a href='https://rdrr.io/pkg/nlme/man/nlme.html'>nlme</a></span><span class='op'>(</span><span class='va'>f_2</span><span class='op'>[</span><span class='st'>"DFOP-SFO"</span>, <span class='op'>]</span>, control <span class='op'>=</span> <span class='fu'><a href='https://rdrr.io/r/base/list.html'>list</a></span><span class='op'>(</span>pnlsMaxIter <span class='op'>=</span> <span class='fl'>120</span>, tolerance <span class='op'>=</span> <span class='fl'>5e-4</span><span class='op'>)</span>, verbose <span class='op'>=</span> <span class='cn'>TRUE</span><span class='op'>)</span> </div><div class='output co'>#> #> **Iteration 1 @@ -415,17 +358,10 @@ with additional elements</p> #> iterations: 120 #> Convergence crit. (must all become <= tolerance = 0.0005): #> fixed reStruct -#> 4.789774e-07 2.200661e-05 </div><div class='input'> <span class='fu'><a href='https://rdrr.io/r/graphics/plot.default.html'>plot</a></span><span class='op'>(</span><span class='va'>f_2</span><span class='op'>[</span><span class='st'>"FOMC-SFO"</span>, <span class='fl'>3</span><span class='op'>:</span><span class='fl'>4</span><span class='op'>]</span><span class='op'>)</span> -</div><div class='img'><img src='nlme.mmkin-4.png' alt='' width='700' height='433' /></div><div class='input'> <span class='fu'><a href='https://rdrr.io/r/graphics/plot.default.html'>plot</a></span><span class='op'>(</span><span class='va'>f_nlme_fomc_sfo</span>, <span class='fl'>3</span><span class='op'>:</span><span class='fl'>4</span><span class='op'>)</span> -</div><div class='img'><img src='nlme.mmkin-5.png' alt='' width='700' height='433' /></div><div class='input'> - <span class='fu'><a href='https://rdrr.io/r/graphics/plot.default.html'>plot</a></span><span class='op'>(</span><span class='va'>f_2</span><span class='op'>[</span><span class='st'>"DFOP-SFO"</span>, <span class='fl'>3</span><span class='op'>:</span><span class='fl'>4</span><span class='op'>]</span><span class='op'>)</span> -</div><div class='img'><img src='nlme.mmkin-6.png' alt='' width='700' height='433' /></div><div class='input'> <span class='fu'><a href='https://rdrr.io/r/graphics/plot.default.html'>plot</a></span><span class='op'>(</span><span class='va'>f_nlme_dfop_sfo</span>, <span class='fl'>3</span><span class='op'>:</span><span class='fl'>4</span><span class='op'>)</span> -</div><div class='img'><img src='nlme.mmkin-7.png' alt='' width='700' height='433' /></div><div class='input'> - <span class='fu'><a href='https://rdrr.io/r/stats/anova.html'>anova</a></span><span class='op'>(</span><span class='va'>f_nlme_dfop_sfo</span>, <span class='va'>f_nlme_fomc_sfo</span>, <span class='va'>f_nlme_sfo_sfo</span><span class='op'>)</span> -</div><div class='output co'>#> Model df AIC BIC logLik Test L.Ratio p-value -#> f_nlme_dfop_sfo 1 13 843.8547 884.6201 -408.9273 -#> f_nlme_fomc_sfo 2 11 818.5149 853.0087 -398.2575 1 vs 2 21.33975 <.0001 -#> f_nlme_sfo_sfo 3 9 1085.1821 1113.4043 -533.5910 2 vs 3 270.66716 <.0001</div><div class='input'> <span class='fu'><a href='https://rdrr.io/r/stats/anova.html'>anova</a></span><span class='op'>(</span><span class='va'>f_nlme_dfop_sfo</span>, <span class='va'>f_nlme_sfo_sfo</span><span class='op'>)</span> <span class='co'># if we ignore FOMC</span> +#> 4.789774e-07 2.200661e-05 </div><div class='input'> + <span class='fu'><a href='https://rdrr.io/r/graphics/plot.default.html'>plot</a></span><span class='op'>(</span><span class='va'>f_nlme_dfop_sfo</span><span class='op'>)</span> +</div><div class='img'><img src='nlme.mmkin-4.png' alt='' width='700' height='433' /></div><div class='input'> + <span class='fu'><a href='https://rdrr.io/r/stats/anova.html'>anova</a></span><span class='op'>(</span><span class='va'>f_nlme_dfop_sfo</span>, <span class='va'>f_nlme_sfo_sfo</span><span class='op'>)</span> </div><div class='output co'>#> Model df AIC BIC logLik Test L.Ratio p-value #> f_nlme_dfop_sfo 1 13 843.8547 884.6201 -408.9273 #> f_nlme_sfo_sfo 2 9 1085.1821 1113.4043 -533.5910 1 vs 2 249.3274 <.0001</div><div class='input'> @@ -449,19 +385,8 @@ with additional elements</p> #> A1 162.30536 539.1667 NA NA NA #> </div><div class='input'> <span class='kw'>if</span> <span class='op'>(</span><span class='fu'><a href='https://rdrr.io/r/base/length.html'>length</a></span><span class='op'>(</span><span class='fu'>findFunction</span><span class='op'>(</span><span class='st'>"varConstProp"</span><span class='op'>)</span><span class='op'>)</span> <span class='op'>></span> <span class='fl'>0</span><span class='op'>)</span> <span class='op'>{</span> <span class='co'># tc error model for nlme available</span> - <span class='co'># Attempts to fit metabolite kinetics with the tc error model</span> - <span class='co'>#f_2_tc <- mmkin(list("SFO-SFO" = m_sfo_sfo,</span> - <span class='co'># "SFO-SFO-ff" = m_sfo_sfo_ff,</span> - <span class='co'># "FOMC-SFO" = m_fomc_sfo,</span> - <span class='co'># "DFOP-SFO" = m_dfop_sfo),</span> - <span class='co'># ds_2, quiet = TRUE,</span> - <span class='co'># error_model = "tc")</span> - <span class='co'>#f_nlme_sfo_sfo_tc <- nlme(f_2_tc["SFO-SFO", ], control = list(maxIter = 100))</span> - <span class='co'>#f_nlme_dfop_sfo_tc <- nlme(f_2_tc["DFOP-SFO", ])</span> - <span class='co'>#f_nlme_dfop_sfo_tc <- update(f_nlme_dfop_sfo, weights = varConstProp(),</span> - <span class='co'># control = list(sigma = 1, msMaxIter = 100, pnlsMaxIter = 15))</span> - <span class='co'># Fitting metabolite kinetics with nlme.mmkin and the two-component</span> - <span class='co'># error model currently does not work, at least not with these data.</span> + <span class='co'># Attempts to fit metabolite kinetics with the tc error model are possible,</span> + <span class='co'># but need tweeking of control values and sometimes do not converge</span> <span class='va'>f_tc</span> <span class='op'><-</span> <span class='fu'><a href='mmkin.html'>mmkin</a></span><span class='op'>(</span><span class='fu'><a href='https://rdrr.io/r/base/c.html'>c</a></span><span class='op'>(</span><span class='st'>"SFO"</span>, <span class='st'>"DFOP"</span><span class='op'>)</span>, <span class='va'>ds</span>, quiet <span class='op'>=</span> <span class='cn'>TRUE</span>, error_model <span class='op'>=</span> <span class='st'>"tc"</span><span class='op'>)</span> <span class='va'>f_nlme_sfo_tc</span> <span class='op'><-</span> <span class='fu'><a href='https://rdrr.io/pkg/nlme/man/nlme.html'>nlme</a></span><span class='op'>(</span><span class='va'>f_tc</span><span class='op'>[</span><span class='st'>"SFO"</span>, <span class='op'>]</span><span class='op'>)</span> diff --git a/man/nlme.mmkin.Rd b/man/nlme.mmkin.Rd index 08ce1ad8..87d84c74 100644 --- a/man/nlme.mmkin.Rd +++ b/man/nlme.mmkin.Rd @@ -83,6 +83,7 @@ f_nlme_sfo <- nlme(f["SFO", ]) 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)) @@ -93,58 +94,36 @@ endpoints(f_nlme_dfop) 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", ]) |