% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/sg-gof-res-dist.R
\name{sg_gof_res_dist}
\alias{sg_gof_res_dist}
\title{Plot distribution or QQ-plot of residuals from NONMEM/Simurg run}
\usage{
sg_gof_res_dist(
  fpath_i,
  res_type = "RES",
  DVID = 1,
  n_bins = 30,
  ndist = TRUE,
  plot_type = "DIST"
)
}
\arguments{
\item{fpath_i}{String or sg-fit object. If the string is given, the path to
\code{.Rdata} or \code{.json} file with sg-fit object is expected.}

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

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

\item{n_bins}{Integer. Number of bins to use in the histogram. Default is 30.}

\item{ndist}{Logical. If \code{TRUE}, overlays the corresponding normal density
curve on the histogram (default: TRUE).}

\item{plot_type}{Character. Type of plot to produce:
\itemize{
\item \code{"DIST"} (default) - histogram of individual parameters,
\item \code{"QQ"} - QQ-plot of individual parameters.
}}
}
\value{
A \code{ggplot} object.
}
\description{
This function visualizes residuals from estimation results
stored in a Simurg output object. The residuals can be plotted either as
histograms with overlaid normal density curves, or as QQ-plots to assess
normality.
}
\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")
sg_gof_res_dist(fpath_i = fpath_i, res_type = "IWRES")

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

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