From ea57db98cef3fb882f7bd9656b44f270e7bded38 Mon Sep 17 00:00:00 2001 From: Johannes Ranke Date: Tue, 12 Apr 2022 14:41:07 +0200 Subject: More control of y axes in plot.mkinfit, updates Documentation and test results were updated, the latter with regard to the previous work on plot.mixed.mmkin. --- NEWS.md | 2 ++ R/plot.mkinfit.R | 17 +++++++++++------ README.md | 2 +- man/plot.mkinfit.Rd | 3 ++- test.log | 14 +++++++------- .../_snaps/plot/mixed-model-fit-for-mmkin-object.svg | 4 ++-- .../_snaps/plot/mixed-model-fit-for-nlme-object.svg | 2 +- ...el-fit-for-saem-object-with-mkin-transformations.svg | 4 ++-- ...-fit-for-saem-object-with-saemix-transformations.svg | 4 ++-- 9 files changed, 30 insertions(+), 22 deletions(-) diff --git a/NEWS.md b/NEWS.md index 77eec332..f051915e 100644 --- a/NEWS.md +++ b/NEWS.md @@ -10,6 +10,8 @@ - 'plot.mixed.mmkin': Pass the frame argument also to residual plots, take the 'default_log_parms' argument for 'mean_degparms' used for constructing approximate population curves, plot population curve last to avoid that it is covered by data +- 'plot.mkinfit': Respect argument 'maxabs' for residual plots, and make it possible to give ylim as a list, for row layouts + # mkin 1.1.0 (2022-03-14) ## Mixed-effects models diff --git a/R/plot.mkinfit.R b/R/plot.mkinfit.R index 1d4ea543..cafccae9 100644 --- a/R/plot.mkinfit.R +++ b/R/plot.mkinfit.R @@ -20,7 +20,8 @@ utils::globalVariables(c("type", "variable", "observed")) #' @param xlab Label for the x axis. #' @param ylab Label for the y axis. #' @param xlim Plot range in x direction. -#' @param ylim Plot range in y direction. +#' @param ylim Plot range in y direction. If given as a list, plot ranges +#' for the different plot rows can be given for row layout. #' @param col_obs Colors used for plotting the observed data and the #' corresponding model prediction lines. #' @param pch_obs Symbols to be used for plotting the data. @@ -191,11 +192,15 @@ plot.mkinfit <- function(x, fit = x, row_obs_vars = if (sep_obs) obs_vars[plot_row] else obs_vars # Set ylim to sensible default, or to the specified value - if (ylim[[1]] == "default") { - ylim_row = c(0, max(c(subset(fit$data, variable %in% row_obs_vars)$observed, - unlist(out[row_obs_vars])), na.rm = TRUE)) + if (is.list(ylim)) { + ylim_row <- ylim[[plot_row]] } else { - ylim_row = ylim + if (ylim[[1]] == "default") { + ylim_row = c(0, max(c(subset(fit$data, variable %in% row_obs_vars)$observed, + unlist(out[row_obs_vars])), na.rm = TRUE)) + } else { + ylim_row = ylim + } } if (row_layout) { @@ -278,7 +283,7 @@ plot.mkinfit <- function(x, fit = x, if (show_residuals) { mkinresplot(fit, obs_vars = row_obs_vars, standardized = standardized, pch_obs = pch_obs[row_obs_vars], col_obs = col_obs[row_obs_vars], - legend = FALSE, frame = frame, xlab = xlab, xlim = xlim) + legend = FALSE, frame = frame, xlab = xlab, xlim = xlim, maxabs = maxabs) } # Show error model plot if requested diff --git a/README.md b/README.md index 7c29696a..67cee4e9 100644 --- a/README.md +++ b/README.md @@ -66,7 +66,7 @@ version is found in the ['dev' subdirectory](https://pkgdown.jrwb.de/mkin/dev/). * The chi-squared error level as defined in the FOCUS kinetics guidance (see below) is calculated for each observed variable. * The 'variance by variable' error model which is often fitted using - Iteratively Reweighted Least Squares (IRLS) should now be specified as + Iteratively Reweighted Least Squares (IRLS) can be specified as `error_model = "obs"`. ### Unique in mkin diff --git a/man/plot.mkinfit.Rd b/man/plot.mkinfit.Rd index 9fd4c038..c63f51cb 100644 --- a/man/plot.mkinfit.Rd +++ b/man/plot.mkinfit.Rd @@ -67,7 +67,8 @@ variables in the model.} \item{xlim}{Plot range in x direction.} -\item{ylim}{Plot range in y direction.} +\item{ylim}{Plot range in y direction. If given as a list, plot ranges +for the different plot rows can be given for row layout.} \item{col_obs}{Colors used for plotting the observed data and the corresponding model prediction lines.} diff --git a/test.log b/test.log index 2fc6a43c..44a93ac1 100644 --- a/test.log +++ b/test.log @@ -3,16 +3,16 @@ Loading required package: parallel ℹ Testing mkin ✔ | F W S OK | Context ✔ | 5 | AIC calculation -✔ | 5 | Analytical solutions for coupled models [3.3s] +✔ | 5 | Analytical solutions for coupled models [3.5s] ✔ | 5 | Calculation of Akaike weights ✔ | 3 | Export dataset for reading into CAKE ✔ | 12 | Confidence intervals and p-values [1.0s] -✔ | 1 12 | Dimethenamid data from 2018 [31.0s] +✔ | 1 12 | Dimethenamid data from 2018 [31.6s] ──────────────────────────────────────────────────────────────────────────────── Skip (test_dmta.R:98:3): Different backends get consistent results for SFO-SFO3+, dimethenamid data Reason: Fitting this ODE model with saemix takes about 15 minutes on my system ──────────────────────────────────────────────────────────────────────────────── -✔ | 14 | Error model fitting [4.6s] +✔ | 14 | Error model fitting [4.7s] ✔ | 5 | Time step normalisation ✔ | 4 | Calculation of FOCUS chi2 error levels [0.5s] ✔ | 14 | Results for FOCUS D established in expertise for UBA (Ranke 2014) [0.8s] @@ -30,19 +30,19 @@ Reason: Fitting with saemix takes around 10 minutes when using deSolve ✔ | 3 | Model predictions with mkinpredict [0.3s] ✔ | 16 | Evaluations according to 2015 NAFTA guidance [1.4s] ✔ | 9 | Nonlinear mixed-effects models with nlme [8.0s] -✔ | 16 | Plotting [9.9s] +✔ | 16 | Plotting [10.1s] ✔ | 4 | Residuals extracted from mkinfit models -✔ | 25 | saemix parent models [170.8s] +✔ | 25 | saemix parent models [170.4s] ✔ | 2 | Complex test case from Schaefer et al. (2007) Piacenza paper [1.4s] ✔ | 7 | Fitting the SFORB model [3.6s] ✔ | 1 | Summaries of old mkinfit objects ✔ | 4 | Summary [0.1s] ✔ | 4 | Results for synthetic data established in expertise for UBA (Ranke 2014) [2.2s] -✔ | 9 | Hypothesis tests [8.0s] +✔ | 9 | Hypothesis tests [8.1s] ✔ | 4 | Calculation of maximum time weighted average concentrations (TWAs) [2.2s] ══ Results ═════════════════════════════════════════════════════════════════════ -Duration: 251.5 s +Duration: 252.5 s ── Skipped tests ────────────────────────────────────────────────────────────── • Fitting this ODE model with saemix takes about 15 minutes on my system (1) diff --git a/tests/testthat/_snaps/plot/mixed-model-fit-for-mmkin-object.svg b/tests/testthat/_snaps/plot/mixed-model-fit-for-mmkin-object.svg index ed0998e5..e537e697 100644 --- a/tests/testthat/_snaps/plot/mixed-model-fit-for-mmkin-object.svg +++ b/tests/testthat/_snaps/plot/mixed-model-fit-for-mmkin-object.svg @@ -51,7 +51,6 @@ - @@ -219,6 +218,7 @@ + @@ -398,7 +398,6 @@ - @@ -552,6 +551,7 @@ + diff --git a/tests/testthat/_snaps/plot/mixed-model-fit-for-nlme-object.svg b/tests/testthat/_snaps/plot/mixed-model-fit-for-nlme-object.svg index 25a5d263..051b46b1 100644 --- a/tests/testthat/_snaps/plot/mixed-model-fit-for-nlme-object.svg +++ b/tests/testthat/_snaps/plot/mixed-model-fit-for-nlme-object.svg @@ -96,7 +96,6 @@ - @@ -730,6 +729,7 @@ + diff --git a/tests/testthat/_snaps/plot/mixed-model-fit-for-saem-object-with-mkin-transformations.svg b/tests/testthat/_snaps/plot/mixed-model-fit-for-saem-object-with-mkin-transformations.svg index dc7c1e17..375ab089 100644 --- a/tests/testthat/_snaps/plot/mixed-model-fit-for-saem-object-with-mkin-transformations.svg +++ b/tests/testthat/_snaps/plot/mixed-model-fit-for-saem-object-with-mkin-transformations.svg @@ -96,7 +96,6 @@ - @@ -730,6 +729,7 @@ + @@ -1363,7 +1363,6 @@ - @@ -1931,6 +1930,7 @@ + diff --git a/tests/testthat/_snaps/plot/mixed-model-fit-for-saem-object-with-saemix-transformations.svg b/tests/testthat/_snaps/plot/mixed-model-fit-for-saem-object-with-saemix-transformations.svg index b7d3fb63..a3c4b819 100644 --- a/tests/testthat/_snaps/plot/mixed-model-fit-for-saem-object-with-saemix-transformations.svg +++ b/tests/testthat/_snaps/plot/mixed-model-fit-for-saem-object-with-saemix-transformations.svg @@ -51,7 +51,6 @@ - @@ -219,6 +218,7 @@ + @@ -398,7 +398,6 @@ - @@ -552,6 +551,7 @@ + -- cgit v1.2.1