From 349285fccfcb3327eb1f9924db5a880f1e5e1a7d Mon Sep 17 00:00:00 2001 From: Johannes Ranke Date: Wed, 11 Nov 2020 09:47:46 +0100 Subject: Add print and plot calls to the saem example code --- docs/dev/pkgdown.yml | 2 +- docs/dev/reference/Rplot001.png | Bin 19782 -> 19395 bytes docs/dev/reference/Rplot002.png | Bin 16877 -> 16843 bytes docs/dev/reference/Rplot003.png | Bin 28593 -> 28735 bytes docs/dev/reference/Rplot004.png | Bin 49175 -> 49269 bytes docs/dev/reference/Rplot005.png | Bin 15024 -> 57095 bytes docs/dev/reference/saem-1.png | Bin 48512 -> 47315 bytes docs/dev/reference/saem-2.png | Bin 48630 -> 48720 bytes docs/dev/reference/saem-3.png | Bin 82018 -> 82102 bytes docs/dev/reference/saem-4.png | Bin 128571 -> 128231 bytes docs/dev/reference/saem-5.png | Bin 0 -> 164443 bytes docs/dev/reference/saem.html | 160 +++++++++++++++++++++++++--------------- 12 files changed, 102 insertions(+), 60 deletions(-) create mode 100644 docs/dev/reference/saem-5.png (limited to 'docs/dev') diff --git a/docs/dev/pkgdown.yml b/docs/dev/pkgdown.yml index 17d7c266..20533121 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-11-10T04:11Z +last_built: 2020-11-11T08:36Z 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 index fc26276a..bca41e2c 100644 Binary files a/docs/dev/reference/Rplot001.png and b/docs/dev/reference/Rplot001.png differ diff --git a/docs/dev/reference/Rplot002.png b/docs/dev/reference/Rplot002.png index 48e8698c..9b97a634 100644 Binary files a/docs/dev/reference/Rplot002.png and b/docs/dev/reference/Rplot002.png differ diff --git a/docs/dev/reference/Rplot003.png b/docs/dev/reference/Rplot003.png index b4581e35..ff6bc722 100644 Binary files a/docs/dev/reference/Rplot003.png and b/docs/dev/reference/Rplot003.png differ diff --git a/docs/dev/reference/Rplot004.png b/docs/dev/reference/Rplot004.png index 2a90c6ee..98dd019e 100644 Binary files a/docs/dev/reference/Rplot004.png and b/docs/dev/reference/Rplot004.png differ diff --git a/docs/dev/reference/Rplot005.png b/docs/dev/reference/Rplot005.png index b9285d56..5e675828 100644 Binary files a/docs/dev/reference/Rplot005.png and b/docs/dev/reference/Rplot005.png differ diff --git a/docs/dev/reference/saem-1.png b/docs/dev/reference/saem-1.png index 9c3421bd..2df248bb 100644 Binary files a/docs/dev/reference/saem-1.png and b/docs/dev/reference/saem-1.png differ diff --git a/docs/dev/reference/saem-2.png b/docs/dev/reference/saem-2.png index bc975b79..d4a2c1be 100644 Binary files a/docs/dev/reference/saem-2.png and b/docs/dev/reference/saem-2.png differ diff --git a/docs/dev/reference/saem-3.png b/docs/dev/reference/saem-3.png index 5744b722..6a32cda1 100644 Binary files a/docs/dev/reference/saem-3.png and b/docs/dev/reference/saem-3.png differ diff --git a/docs/dev/reference/saem-4.png b/docs/dev/reference/saem-4.png index b020dbbc..bf24d6b0 100644 Binary files a/docs/dev/reference/saem-4.png and b/docs/dev/reference/saem-4.png differ diff --git a/docs/dev/reference/saem-5.png b/docs/dev/reference/saem-5.png new file mode 100644 index 00000000..6e6e0f91 Binary files /dev/null and b/docs/dev/reference/saem-5.png differ diff --git a/docs/dev/reference/saem.html b/docs/dev/reference/saem.html index f9cdf1c8..bc54e1e1 100644 --- a/docs/dev/reference/saem.html +++ b/docs/dev/reference/saem.html @@ -241,53 +241,53 @@ using mmkin.

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] "Tue Nov 10 05:12:21 2020" +#> [1] "Wed Nov 11 09:36:41 2020" #> .... #> Minimisation finished -#> [1] "Tue Nov 10 05:12:23 2020"
+#> [1] "Wed Nov 11 09:36:43 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] "Tue Nov 10 05:12:24 2020" +#> [1] "Wed Nov 11 09:36:44 2020" #> .... #> Minimisation finished -#> [1] "Tue Nov 10 05:12:26 2020"
f_saem_fomc <- saem(f_mmkin_parent["FOMC", ]) +#> [1] "Wed Nov 11 09:36:45 2020"
f_saem_fomc <- saem(f_mmkin_parent["FOMC", ])
#> Running main SAEM algorithm -#> [1] "Tue Nov 10 05:12:26 2020" +#> [1] "Wed Nov 11 09:36:46 2020" #> .... #> Minimisation finished -#> [1] "Tue Nov 10 05:12:28 2020"
f_saem_dfop <- saem(f_mmkin_parent["DFOP", ]) +#> [1] "Wed Nov 11 09:36:48 2020"
f_saem_dfop <- saem(f_mmkin_parent["DFOP", ])
#> Running main SAEM algorithm -#> [1] "Tue Nov 10 05:12:29 2020" +#> [1] "Wed Nov 11 09:36:48 2020" #> .... #> Minimisation finished -#> [1] "Tue Nov 10 05:12:32 2020"
+#> [1] "Wed Nov 11 09:36:51 2020"
# The returned saem.mmkin object contains an SaemixObject, therefore we can use # functions from saemix library(saemix)
#> Package saemix, version 3.1.9000 #> please direct bugs, questions and feedback to emmanuelle.comets@inserm.fr
compare.saemix(list(f_saem_sfo$so, f_saem_fomc$so, f_saem_dfop$so))
#> Likelihoods computed by importance sampling
#> AIC BIC -#> 1 624.2428 622.2900 -#> 2 467.7644 465.0305 -#> 3 491.3541 487.8391
plot(f_saem_fomc$so, plot.type = "convergence") +#> 1 624.2484 622.2956 +#> 2 467.7096 464.9757 +#> 3 495.4373 491.9222
plot(f_saem_fomc$so, plot.type = "convergence")
#> Plotting convergence plots
plot(f_saem_fomc$so, plot.type = "individual.fit")
#> Plotting individual fits
plot(f_saem_fomc$so, plot.type = "npde")
#> Simulating data using nsim = 1000 simulated datasets #> Computing WRES and npde . #> Plotting npde
#> --------------------------------------------- #> Distribution of npde: -#> mean= -0.01736 (SE= 0.098 ) -#> variance= 0.8562 (SE= 0.13 ) -#> skewness= 0.513 -#> kurtosis= 1.202 +#> mean= -0.01528 (SE= 0.098 ) +#> variance= 0.862 (SE= 0.13 ) +#> skewness= 0.5016 +#> kurtosis= 1.18 #> --------------------------------------------- #> #> Statistical tests -#> Wilcoxon signed rank test : 0.652 -#> Fisher variance test : 0.338 -#> SW test of normality : 0.0757 . -#> Global adjusted p-value : 0.227 +#> Wilcoxon signed rank test : 0.679 +#> Fisher variance test : 0.36 +#> SW test of normality : 0.0855 . +#> Global adjusted p-value : 0.257 #> --- #> Signif. codes: '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 #> ---------------------------------------------
plot(f_saem_fomc$so, plot.type = "vpc") @@ -307,13 +307,13 @@ 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] "Tue Nov 10 05:12:34 2020" +#> [1] "Wed Nov 11 09:36:54 2020" #> .... #> Minimisation finished -#> [1] "Tue Nov 10 05:12:39 2020"
compare.saemix(list(f_saem_fomc$so, f_saem_fomc_tc$so)) +#> [1] "Wed Nov 11 09:36:59 2020"
compare.saemix(list(f_saem_fomc$so, f_saem_fomc_tc$so))
#> Likelihoods computed by importance sampling
#> AIC BIC -#> 1 467.7644 465.0305 -#> 2 469.4862 466.3617
+#> 1 467.7096 464.9757 +#> 2 469.5208 466.3963
sfo_sfo <- mkinmod(parent = mkinsub("SFO", "A1"), A1 = mkinsub("SFO"))
#> Successfully compiled differential equation model from auto-generated C code.
fomc_sfo <- mkinmod(parent = mkinsub("FOMC", "A1"), @@ -330,20 +330,62 @@ using mmkin.

# solutions written for mkin this took around four minutes f_saem_sfo_sfo <- saem(f_mmkin["SFO-SFO", ])
#> Running main SAEM algorithm -#> [1] "Tue Nov 10 05:12:42 2020" +#> [1] "Wed Nov 11 09:37:01 2020" #> .... #> Minimisation finished -#> [1] "Tue Nov 10 05:12:47 2020"
f_saem_dfop_sfo <- saem(f_mmkin["DFOP-SFO", ]) +#> [1] "Wed Nov 11 09:37:06 2020"
f_saem_dfop_sfo <- saem(f_mmkin["DFOP-SFO", ])
#> Running main SAEM algorithm -#> [1] "Tue Nov 10 05:12:48 2020" +#> [1] "Wed Nov 11 09:37:06 2020" #> .... #> Minimisation finished -#> [1] "Tue Nov 10 05:12:57 2020"
summary(f_saem_dfop_sfo, data = FALSE) -
#> saemix version used for fitting: 3.1.9000 +#> [1] "Wed Nov 11 09:37:15 2020"
# We can use print, plot and summary methods to check the results +print(f_saem_dfop_sfo) +
#> Kinetic nonlinear mixed-effects model fit by SAEM +#> Structural model: +#> d_parent/dt = - ((k1 * g * exp(-k1 * time) + k2 * (1 - g) * exp(-k2 * +#> time)) / (g * exp(-k1 * time) + (1 - g) * exp(-k2 * time))) +#> * parent +#> d_A1/dt = + f_parent_to_A1 * ((k1 * g * exp(-k1 * time) + k2 * (1 - g) +#> * exp(-k2 * time)) / (g * exp(-k1 * time) + (1 - g) * +#> exp(-k2 * time))) * parent - k_A1 * A1 +#> +#> Data: +#> 170 observations of 2 variable(s) grouped in 5 datasets +#> +#> Likelihood computed by importance sampling +#> +#> LL by is "-407.78 (df=13)" +#> AIC BIC logLik +#> 841.6 836.5 -407.8 +#> +#> Fitted parameters: +#> estimate lower upper +#> parent_0 93.76647 91.15312 96.3798 +#> log_k_A1 -6.13235 -8.45788 -3.8068 +#> f_parent_qlogis -0.97364 -1.36940 -0.5779 +#> log_k1 -2.53176 -3.80372 -1.2598 +#> log_k2 -3.58667 -5.29524 -1.8781 +#> g_qlogis 0.01238 -1.07968 1.1044 +#> Var.parent_0 7.61106 -3.34955 18.5717 +#> Var.log_k_A1 4.64679 -2.73133 12.0249 +#> Var.f_parent_qlogis 0.19693 -0.05498 0.4488 +#> Var.log_k1 2.01717 -0.51980 4.5542 +#> Var.log_k2 3.63412 -0.92964 8.1979 +#> Var.g_qlogis 0.20045 -0.97425 1.3751 +#> a.1 1.88335 1.66636 2.1004 +#> SD.parent_0 2.75881 0.77234 4.7453 +#> SD.log_k_A1 2.15564 0.44429 3.8670 +#> SD.f_parent_qlogis 0.44377 0.15994 0.7276 +#> SD.log_k1 1.42027 0.52714 2.3134 +#> SD.log_k2 1.90634 0.70934 3.1033 +#> SD.g_qlogis 0.44771 -0.86417 1.7596
plot(f_saem_dfop_sfo) +
summary(f_saem_dfop_sfo, data = FALSE) +
#> +#> LL by is "-407.78 (df=13)"
#> 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: Tue Nov 10 05:12:58 2020 -#> Date of summary: Tue Nov 10 05:12:58 2020 +#> Date of fit: Wed Nov 11 09:37:16 2020 +#> Date of summary: Wed Nov 11 09:37:16 2020 #> #> Equations: #> d_parent/dt = - ((k1 * g * exp(-k1 * time) + k2 * (1 - g) * exp(-k2 * @@ -358,7 +400,7 @@ using mmkin.

#> #> Model predictions using solution type analytical #> -#> Fitted in 10.382 s using 300, 100 iterations +#> Fitted in 9.691 s using 300, 100 iterations #> #> Variance model: Constant variance #> @@ -375,33 +417,33 @@ using mmkin.

#> #> Likelihood computed by importance sampling #> AIC BIC logLik -#> 841.3 836.2 -407.7 +#> 841.6 836.5 -407.8 #> #> Optimised, transformed parameters with symmetric confidence intervals: -#> est. lower upper -#> parent_0 93.7514328 91.114 96.389 -#> log_k_A1 -6.1262333 -8.432 -3.820 -#> f_parent_qlogis -0.9739852 -1.372 -0.576 -#> log_k1 -2.4818389 -3.747 -1.217 -#> log_k2 -3.6138617 -5.294 -1.934 -#> g_qlogis -0.0004614 -1.063 1.062 +#> est. lower upper +#> parent_0 93.76647 91.153 96.3798 +#> log_k_A1 -6.13235 -8.458 -3.8068 +#> f_parent_qlogis -0.97364 -1.369 -0.5779 +#> log_k1 -2.53176 -3.804 -1.2598 +#> log_k2 -3.58667 -5.295 -1.8781 +#> g_qlogis 0.01238 -1.080 1.1044 #> #> Correlation: #> prnt_0 lg__A1 f_prn_ log_k1 log_k2 #> log_k_A1 -0.013 #> f_parent_qlogis -0.025 0.050 #> log_k1 0.030 0.000 -0.005 -#> log_k2 0.013 0.005 -0.003 0.037 -#> g_qlogis -0.068 -0.016 0.011 -0.181 -0.181 +#> log_k2 0.010 0.005 -0.003 0.032 +#> g_qlogis -0.063 -0.015 0.010 -0.167 -0.177 #> #> Random effects: #> est. lower upper -#> SD.parent_0 2.7857 0.7825 4.7889 -#> SD.log_k_A1 2.1413 0.4425 3.8400 -#> SD.f_parent_qlogis 0.4463 0.1609 0.7317 -#> SD.log_k1 1.4097 0.5241 2.2954 -#> SD.log_k2 1.8739 0.6979 3.0499 -#> SD.g_qlogis 0.4559 -0.8150 1.7268 +#> SD.parent_0 2.7588 0.7723 4.7453 +#> SD.log_k_A1 2.1556 0.4443 3.8670 +#> SD.f_parent_qlogis 0.4438 0.1599 0.7276 +#> SD.log_k1 1.4203 0.5271 2.3134 +#> SD.log_k2 1.9063 0.7093 3.1033 +#> SD.g_qlogis 0.4477 -0.8642 1.7596 #> #> Variance model: #> est. lower upper @@ -409,24 +451,24 @@ using mmkin.

#> #> Backtransformed parameters with asymmetric confidence intervals: #> est. lower upper -#> parent_0 93.751433 9.111e+01 96.38921 -#> k_A1 0.002185 2.177e-04 0.02193 -#> f_parent_to_A1 0.274087 2.023e-01 0.35986 -#> k1 0.083589 2.359e-02 0.29618 -#> k2 0.026948 5.021e-03 0.14463 -#> g 0.499885 2.567e-01 0.74312 +#> parent_0 93.766473 9.115e+01 96.37983 +#> k_A1 0.002171 2.122e-04 0.02222 +#> f_parent_to_A1 0.274156 2.027e-01 0.35942 +#> k1 0.079519 2.229e-02 0.28371 +#> k2 0.027691 5.015e-03 0.15288 +#> g 0.503095 2.536e-01 0.75109 #> #> Resulting formation fractions: #> ff -#> parent_A1 0.2741 -#> parent_sink 0.7259 +#> parent_A1 0.2742 +#> parent_sink 0.7258 #> #> Estimated disappearance times: #> DT50 DT90 DT50back DT50_k1 DT50_k2 -#> parent 13.91 60.89 18.33 8.292 25.72 -#> A1 317.26 1053.91 NA NA NA
-# Using a single core, the following takes about 6 minutes, using 10 cores -# it is slower instead of faster +#> parent 14.11 59.53 17.92 8.717 25.03 +#> A1 319.21 1060.38 NA NA NA
+# 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) # }
-- cgit v1.2.1