Skip to contents

This function visualizes residuals from GFO $SDTAB. The residuals can be plotted either as histograms with overlaid normal density curves, or as QQ-plots to assess normality.

Usage

sg_gof_res_dist(
  fpath_i,
  res_type = "RES",
  DVID = 1,
  n_bins = 30,
  ndist = TRUE,
  plot_type = "DIST"
)

Arguments

fpath_i

String, GFO, or a named list with a GFO component (and optionally GCO). If a string is given, the path to a .RData or .json file with a fit object is expected.

res_type

Character vector. One or several types of residuals to plot. Values must correspond to column name(s) in smrg_obj$SDTAB, e.g. "RES", "IWRES", "IRES". If multiple residual types are provided, plots will be generated for each of them.

DVID

Restrict SDTAB to one observation type. Numeric values select the DVID column (default 1). If SDTAB has DVNAME, a character or factor is matched to DVNAME first; otherwise a digit-only string is coerced to numeric DVID.

n_bins

Integer. Number of bins to use in the histogram. Default is 30.

ndist

Logical. If TRUE, overlays the corresponding normal density curve on the histogram (default: TRUE).

plot_type

Character. Type of plot to produce:

  • "DIST" (default) - histogram of individual parameters,

  • "QQ" - QQ-plot of individual parameters.

Value

A ggplot object.

Examples

# Plot the distribution of individual weighted residuals (IWRES)
# (default \code{DVID = 1}; pass \code{DVID} or a \code{DVNAME} string to select another endpoint)
fpath_i <- system.file("extdata", "simurg_object", "Warfarin_PK.RData",
                        package = "SimuRg")
p <- sg_gof_res_dist(fpath_i = fpath_i, res_type = "IWRES")
p
#> Warning: The dot-dot notation (`..density..`) was deprecated in ggplot2 3.4.0.
#>  Please use `after_stat(density)` instead.
#>  The deprecated feature was likely used in the SimuRg package.
#>   Please report the issue at <https://github.com/ms-decisions/SimuRg/issues>.


# QQ-plots for the same default endpoint
p <- sg_gof_res_dist(fpath_i = fpath_i, res_type = "RES", plot_type = "QQ")
p


# Several residual columns at once (still one \code{DVID} unless you change it)
p <- sg_gof_res_dist(fpath_i = fpath_i, res_type = c("IWRES", "IRES"))
p