From c6a1733974334b4e97a27170c60e481dc9e9f35d Mon Sep 17 00:00:00 2001
From: Johannes Ranke
saem(object, control, ...) +saem(object, ...) # S3 method for mmkin saem( object, + transformations = c("mkin", "saemix"), + solution_type = "auto", control = list(displayProgress = FALSE, print = FALSE, save = FALSE, save.graphs = FALSE), cores = 1, @@ -168,7 +170,14 @@ Expectation Maximisation algorithm (SAEM). # S3 method for saem.mmkin print(x, digits = max(3, getOption("digits") - 3), ...) -saemix_model(object, cores = 1, verbose = FALSE, ...) +saemix_model( + object, + solution_type = "auto", + transformations = c("mkin", "saemix"), + cores = 1, + verbose = FALSE, + ... +) saemix_data(object, verbose = FALSE, ...)@@ -180,20 +189,26 @@ Expectation Maximisation algorithm (SAEM).- An mmkin row object containing several fits of the same mkinmod model to different datasets
- control -- Passed to saemix::saemix
... Further parameters passed to saemix::saemixModel.
- +cores -+ The number of cores to be used for multicore processing using -
parallel::mclapply()
. Using more than 1 core is experimental and may -lead to excessive forking, apparently depending on the BLAS version -used.transformations ++ Per default, all parameter transformations are done +in mkin. If this argument is set to 'saemix', parameter transformations +are done in 'saemix' for the supported cases. Currently this is only +supported in cases where the initial concentration of the parent is not fixed, +SFO or DFOP is used for the parent and there is either no metabolite or one.
+ +solution_type ++ Possibility to specify the solution type in case the +automatic choice is not desired
+ control +Passed to saemix::saemix
verbose @@ -243,31 +258,31 @@ using mmkin. 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_p0_fixed <- mmkin("FOMC", ds, cores = 1, +f_mmkin_parent_p0_fixed <- mmkin("FOMC", ds, state.ini = c(parent = 100), fixed_initials = "parent", quiet = TRUE) f_saem_p0_fixed <- saem(f_mmkin_parent_p0_fixed)#> Running main SAEM algorithm -#> [1] "Mon Nov 30 15:53:02 2020" +#> [1] "Fri Dec 11 15:37:47 2020" #> .... #> Minimisation finished -#> [1] "Mon Nov 30 15:53:04 2020"+#> [1] "Fri Dec 11 15:37:49 2020"f_mmkin_parent <- mmkin(c("SFO", "FOMC", "DFOP"), ds, quiet = TRUE) f_saem_sfo <- saem(f_mmkin_parent["SFO", ])#> Running main SAEM algorithm -#> [1] "Mon Nov 30 15:53:05 2020" +#> [1] "Fri Dec 11 15:37:51 2020" #> .... #> Minimisation finished -#> [1] "Mon Nov 30 15:53:07 2020"f_saem_fomc <- saem(f_mmkin_parent["FOMC", ]) +#> [1] "Fri Dec 11 15:37:52 2020"f_saem_fomc <- saem(f_mmkin_parent["FOMC", ])#> Running main SAEM algorithm -#> [1] "Mon Nov 30 15:53:07 2020" +#> [1] "Fri Dec 11 15:37:52 2020" #> .... #> Minimisation finished -#> [1] "Mon Nov 30 15:53:09 2020"f_saem_dfop <- saem(f_mmkin_parent["DFOP", ]) +#> [1] "Fri Dec 11 15:37:55 2020"f_saem_dfop <- saem(f_mmkin_parent["DFOP", ])#> Running main SAEM algorithm -#> [1] "Mon Nov 30 15:53:10 2020" +#> [1] "Fri Dec 11 15:37:55 2020" #> .... #> Minimisation finished -#> [1] "Mon Nov 30 15:53:13 2020"+#> [1] "Fri Dec 11 15:37:58 2020"# The returned saem.mmkin object contains an SaemixObject, therefore we can use # functions from saemix library(saemix) @@ -313,10 +328,10 @@ using mmkin. f_mmkin_parent_tc <- update(f_mmkin_parent, error_model = "tc") f_saem_fomc_tc <- saem(f_mmkin_parent_tc["FOMC", ])#> Running main SAEM algorithm -#> [1] "Mon Nov 30 15:53:15 2020" +#> [1] "Fri Dec 11 15:38:01 2020" #> .... #> Minimisation finished -#> [1] "Mon Nov 30 15:53:20 2020"#> Likelihoods computed by importance sampling#> AIC BIC #> 1 467.7096 464.9757 #> 2 469.5208 466.3963@@ -331,20 +346,21 @@ using mmkin. f_mmkin <- mmkin(list( "SFO-SFO" = sfo_sfo, "FOMC-SFO" = fomc_sfo, "DFOP-SFO" = dfop_sfo), ds, quiet = TRUE) -# These take about five seconds each on this system, as we use -# analytical solutions written for saemix. When using the analytical -# solutions written for mkin this took around four minutes +# saem fits of SFO-SFO and DFOP-SFO to these data take about five seconds +# each on this system, as we use analytical solutions written for saemix. +# When using the analytical solutions written for mkin this took around +# four minutes f_saem_sfo_sfo <- saem(f_mmkin["SFO-SFO", ])#> Running main SAEM algorithm -#> [1] "Mon Nov 30 15:53:23 2020" +#> [1] "Fri Dec 11 15:38:09 2020" #> .... #> Minimisation finished -#> [1] "Mon Nov 30 15:53:28 2020"f_saem_dfop_sfo <- saem(f_mmkin["DFOP-SFO", ]) +#> [1] "Fri Dec 11 15:38:14 2020"f_saem_dfop_sfo <- saem(f_mmkin["DFOP-SFO", ])#> Running main SAEM algorithm -#> [1] "Mon Nov 30 15:53:29 2020" +#> [1] "Fri Dec 11 15:38:15 2020" #> .... #> Minimisation finished -#> [1] "Mon Nov 30 15:53:38 2020"# We can use print, plot and summary methods to check the results +#> [1] "Fri Dec 11 15:38:24 2020"#> Kinetic nonlinear mixed-effects model fit by SAEM #> Structural model: @@ -387,8 +403,8 @@ using mmkin.#> saemix version used for fitting: 3.1.9000 #> mkin version used for pre-fitting: 0.9.50.4 #> R version used for fitting: 4.0.3 -#> Date of fit: Mon Nov 30 15:53:38 2020 -#> Date of summary: Mon Nov 30 15:53:39 2020 +#> Date of fit: Fri Dec 11 15:38:25 2020 +#> Date of summary: Fri Dec 11 15:38:25 2020 #> #> Equations: #> d_parent/dt = - ((k1 * g * exp(-k1 * time) + k2 * (1 - g) * exp(-k2 * @@ -403,15 +419,15 @@ using mmkin. #> #> Model predictions using solution type analytical #> -#> Fitted in 9.963 s using 300, 100 iterations +#> Fitted in 10.096 s using 300, 100 iterations #> #> Variance model: Constant variance #> #> Mean of starting values for individual parameters: #> parent_0 log_k_A1 f_parent_qlogis log_k1 log_k2 -#> 93.8101519 -9.7647455 -0.9711148 -1.8799371 -4.2708142 +#> 93.8102 -9.7647 -0.9711 -1.8799 -4.2708 #> g_qlogis -#> 0.1356441 +#> 0.1356 #> #> Fixed degradation parameter values: #> None @@ -422,7 +438,7 @@ using mmkin. #> AIC BIC logLik #> 841.6 836.5 -407.8 #> -#> Optimised, transformed parameters with symmetric confidence intervals: +#> Optimised parameters: #> est. lower upper #> parent_0 93.76647 91.153 96.3798 #> log_k_A1 -6.13235 -8.458 -3.8068 @@ -452,7 +468,7 @@ using mmkin. #> est. lower upper #> a.1 1.883 1.666 2.1 #> -#> Backtransformed parameters with asymmetric confidence intervals: +#> Backtransformed parameters: #> est. lower upper #> parent_0 93.766473 9.115e+01 96.37983 #> k_A1 0.002171 2.122e-04 0.02222 @@ -643,32 +659,19 @@ using mmkin. #> Dataset 10 A1 91 13.2 11.93773 -1.26227 1.883 -0.670224 #> Dataset 10 A1 120 14.3 12.77666 -1.52334 1.883 -0.808847 #> Dataset 10 A1 120 12.1 12.77666 0.67666 1.883 0.359282-# Using a single core, the following takes about 6 minutes as we do not have an -# analytical solution. Using 10 cores it is slower instead of faster -f_saem_fomc <- saem(f_mmkin["FOMC-SFO", ], cores = 1) -#> Running main SAEM algorithm -#> [1] "Mon Nov 30 15:53:39 2020" -#> DLSODA- At current T (=R1), MXSTEP (=I1) steps -#> taken on this call before reaching TOUT -#> In above message, I1 = 5000 -#> -#> In above message, R1 = 0.00156238 -#> -#> DLSODA- At T (=R1) and step size H (=R2), the -#> corrector convergence failed repeatedly -#> or with ABS(H) = HMIN -#> In above message, R1 = 0, R2 = 1.1373e-10 -#> -#> DLSODA- At current T (=R1), MXSTEP (=I1) steps -#> taken on this call before reaching TOUT -#> In above message, I1 = 5000 -#> -#> In above message, R1 = 2.24752e-06 -#> -#> .... -#> Minimisation finished -#> [1] "Mon Nov 30 16:00:45 2020"# } +# The following takes about 6 minutes +#f_saem_dfop_sfo_deSolve <- saem(f_mmkin["DFOP-SFO", ], solution_type = "deSolve", +# control = list(nbiter.saemix = c(200, 80), nbdisplay = 10)) + +#saemix::compare.saemix(list( +# f_saem_dfop_sfo$so, +# f_saem_dfop_sfo_deSolve$so)) + +# If the model supports it, we can also use eigenvalue based solutions, which +# take a similar amount of time +#f_saem_sfo_sfo_eigen <- saem(f_mmkin["SFO-SFO", ], solution_type = "eigen", +# control = list(nbiter.saemix = c(200, 80), nbdisplay = 10)) +# }