plot_residuals: Residuals plot

View source: R/plot_residuals.R

plot_residualsR Documentation

Residuals plot

Description

Plot residuals (e.g. CWRES, IWRES, NPDE) as either a scatterplot (versus an independent variable), an histogram (distribution) or a quantile-quantile plot.

Usage

plot_residuals(
  run,
  compartment = NULL,
  idv = "TIME",
  residuals,
  absolute_residuals = FALSE,
  keep_time_zero = FALSE,
  type = "scatterplot",
  smoothing_method = NULL,
  smoothing_se = TRUE,
  reference_value = NULL,
  histogram_bins = 30L,
  histogram_empirical_density = TRUE,
  histogram_reference_distribution = list(fun = dnorm, args = list(mean = 0, sd = 1)),
  qq_reference_distribution = list(fun = qnorm, args = list(mean = 0, sd = 1)),
  x_scale = "linear",
  y_scale = "linear",
  facet_scales = "free",
  transparency = FALSE,
  auto_legend = TRUE
)

Arguments

run

pmxploit NONMEM run object.

compartment

integer vector of the numbers of the compartments of residuals.

idv

character. Name of the column used as independent variable. Default is "TIME".

residuals

character vector of column names of residuals.

absolute_residuals

logical. If TRUE residuals are transformed to absolute values.

keep_time_zero

logical. If TRUE, does not ignore values at initiation (when TIME = 0). Default is FALSE.

type

character. Type of representation of the residuals. One of scatterplot, histogram and qq (Q-Q plot of a distribution of reference). Default is scatterplot.

smoothing_method

character. ggplot2 smoothing method.

smoothing_se

logical. Display confidence interval around smooth?

reference_value

numeric. Draws reference lines at +/- a particular value.

histogram_bins

integer. If type = "histogram", sets the number of bins. Default is 30.

histogram_empirical_density

logical. If TRUE, draws the empirical density over the histogram.

histogram_reference_distribution

logical. If TRUE, draws a theoretical density over the histogram.

x_scale

character. X-axis scale, one of "linear" or "log". Default is "linear".

y_scale

character. Y-axis scale, one of "linear" or "log". Default is "linear".

facet_scales

character. ggplot2 facet scales. Default is "free".

transparency

logical. Plot scatterplot dots with transparency, useful to avoid overplotting with large datasets. Default is FALSE.

auto_legend

logical. When TRUE (default), default pmxploit plotting options are applied (title, labels, axis...).

Value

A ggplot2 object.

Examples

EXAMPLERUN %>%
  plot_residuals(compartment = 2, idv = c("TIME", "PRED"), residuals = "CWRES")

EXAMPLERUN %>%
  group_by(CMT) %>%
  plot_residuals(compartment = 2:3, idv = c("TIME", "PRED"), residuals = "CWRES")

EXAMPLERUN %>%
  plot_residuals(compartment = 2, idv = c("TIME", "PRED"),
                 residuals = "CWRES", smoothing_method = "lm")

EXAMPLERUN %>%
  plot_residuals(compartment = 2, idv = c("TIME", "PRED"),
                 residuals = "CWRES", type = "histogram")
EXAMPLERUN %>%
  plot_residuals(compartment = 2, idv = c("TIME", "PRED"),
                 residuals = "CWRES", type = "qq")

EXAMPLERUN %>%
  group_by(STUD) %>%
  plot_residuals(compartment = 2, idv = c("TIME", "PRED"),
                 residuals = "CWRES", type = "qq")

pnolain/pmxploit documentation built on Jan. 31, 2024, 1:16 p.m.