From 6b7b93c29115d75bf10c63b61f565a61a2d74498 Mon Sep 17 00:00:00 2001 From: Johannes Ranke Date: Mon, 28 Feb 2022 11:03:23 +0100 Subject: Improve dimethenamid vignette --- vignettes/web_only/dimethenamid_2018.html | 226 ++++++--------------- vignettes/web_only/dimethenamid_2018.rmd | 141 ++++++------- .../f_parent_nlmixr_saem_dfop_tc_1k-1.png | Bin 77251 -> 84973 bytes 3 files changed, 126 insertions(+), 241 deletions(-) diff --git a/vignettes/web_only/dimethenamid_2018.html b/vignettes/web_only/dimethenamid_2018.html index cadbcdbf..2a561b97 100644 --- a/vignettes/web_only/dimethenamid_2018.html +++ b/vignettes/web_only/dimethenamid_2018.html @@ -1591,7 +1591,7 @@ div.tocify {

Example evaluations of the dimethenamid data from 2018

Johannes Ranke

-

Last change 11 January 2022, built on 11 Jan 2022

+

Last change 10 February 2022, built on 28 Feb 2022

@@ -1642,6 +1642,18 @@ f_parent_mkin_tc <- mmkin(c("SFO", "DFOP"), dmta_ds,

The remaining trend of the residuals to be higher for higher predicted residues is reduced by using the two-component error model:

plot(mixed(f_parent_mkin_tc["DFOP", ]), test_log_parms = TRUE)

+

However, note that in the case of using this error model, the fits to the Flaach and BBA 2.3 datasets appear to be ill-defined, indicated by the fact that they did not converge:

+
print(f_parent_mkin_tc["DFOP", ])
+
<mmkin> object
+Status of individual fits:
+
+      dataset
+model  Calke Borstel Flaach BBA 2.2 BBA 2.3 Elliot
+  DFOP OK    OK      C      OK      C       OK    
+
+OK: No warnings
+C: Optimisation did not converge:
+iteration limit reached without convergence (10)

Nonlinear mixed-effects models

@@ -1686,6 +1698,8 @@ anova(f_parent_nlme_dfop_tc, f_parent_nlme_dfop_tc_logchol) saemix_control <- saemixControl(nbiter.saemix = c(800, 300), nb.chains = 15, print = FALSE, save = FALSE, save.graphs = FALSE, displayProgress = FALSE) saemix_control_moreiter <- saemixControl(nbiter.saemix = c(1600, 300), nb.chains = 15, + print = FALSE, save = FALSE, save.graphs = FALSE, displayProgress = FALSE) +saemix_control_10k <- saemixControl(nbiter.saemix = c(10000, 300), nb.chains = 15, print = FALSE, save = FALSE, save.graphs = FALSE, displayProgress = FALSE)

The convergence plot for the SFO model using constant variance is shown below.

f_parent_saemix_sfo_const <- mkin::saem(f_parent_mkin_const["SFO", ], quiet = TRUE,
@@ -1705,50 +1719,29 @@ plot(f_parent_saemix_dfop_const$so, plot.type = "convergence")<
 

This is improved when the DFOP model is fitted with the two-component error model. Convergence of the variance of k2 is enhanced, it remains more or less stable already after 200 iterations of the first phase.

f_parent_saemix_dfop_tc <- mkin::saem(f_parent_mkin_tc["DFOP", ], quiet = TRUE,
   control = saemix_control, transformations = "saemix")
-plot(f_parent_saemix_dfop_tc$so, plot.type = "convergence")
-

-
# The last time I tried (2022-01-11) this gives an error in solve.default(omega.eta)
-# system is computationally singular: reciprocal condition number = 5e-17
-#f_parent_saemix_dfop_tc_10k <- mkin::saem(f_parent_mkin_tc["DFOP", ], quiet = TRUE,
-#  control = saemix_control_10k, transformations = "saemix")
-# Now we do not get a significant improvement by using twice the number of iterations
 f_parent_saemix_dfop_tc_moreiter <- mkin::saem(f_parent_mkin_tc["DFOP", ], quiet = TRUE,
   control = saemix_control_moreiter, transformations = "saemix")
-#plot(f_parent_saemix_dfop_tc_moreiter$so, plot.type = "convergence")
-

An alternative way to fit DFOP in combination with the two-component error model is to use the model formulation with transformed parameters as used per default in mkin.

-
f_parent_saemix_dfop_tc_mkin <- mkin::saem(f_parent_mkin_tc["DFOP", ], quiet = TRUE,
-  control = saemix_control, transformations = "mkin")
-plot(f_parent_saemix_dfop_tc_mkin$so, plot.type = "convergence")
-

As the convergence plots do not clearly indicate that the algorithm has converged, we again use four times the number of iterations, which leads to almost satisfactory convergence (see below).

-
saemix_control_muchmoreiter <- saemixControl(nbiter.saemix = c(3200, 300), nb.chains = 15,
-    print = FALSE, save = FALSE, save.graphs = FALSE, displayProgress = FALSE)
-f_parent_saemix_dfop_tc_mkin_muchmoreiter <- mkin::saem(f_parent_mkin_tc["DFOP", ], quiet = TRUE,
-  control = saemix_control_muchmoreiter, transformations = "mkin")
-plot(f_parent_saemix_dfop_tc_mkin_muchmoreiter$so, plot.type = "convergence")
-

-

The four combinations (SFO/const, SFO/tc, DFOP/const and DFOP/tc), including the variations of the DFOP/tc combination can be compared using the model comparison function of the saemix package:

+plot(f_parent_saemix_dfop_tc$so, plot.type = "convergence")
+

+

Doubling the number of iterations in the first phase of the algorithm leads to a slightly lower likelihood, and therefore to slightly higher AIC and BIC values. With even more iterations, the algorithm stops with an error message. This is related to the variance of k2 approximating zero. This has been submitted as a bug to the saemix package, as the algorithm does not converge in this case.

+

An alternative way to fit DFOP in combination with the two-component error model is to use the model formulation with transformed parameters as used per default in mkin. When using this option, convergence is slower, but eventually the algorithm stops as well with the same error message.

+

The four combinations (SFO/const, SFO/tc, DFOP/const and DFOP/tc) and the version with increased iterations can be compared using the model comparison function of the saemix package:

AIC_parent_saemix <- saemix::compare.saemix(
   f_parent_saemix_sfo_const$so,
   f_parent_saemix_sfo_tc$so,
   f_parent_saemix_dfop_const$so,
   f_parent_saemix_dfop_tc$so,
-  f_parent_saemix_dfop_tc_moreiter$so,
-  f_parent_saemix_dfop_tc_mkin$so,
-  f_parent_saemix_dfop_tc_mkin_muchmoreiter$so)
+ f_parent_saemix_dfop_tc_moreiter$so)
Likelihoods calculated by importance sampling
rownames(AIC_parent_saemix) <- c(
-  "SFO const", "SFO tc", "DFOP const", "DFOP tc", "DFOP tc more iterations",
-  "DFOP tc mkintrans", "DFOP tc mkintrans more iterations")
+  "SFO const", "SFO tc", "DFOP const", "DFOP tc", "DFOP tc more iterations")
 print(AIC_parent_saemix)
-
                                     AIC    BIC
-SFO const                         796.38 795.34
-SFO tc                            798.38 797.13
-DFOP const                        705.75 703.88
-DFOP tc                           665.65 663.57
-DFOP tc more iterations           665.88 663.80
-DFOP tc mkintrans                 674.02 671.94
-DFOP tc mkintrans more iterations 667.94 665.86
-

As in the case of nlme fits, the DFOP model fitted with two-component error (number 4) gives the lowest AIC. Using a much larger number of iterations does not significantly change the AIC. When the mkin transformations are used instead of the saemix transformations, we need four times the number of iterations to obtain a goodness of fit that almost as good as the result obtained with saemix transformations.

+
                           AIC    BIC
+SFO const               796.38 795.34
+SFO tc                  798.38 797.13
+DFOP const              705.75 703.88
+DFOP tc                 665.65 663.57
+DFOP tc more iterations 665.88 663.80

In order to check the influence of the likelihood calculation algorithms implemented in saemix, the likelihood from Gaussian quadrature is added to the best fit, and the AIC values obtained from the three methods are compared.

f_parent_saemix_dfop_tc$so <-
   saemix::llgq.saemix(f_parent_saemix_dfop_tc$so)
@@ -1760,23 +1753,34 @@ AIC_parent_saemix_methods <- c(
 print(AIC_parent_saemix_methods)
    is     gq    lin 
 665.65 665.68 665.11 
-

The AIC values based on importance sampling and Gaussian quadrature are very similar. Using linearisation is known to be less accurate, but still gives a similar value.

+

The AIC values based on importance sampling and Gaussian quadrature are very similar. Using linearisation is known to be less accurate, but still gives a similar value. In order to illustrate that the comparison of the three method depends on the degree of convergence obtained in the fit, the same comparison is shown below for the fit using the defaults for the number of iterations and the number of MCMC chains.

+
f_parent_saemix_dfop_tc_defaults <- mkin::saem(f_parent_mkin_tc["DFOP", ])
+f_parent_saemix_dfop_tc_defaults$so <-
+  saemix::llgq.saemix(f_parent_saemix_dfop_tc_defaults$so)
+AIC_parent_saemix_methods_defaults <- c(
+  is = AIC(f_parent_saemix_dfop_tc_defaults$so, method = "is"),
+  gq = AIC(f_parent_saemix_dfop_tc_defaults$so, method = "gq"),
+  lin = AIC(f_parent_saemix_dfop_tc_defaults$so, method = "lin")
+)
+print(AIC_parent_saemix_methods_defaults)
+
    is     gq    lin 
+668.27 718.36 666.49 

nlmixr

In the last years, a lot of effort has been put into the nlmixr package which is designed for pharmacokinetics, where nonlinear mixed-effects models are routinely used, but which can also be used for related data like chemical degradation data. A current development branch of the mkin package provides an interface between mkin and nlmixr. Here, we check if we get equivalent results when using a refined version of the First Order Conditional Estimation (FOCE) algorithm used in nlme, namely the First Order Conditional Estimation with Interaction (FOCEI), and the SAEM algorithm as implemented in nlmixr.

-

First, the focei algorithm is used for the four model combinations. A number of warnings are produced with unclear significance.

+

First, the focei algorithm is used for the four model combinations.

library(nlmixr)
 f_parent_nlmixr_focei_sfo_const <- nlmixr(f_parent_mkin_const["SFO", ], est = "focei")
 f_parent_nlmixr_focei_sfo_tc <- nlmixr(f_parent_mkin_tc["SFO", ], est = "focei")
 f_parent_nlmixr_focei_dfop_const <- nlmixr(f_parent_mkin_const["DFOP", ], est = "focei")
 f_parent_nlmixr_focei_dfop_tc<- nlmixr(f_parent_mkin_tc["DFOP", ], est = "focei")
+

For the SFO model with constant variance, the AIC values are the same, for the DFOP model, there are significant differences between the AIC values. These may be caused by different solutions that are found, but also by the fact that the AIC values for the nlmixr fits are calculated based on Gaussian quadrature, not on linearisation.

aic_nlmixr_focei <- sapply(
   list(f_parent_nlmixr_focei_sfo_const$nm, f_parent_nlmixr_focei_sfo_tc$nm,
     f_parent_nlmixr_focei_dfop_const$nm, f_parent_nlmixr_focei_dfop_tc$nm),
-  AIC)
-

The AIC values are very close to the ones obtained with nlme which are repeated below for convenience.

-
aic_nlme <- sapply(
+  AIC)
+aic_nlme <- sapply(
   list(f_parent_nlme_sfo_const, NA, f_parent_nlme_sfo_tc, f_parent_nlme_dfop_tc),
   function(x) if (is.na(x[1])) NA else AIC(x))
 aic_nlme_nlmixr_focei <- data.frame(
@@ -1792,11 +1796,11 @@ print(aic_nlme_nlmixr_focei)
2 SFO two-component NA 798.64 3 DFOP constant variance 798.60 745.87 4 DFOP two-component 671.91 740.42 -

Secondly, we use the SAEM estimation routine and check the convergence plots. The control parameters also used for the saemix fits are defined beforehand.

+

Secondly, we use the SAEM estimation routine and check the convergence plots. The control parameters, which were also used for the saemix fits, are defined beforehand.

nlmixr_saem_control_800 <- saemControl(logLik = TRUE,
   nBurn = 800, nEm = 300, nmc = 15)
-nlmixr_saem_control_1000 <- saemControl(logLik = TRUE,
-  nBurn = 1000, nEm = 300, nmc = 15)
+nlmixr_saem_control_moreiter <- saemControl(logLik = TRUE,
+  nBurn = 1600, nEm = 300, nmc = 15)
 nlmixr_saem_control_10k <- saemControl(logLik = TRUE,
   nBurn = 10000, nEm = 1000, nmc = 15)

Then we fit SFO with constant variance

@@ -1809,40 +1813,39 @@ traceplot(f_parent_nlmixr_saem_sfo_const$nm) control = nlmixr_saem_control_800) traceplot(f_parent_nlmixr_saem_sfo_tc$nm)

-

For DFOP with constant variance, the convergence plots show considerable instability of the fit, which indicates overparameterisation which was already observed above for this model combination.

+

For DFOP with constant variance, the convergence plots show considerable instability of the fit, which indicates overparameterisation which was already observed above for this model combination. Also note that the variance of k2 approximates zero, which was already observed in the saemix fits of the DFOP model.

f_parent_nlmixr_saem_dfop_const <- nlmixr(f_parent_mkin_const["DFOP", ], est = "saem",
   control = nlmixr_saem_control_800)
 traceplot(f_parent_nlmixr_saem_dfop_const$nm)

-

For DFOP with two-component error, a less erratic convergence is seen.

+

For DFOP with two-component error, a less erratic convergence is seen, but the variance of k2 again approximates zero.

f_parent_nlmixr_saem_dfop_tc <- nlmixr(f_parent_mkin_tc["DFOP", ], est = "saem",
   control = nlmixr_saem_control_800)
 traceplot(f_parent_nlmixr_saem_dfop_tc$nm)

To check if an increase in the number of iterations improves the fit, we repeat the fit with 1000 iterations for the burn in phase and 300 iterations for the second phase.

-
f_parent_nlmixr_saem_dfop_tc_1000 <- nlmixr(f_parent_mkin_tc["DFOP", ], est = "saem",
-  control = nlmixr_saem_control_1000)
-traceplot(f_parent_nlmixr_saem_dfop_tc_1000$nm)
-

+
f_parent_nlmixr_saem_dfop_tc_moreiter <- nlmixr(f_parent_mkin_tc["DFOP", ], est = "saem",
+  control = nlmixr_saem_control_moreiter)
+traceplot(f_parent_nlmixr_saem_dfop_tc_moreiter$nm)
+

Here the fit looks very similar, but we will see below that it shows a higher AIC than the fit with 800 iterations in the burn in phase. Next we choose 10 000 iterations for the burn in phase and 1000 iterations for the second phase for comparison with saemix.

f_parent_nlmixr_saem_dfop_tc_10k <- nlmixr(f_parent_mkin_tc["DFOP", ], est = "saem",
   control = nlmixr_saem_control_10k)
 traceplot(f_parent_nlmixr_saem_dfop_tc_10k$nm)

-

In the above convergence plot, the time course of ‘eta.DMTA_0’ and ‘log_k2’ indicate a false convergence.

The AIC values are internally calculated using Gaussian quadrature.

AIC(f_parent_nlmixr_saem_sfo_const$nm, f_parent_nlmixr_saem_sfo_tc$nm,
   f_parent_nlmixr_saem_dfop_const$nm, f_parent_nlmixr_saem_dfop_tc$nm,
-  f_parent_nlmixr_saem_dfop_tc_1000$nm,
+  f_parent_nlmixr_saem_dfop_tc_moreiter$nm,
   f_parent_nlmixr_saem_dfop_tc_10k$nm)
-
                                     df     AIC
-f_parent_nlmixr_saem_sfo_const$nm     5  798.71
-f_parent_nlmixr_saem_sfo_tc$nm        6  808.64
-f_parent_nlmixr_saem_dfop_const$nm    9 1995.96
-f_parent_nlmixr_saem_dfop_tc$nm      10  664.96
-f_parent_nlmixr_saem_dfop_tc_1000$nm 10  667.39
-f_parent_nlmixr_saem_dfop_tc_10k$nm  10     Inf
-

We can see that again, the DFOP/tc model shows the best goodness of fit. However, increasing the number of burn-in iterations from 800 to 1000 results in a higher AIC. If we further increase the number of iterations to 10 000 (burn-in) and 1000 (second phase), the AIC cannot be calculated for the nlmixr/saem fit, supporting that the fit did not converge properly.

+
                                         df     AIC
+f_parent_nlmixr_saem_sfo_const$nm         5  798.71
+f_parent_nlmixr_saem_sfo_tc$nm            6  808.64
+f_parent_nlmixr_saem_dfop_const$nm        9 1995.96
+f_parent_nlmixr_saem_dfop_tc$nm          10  664.96
+f_parent_nlmixr_saem_dfop_tc_moreiter$nm 10 4464.93
+f_parent_nlmixr_saem_dfop_tc_10k$nm      10     Inf
+

We can see that again, the DFOP/tc model shows the best goodness of fit. However, increasing the number of burn-in iterations from 800 to 1600 results in a higher AIC. If we further increase the number of iterations to 10 000 (burn-in) and 1000 (second phase), the AIC cannot be calculated for the nlmixr/saem fit, confirming that this fit does not converge properly with the SAEM algorithm.

Comparison

@@ -1906,111 +1909,6 @@ kable(AIC_all) -
intervals(f_parent_saemix_dfop_tc)
-
Approximate 95% confidence intervals
-
- Fixed effects:
-            lower       est.      upper
-DMTA_0 96.3087887 98.2761715 100.243554
-k1      0.0336893  0.0643651   0.095041
-k2      0.0062993  0.0088001   0.011301
-g       0.9100426  0.9524920   0.994941
-
- Random effects:
-               lower      est.    upper
-sd(DMTA_0)   0.41868 2.0607469  3.70281
-sd(k1)       0.25611 0.5935653  0.93102
-sd(k2)     -10.29603 0.0029188 10.30187
-sd(g)        0.38083 1.0572543  1.73368
-
- 
-      lower     est.    upper
-a.1 0.86253 1.061610 1.260690
-b.1 0.02262 0.029666 0.036712
-
intervals(f_parent_saemix_dfop_tc)
-
Approximate 95% confidence intervals
-
- Fixed effects:
-            lower       est.      upper
-DMTA_0 96.3087887 98.2761715 100.243554
-k1      0.0336893  0.0643651   0.095041
-k2      0.0062993  0.0088001   0.011301
-g       0.9100426  0.9524920   0.994941
-
- Random effects:
-               lower      est.    upper
-sd(DMTA_0)   0.41868 2.0607469  3.70281
-sd(k1)       0.25611 0.5935653  0.93102
-sd(k2)     -10.29603 0.0029188 10.30187
-sd(g)        0.38083 1.0572543  1.73368
-
- 
-      lower     est.    upper
-a.1 0.86253 1.061610 1.260690
-b.1 0.02262 0.029666 0.036712
-
intervals(f_parent_saemix_dfop_tc_mkin_muchmoreiter)
-
Approximate 95% confidence intervals
-
- Fixed effects:
-            lower       est.      upper
-DMTA_0 96.3402070 98.2789378 100.217669
-k1      0.0397896  0.0641976   0.103578
-k2      0.0041987  0.0084427   0.016977
-g       0.8656257  0.9521509   0.983992
-
- Random effects:
-                lower    est.   upper
-sd(DMTA_0)    0.38907 2.01821 3.64735
-sd(log_k1)    0.25653 0.59512 0.93371
-sd(log_k2)   -0.20501 0.37610 0.95721
-sd(g_qlogis)  0.39712 1.18296 1.96879
-
- 
-       lower     est.    upper
-a.1 0.868558 1.070260 1.271963
-b.1 0.022461 0.029505 0.036548
-
intervals(f_parent_nlmixr_saem_dfop_tc)
-
Approximate 95% confidence intervals
-
- Fixed effects:
-            lower       est.      upper
-DMTA_0 96.3224806 98.2941093 100.265738
-k1      0.0402270  0.0648200   0.104448
-k2      0.0068547  0.0093928   0.012871
-g       0.8764066  0.9501419   0.980848
-
- Random effects:
-             lower     est. upper
-sd(DMTA_0)      NA 1.686509    NA
-sd(log_k1)      NA 0.592805    NA
-sd(log_k2)      NA 0.009766    NA
-sd(g_qlogis)    NA 1.082616    NA
-
- 
-          lower     est. upper
-sigma_low    NA 1.081677    NA
-rsd_high     NA 0.032073    NA
-
intervals(f_parent_nlmixr_saem_dfop_tc_10k)
-
Approximate 95% confidence intervals
-
- Fixed effects:
-            lower       est.      upper
-DMTA_0 96.2302085 98.1641090 100.098010
-k1      0.0398514  0.0643909   0.104041
-k2      0.0066292  0.0090784   0.012432
-g       0.8831478  0.9527284   0.981734
-
- Random effects:
-             lower       est. upper
-sd(DMTA_0)      NA 1.6257e+00    NA
-sd(log_k1)      NA 5.9627e-01    NA
-sd(log_k2)      NA 5.8400e-07    NA
-sd(g_qlogis)    NA 1.0676e+00    NA
-
- 
-          lower     est. upper
-sigma_low    NA 1.087722    NA
-rsd_high     NA 0.031883    NA
diff --git a/vignettes/web_only/dimethenamid_2018.rmd b/vignettes/web_only/dimethenamid_2018.rmd index 08661b5a..7700fe35 100644 --- a/vignettes/web_only/dimethenamid_2018.rmd +++ b/vignettes/web_only/dimethenamid_2018.rmd @@ -1,7 +1,7 @@ --- title: Example evaluations of the dimethenamid data from 2018 author: Johannes Ranke -date: Last change 11 January 2022, built on `r format(Sys.Date(), format = "%d %b %Y")` +date: Last change 10 February 2022, built on `r format(Sys.Date(), format = "%d %b %Y")` output: html_document: toc: true @@ -137,6 +137,14 @@ is reduced by using the two-component error model: plot(mixed(f_parent_mkin_tc["DFOP", ]), test_log_parms = TRUE) ``` +However, note that in the case of using this error model, the fits to the +Flaach and BBA 2.3 datasets appear to be ill-defined, indicated by the fact +that they did not converge: + +```{r f_parent_mkin_dfop_tc_print} +print(f_parent_mkin_tc["DFOP", ]) +``` + ## Nonlinear mixed-effects models Instead of taking a model selection decision for each of the individual fits, we fit @@ -236,6 +244,8 @@ saemix_control <- saemixControl(nbiter.saemix = c(800, 300), nb.chains = 15, print = FALSE, save = FALSE, save.graphs = FALSE, displayProgress = FALSE) saemix_control_moreiter <- saemixControl(nbiter.saemix = c(1600, 300), nb.chains = 15, print = FALSE, save = FALSE, save.graphs = FALSE, displayProgress = FALSE) +saemix_control_10k <- saemixControl(nbiter.saemix = c(10000, 300), nb.chains = 15, + print = FALSE, save = FALSE, save.graphs = FALSE, displayProgress = FALSE) ``` The convergence plot for the SFO model using constant variance is shown below. @@ -271,43 +281,25 @@ stable already after 200 iterations of the first phase. ```{r f_parent_saemix_dfop_tc, results = 'hide', dependson = "saemix_control"} f_parent_saemix_dfop_tc <- mkin::saem(f_parent_mkin_tc["DFOP", ], quiet = TRUE, control = saemix_control, transformations = "saemix") -plot(f_parent_saemix_dfop_tc$so, plot.type = "convergence") -``` - -```{r f_parent_saemix_dfop_tc_moreiter, results = 'hide', dependson = "saemix_control"} -# The last time I tried (2022-01-11) this gives an error in solve.default(omega.eta) -# system is computationally singular: reciprocal condition number = 5e-17 -#f_parent_saemix_dfop_tc_10k <- mkin::saem(f_parent_mkin_tc["DFOP", ], quiet = TRUE, -# control = saemix_control_10k, transformations = "saemix") -# Now we do not get a significant improvement by using twice the number of iterations f_parent_saemix_dfop_tc_moreiter <- mkin::saem(f_parent_mkin_tc["DFOP", ], quiet = TRUE, control = saemix_control_moreiter, transformations = "saemix") -#plot(f_parent_saemix_dfop_tc_moreiter$so, plot.type = "convergence") +plot(f_parent_saemix_dfop_tc$so, plot.type = "convergence") ``` +Doubling the number of iterations in the first phase of the algorithm +leads to a slightly lower likelihood, and therefore to slightly higher AIC and BIC values. +With even more iterations, the algorithm stops with an error message. This is +related to the variance of k2 approximating zero. This has been submitted +as a [bug to the saemix package](https://github.com/saemixdevelopment/saemixextension/issues/29), +as the algorithm does not converge in this case. + An alternative way to fit DFOP in combination with the two-component error model is to use the model formulation with transformed parameters as used per default -in mkin. - -```{r f_parent_saemix_dfop_tc_mkin, results = 'hide', dependson = "saemix_control"} -f_parent_saemix_dfop_tc_mkin <- mkin::saem(f_parent_mkin_tc["DFOP", ], quiet = TRUE, - control = saemix_control, transformations = "mkin") -plot(f_parent_saemix_dfop_tc_mkin$so, plot.type = "convergence") -``` -As the convergence plots do not clearly indicate that the algorithm has converged, we -again use four times the number of iterations, which leads to almost satisfactory -convergence (see below). - -```{r f_parent_saemix_dfop_tc_mkin_moreiter, results = 'hide', dependson = "saemix_control"} -saemix_control_muchmoreiter <- saemixControl(nbiter.saemix = c(3200, 300), nb.chains = 15, - print = FALSE, save = FALSE, save.graphs = FALSE, displayProgress = FALSE) -f_parent_saemix_dfop_tc_mkin_muchmoreiter <- mkin::saem(f_parent_mkin_tc["DFOP", ], quiet = TRUE, - control = saemix_control_muchmoreiter, transformations = "mkin") -plot(f_parent_saemix_dfop_tc_mkin_muchmoreiter$so, plot.type = "convergence") -``` +in mkin. When using this option, convergence is slower, but eventually +the algorithm stops as well with the same error message. -The four combinations (SFO/const, SFO/tc, DFOP/const and DFOP/tc), including -the variations of the DFOP/tc combination can be compared using the model +The four combinations (SFO/const, SFO/tc, DFOP/const and DFOP/tc) and +the version with increased iterations can be compared using the model comparison function of the saemix package: ```{r AIC_parent_saemix, cache = FALSE} @@ -316,22 +308,12 @@ AIC_parent_saemix <- saemix::compare.saemix( f_parent_saemix_sfo_tc$so, f_parent_saemix_dfop_const$so, f_parent_saemix_dfop_tc$so, - f_parent_saemix_dfop_tc_moreiter$so, - f_parent_saemix_dfop_tc_mkin$so, - f_parent_saemix_dfop_tc_mkin_muchmoreiter$so) + f_parent_saemix_dfop_tc_moreiter$so) rownames(AIC_parent_saemix) <- c( - "SFO const", "SFO tc", "DFOP const", "DFOP tc", "DFOP tc more iterations", - "DFOP tc mkintrans", "DFOP tc mkintrans more iterations") + "SFO const", "SFO tc", "DFOP const", "DFOP tc", "DFOP tc more iterations") print(AIC_parent_saemix) ``` -As in the case of nlme fits, the DFOP model fitted with two-component error -(number 4) gives the lowest AIC. Using a much larger number of iterations -does not significantly change the AIC. When the mkin transformations are used -instead of the saemix transformations, we need four times the number of -iterations to obtain a goodness of fit that almost as good as the result -obtained with saemix transformations. - In order to check the influence of the likelihood calculation algorithms implemented in saemix, the likelihood from Gaussian quadrature is added to the best fit, and the AIC values obtained from the three methods @@ -350,7 +332,22 @@ print(AIC_parent_saemix_methods) The AIC values based on importance sampling and Gaussian quadrature are very similar. Using linearisation is known to be less accurate, but still gives a -similar value. +similar value. In order to illustrate that the comparison of the three method +depends on the degree of convergence obtained in the fit, the same comparison +is shown below for the fit using the defaults for the number of iterations and +the number of MCMC chains. + +```{r AIC_parent_saemix_methods_defaults, cache = FALSE} +f_parent_saemix_dfop_tc_defaults <- mkin::saem(f_parent_mkin_tc["DFOP", ]) +f_parent_saemix_dfop_tc_defaults$so <- + saemix::llgq.saemix(f_parent_saemix_dfop_tc_defaults$so) +AIC_parent_saemix_methods_defaults <- c( + is = AIC(f_parent_saemix_dfop_tc_defaults$so, method = "is"), + gq = AIC(f_parent_saemix_dfop_tc_defaults$so, method = "gq"), + lin = AIC(f_parent_saemix_dfop_tc_defaults$so, method = "lin") +) +print(AIC_parent_saemix_methods_defaults) +``` ### nlmixr @@ -363,8 +360,7 @@ results when using a refined version of the First Order Conditional Estimation (FOCE) algorithm used in nlme, namely the First Order Conditional Estimation with Interaction (FOCEI), and the SAEM algorithm as implemented in nlmixr. -First, the focei algorithm is used for the four model combinations. A number of -warnings are produced with unclear significance. +First, the focei algorithm is used for the four model combinations. ```{r f_parent_nlmixr_focei, results = "hide", message = FALSE, warning = FALSE} library(nlmixr) @@ -374,17 +370,17 @@ f_parent_nlmixr_focei_dfop_const <- nlmixr(f_parent_mkin_const["DFOP", ], est = f_parent_nlmixr_focei_dfop_tc<- nlmixr(f_parent_mkin_tc["DFOP", ], est = "focei") ``` -```{r AIC_parent_nlmixr_focei, cache = FALSE} +For the SFO model with constant variance, the AIC values are the same, for the +DFOP model, there are significant differences between the AIC values. These +may be caused by different solutions that are found, but also by the fact that +the AIC values for the nlmixr fits are calculated based on Gaussian quadrature, +not on linearisation. + +```{r AIC_parent_nlmixr_nlme, cache = FALSE} aic_nlmixr_focei <- sapply( list(f_parent_nlmixr_focei_sfo_const$nm, f_parent_nlmixr_focei_sfo_tc$nm, f_parent_nlmixr_focei_dfop_const$nm, f_parent_nlmixr_focei_dfop_tc$nm), AIC) -``` - -The AIC values are very close to the ones obtained with nlme which are repeated below -for convenience. - -```{r AIC_parent_nlme_rep, cache = FALSE} aic_nlme <- sapply( list(f_parent_nlme_sfo_const, NA, f_parent_nlme_sfo_tc, f_parent_nlme_dfop_tc), function(x) if (is.na(x[1])) NA else AIC(x)) @@ -399,13 +395,13 @@ print(aic_nlme_nlmixr_focei) ``` Secondly, we use the SAEM estimation routine and check the convergence plots. The -control parameters also used for the saemix fits are defined beforehand. +control parameters, which were also used for the saemix fits, are defined beforehand. ```{r nlmixr_saem_control} nlmixr_saem_control_800 <- saemControl(logLik = TRUE, nBurn = 800, nEm = 300, nmc = 15) -nlmixr_saem_control_1000 <- saemControl(logLik = TRUE, - nBurn = 1000, nEm = 300, nmc = 15) +nlmixr_saem_control_moreiter <- saemControl(logLik = TRUE, + nBurn = 1600, nEm = 300, nmc = 15) nlmixr_saem_control_10k <- saemControl(logLik = TRUE, nBurn = 10000, nEm = 1000, nmc = 15) ``` @@ -428,7 +424,9 @@ traceplot(f_parent_nlmixr_saem_sfo_tc$nm) For DFOP with constant variance, the convergence plots show considerable instability of the fit, which indicates overparameterisation which was already -observed above for this model combination. +observed above for this model combination. Also note that the variance of k2 +approximates zero, which was already observed in the saemix fits of the DFOP +model. ```{r f_parent_nlmixr_saem_dfop_const, results = "hide", warning = FALSE, message = FALSE, dependson = "nlmixr_saem_control"} f_parent_nlmixr_saem_dfop_const <- nlmixr(f_parent_mkin_const["DFOP", ], est = "saem", @@ -436,7 +434,8 @@ f_parent_nlmixr_saem_dfop_const <- nlmixr(f_parent_mkin_const["DFOP", ], est = " traceplot(f_parent_nlmixr_saem_dfop_const$nm) ``` -For DFOP with two-component error, a less erratic convergence is seen. +For DFOP with two-component error, a less erratic convergence is seen, but the +variance of k2 again approximates zero. ```{r f_parent_nlmixr_saem_dfop_tc, results = "hide", warning = FALSE, message = FALSE, dependson = "nlmixr_saem_control"} f_parent_nlmixr_saem_dfop_tc <- nlmixr(f_parent_mkin_tc["DFOP", ], est = "saem", @@ -449,9 +448,9 @@ the fit with 1000 iterations for the burn in phase and 300 iterations for the second phase. ```{r f_parent_nlmixr_saem_dfop_tc_1k, results = "hide", warning = FALSE, message = FALSE, dependson = "nlmixr_saem_control"} -f_parent_nlmixr_saem_dfop_tc_1000 <- nlmixr(f_parent_mkin_tc["DFOP", ], est = "saem", - control = nlmixr_saem_control_1000) -traceplot(f_parent_nlmixr_saem_dfop_tc_1000$nm) +f_parent_nlmixr_saem_dfop_tc_moreiter <- nlmixr(f_parent_mkin_tc["DFOP", ], est = "saem", + control = nlmixr_saem_control_moreiter) +traceplot(f_parent_nlmixr_saem_dfop_tc_moreiter$nm) ``` Here the fit looks very similar, but we will see below that it shows a higher AIC @@ -465,23 +464,21 @@ f_parent_nlmixr_saem_dfop_tc_10k <- nlmixr(f_parent_mkin_tc["DFOP", ], est = "sa traceplot(f_parent_nlmixr_saem_dfop_tc_10k$nm) ``` -In the above convergence plot, the time course of 'eta.DMTA_0' and -'log_k2' indicate a false convergence. - The AIC values are internally calculated using Gaussian quadrature. ```{r AIC_parent_nlmixr_saem, cache = FALSE} AIC(f_parent_nlmixr_saem_sfo_const$nm, f_parent_nlmixr_saem_sfo_tc$nm, f_parent_nlmixr_saem_dfop_const$nm, f_parent_nlmixr_saem_dfop_tc$nm, - f_parent_nlmixr_saem_dfop_tc_1000$nm, + f_parent_nlmixr_saem_dfop_tc_moreiter$nm, f_parent_nlmixr_saem_dfop_tc_10k$nm) ``` We can see that again, the DFOP/tc model shows the best goodness of fit. -However, increasing the number of burn-in iterations from 800 to 1000 results +However, increasing the number of burn-in iterations from 800 to 1600 results in a higher AIC. If we further increase the number of iterations to 10 000 (burn-in) and 1000 (second phase), the AIC cannot be calculated for the -nlmixr/saem fit, supporting that the fit did not converge properly. +nlmixr/saem fit, confirming that this fit does not converge properly with +the SAEM algorithm. ### Comparison @@ -505,16 +502,6 @@ AIC_all <- data.frame( kable(AIC_all) ``` -```{r parms_all, cache = FALSE} -intervals(f_parent_saemix_dfop_tc) -intervals(f_parent_saemix_dfop_tc) -intervals(f_parent_saemix_dfop_tc_mkin_muchmoreiter) -intervals(f_parent_nlmixr_saem_dfop_tc) -intervals(f_parent_nlmixr_saem_dfop_tc_10k) -``` - - - # References diff --git a/vignettes/web_only/dimethenamid_2018_files/figure-html/f_parent_nlmixr_saem_dfop_tc_1k-1.png b/vignettes/web_only/dimethenamid_2018_files/figure-html/f_parent_nlmixr_saem_dfop_tc_1k-1.png index aac73dbe..70987378 100644 Binary files a/vignettes/web_only/dimethenamid_2018_files/figure-html/f_parent_nlmixr_saem_dfop_tc_1k-1.png and b/vignettes/web_only/dimethenamid_2018_files/figure-html/f_parent_nlmixr_saem_dfop_tc_1k-1.png differ -- cgit v1.2.1