@@ -55,6 +55,7 @@
Loading
55 55
#' print(f_nlme_dfop)
56 56
#' plot(f_nlme_dfop)
57 57
#' endpoints(f_nlme_dfop)
58 +
#'
58 59
#' \dontrun{
59 60
#'   f_nlme_2 <- nlme(f["SFO", ], start = c(parent_0 = 100, log_k_parent = 0.1))
60 61
#'   update(f_nlme_2, random = parent_0 ~ 1)
@@ -101,6 +102,7 @@
Loading
101 102
#'     AIC(f_nlme_sfo, f_nlme_sfo_tc, f_nlme_dfop, f_nlme_dfop_tc)
102 103
#'     print(f_nlme_dfop_tc)
103 104
#'   }
105 +
#'
104 106
#'   f_2_obs <- mmkin(list("SFO-SFO" = m_sfo_sfo,
105 107
#'    "DFOP-SFO" = m_dfop_sfo),
106 108
#'     ds_2, quiet = TRUE, error_model = "obs")

@@ -48,8 +48,12 @@
Loading
48 48
#'   start = mean_dp)
49 49
#' summary(m_nlme)
50 50
#' plot(augPred(m_nlme, level = 0:1), layout = c(3, 1))
51 -
#' # augPred does not seem to work on fits with more than one state
51 +
#' # augPred does not work on fits with more than one state
52 52
#' # variable
53 +
#' #
54 +
#' # The procedure is greatly simplified by the nlme.mmkin function
55 +
#' f_nlme <- nlme(f)
56 +
#' plot(f_nlme)
53 57
#'
54 58
#' @return A function that can be used with nlme
55 59
#' @export

@@ -5,11 +5,10 @@
Loading
5 5
#' @param x An object of class \code{\link{nlme.mmkin}}
6 6
#' @param i A numeric index to select datasets for which to plot the nlme fit,
7 7
#'   in case plots get too large
8 -
#' @param main The main title placed on the outer margin of the plot.
9 8
#' @inheritParams plot.mkinfit
10 -
#' @param legends An index for the fits for which legends should be shown.
11 9
#' @param standardized Should the residuals be standardized? Only takes effect if
12 10
#'   `resplot = "time"`.
11 +
#' @param rel.height.legend The relative height of the legend shown on top
13 12
#' @param rel.height.bottom The relative height of the bottom plot row
14 13
#' @param ymax Vector of maximum y axis values
15 14
#' @param \dots Further arguments passed to \code{\link{plot.mkinfit}} and
@@ -31,6 +30,7 @@
Loading
31 30
#'   A1 = mkinsub("SFO"), quiet = TRUE)
32 31
#' f <- mmkin(list("DFOP-SFO" = dfop_sfo), ds, quiet = TRUE, cores = 1)
33 32
#' plot(f[, 3:4], standardized = TRUE)
33 +
#'
34 34
#' library(nlme)
35 35
#' # For this fit we need to increase pnlsMaxiter, and we increase the
36 36
#' # tolerance in order to speed up the fit for this example evaluation
@@ -38,15 +38,15 @@
Loading
38 38
#' plot(f_nlme)
39 39
#' @export
40 40
plot.nlme.mmkin <- function(x, i = 1:ncol(x$mmkin_orig),
41 -
  main = NULL,
42 41
  obs_vars = names(x$mkinmod$map),
43 42
  standardized = TRUE,
44 43
  xlab = "Time",
45 44
  xlim = range(x$data$time),
46 -
  legends = 1,
47 -
  lpos = "topright", inset = c(0.05, 0.05),
48 45
  resplot = c("predicted", "time"),
49 46
  ymax = "auto", maxabs = "auto",
47 +
  ncol.legend = ifelse(length(i) <= 3, length(i) + 1, ifelse(length(i) <= 8, 3, 4)),
48 +
  nrow.legend = ceiling((length(i) + 1) / ncol.legend),
49 +
  rel.height.legend = 0.03 + 0.08 * nrow.legend,
50 50
  rel.height.bottom = 1.1,
51 51
  pch_ds = 1:length(i),
52 52
  col_ds = pch_ds + 1,
@@ -65,7 +65,7 @@
Loading
65 65
  names(degparms_fixed) <- rownames(fit_1$fixed)
66 66
  degparms_all <- cbind(as.matrix(degparms_optim),
67 67
    matrix(rep(degparms_fixed, nrow(degparms_optim)),
68 -
      ncol = length(degparms_fixed), 
68 +
      ncol = length(degparms_fixed),
69 69
      nrow = nrow(degparms_optim), byrow = TRUE))
70 70
  degparms_all_names <- c(degparms_optim_names, names(degparms_fixed))
71 71
  colnames(degparms_all) <- degparms_all_names
@@ -81,14 +81,27 @@
Loading
81 81
  n_plot_rows = length(obs_vars)
82 82
  n_plots = n_plot_rows * 2
83 83
84 -
  # Set relative plot heights, so the first and the last plot are the norm
85 -
  # and the middle plots (if n_plot_rows >2) are smaller by rel.height.middle
86 -
  rel.heights <- if (n_plot_rows > 1) c(rep(1, n_plot_rows - 1), rel.height.bottom) else 1
84 +
  # Set relative plot heights, so the first plot row is the norm
85 +
  rel.heights <- if (n_plot_rows > 1) {
86 +
    c(rel.height.legend, c(rep(1, n_plot_rows - 1), rel.height.bottom))
87 +
  } else {
88 +
    c(rel.height.legend, 1)
89 +
  }
87 90
88 -
  layout_matrix = matrix(1:n_plots,
89 -
    n_plot_rows, 2, byrow = TRUE)
91 +
  layout_matrix = matrix(c(1, 1, 2:(n_plots + 1)),
92 +
    n_plot_rows + 1, 2, byrow = TRUE)
90 93
  layout(layout_matrix, heights = rel.heights)
91 94
95 +
  par(mar = c(0.1, 2.1, 0.6, 2.1))
96 +
97 +
  plot(0, type = "n", axes = FALSE, ann = FALSE)
98 +
  legend("center", bty = "n", ncol = ncol.legend,
99 +
    legend = c("Population", ds_names[i]),
100 +
    lty = c(1, lty_ds), lwd = c(2, rep(1, length(i))),
101 +
    col = c(1, col_ds),
102 +
    pch = c(NA, pch_ds))
103 +
104 +
92 105
  solution_type = fit_1$solution_type
93 106
94 107
  outtimes <- sort(unique(c(x$data$time,
@@ -96,6 +109,7 @@
Loading
96 109
97 110
  pred_ds <- purrr::map_dfr(i, function(ds_i)   {
98 111
    odeparms_trans <- degparms_all[ds_i, odeparms_names]
112 +
    names(odeparms_trans) <- odeparms_names # needed if only one odeparm
99 113
    odeparms <- backtransform_odeparms(odeparms_trans,
100 114
      x$mkinmod,
101 115
      transform_rates = fit_1$transform_rates,
@@ -162,14 +176,6 @@
Loading
162 176
        col = col_ds[ds_i], lty = lty_ds[ds_i])
163 177
    }
164 178
165 -
    if (plot_row %in% legends) {
166 -
      legend(lpos, inset = inset,
167 -
        legend = c("Population", ds_names[i]),
168 -
        lty = c(1, lty_ds), lwd = c(2, rep(1, length(i))),
169 -
        col = c(1, col_ds),
170 -
        pch = c(NA, pch_ds))
171 -
    }
172 -
173 179
    if (identical(maxabs, "auto")) {
174 180
      maxabs = max(abs(observed_row$residual), na.rm = TRUE)
175 181
    }
@@ -194,6 +200,8 @@
Loading
194 200
        ylim = c(-1.2 * maxabs, 1.2 * maxabs),
195 201
        ylab = if (standardized) "Standardized residual" else "Residual")
196 202
203 +
      abline(h = 0, lty = 2)
204 +
197 205
      for (ds_i in seq_along(i)) {
198 206
        observed_row_ds <- merge(
199 207
          subset(observed_row, ds == ds_names[ds_i], c("time", "residual")),
Files Coverage
R 83.80%
Project Totals (39 files) 83.80%
Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading