% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/sg-gof-obpr.R
\name{sg_gof_obpr}
\alias{sg_gof_obpr}
\title{Observed vs predicted plot}
\usage{
sg_gof_obpr(
  fpath_i,
  DVID = 1,
  cov_cols = NULL,
  indiv = TRUE,
  addline = TRUE,
  alpha_i = 0.5,
  smooth = TRUE,
  log_axes = FALSE,
  sc_factor = 1,
  abreaks = scales::pretty_breaks(7),
  lab_x = "Model-predicted values",
  lab_y = "Observed values",
  col_i = NULL,
  col_lab = NULL,
  facet_i = NULL,
  f_scales = "fixed",
  no_leg = FALSE,
  n_quantiles = 3,
  levels_discrete = 10
)
}
\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{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{cov_cols}{A character vector specifying the names of the columns with covariates.}

\item{indiv}{Logical. If \code{TRUE}, use individual predictions (\code{"IPRED"});
otherwise use population predictions (\code{"PRED"}). Default is \code{TRUE}.}

\item{addline}{Logical. If \code{TRUE}, lines connecting observations of
individual subjects will be added. Default is \code{TRUE}.}

\item{alpha_i}{Numeric. Transparency level (from 0 to 1) for points/lines.
Default is 0.5.}

\item{smooth}{Logical. Add LOESS smooth line. Default is \code{TRUE}.}

\item{log_axes}{Logical. If \code{TRUE}, a logarithmic scale is applied to all axes. Default is \code{FALSE}.}

\item{sc_factor}{Numeric. Scaling factor for DV/PRED/IPRED values. Default is 1 (no scaling).}

\item{abreaks}{A function that generates axis breaks. Default is \code{scales::pretty_breaks(7)}.}

\item{lab_x}{X-axis label. Default "Model-predicted values"}

\item{lab_y}{Y-axis label. Default "Observed values"}

\item{col_i}{String. Column name for color}

\item{col_lab}{String. Label for color legend}

\item{facet_i}{String. Column name for facet}

\item{f_scales}{String, one of \code{"fixed"}, \code{"free"}, \code{"free_x"}, \code{"free_y"}. User can specify whether the scales (x and y axes) should be fixed across all panels (\code{"fixed"}), free for each panel (\code{"free"}), or free only in one dimension (\code{"free_x"} or \code{"free_y"}). Default is \code{"fixed"}}

\item{no_leg}{Logical. If \code{TRUE}, the legend is not shown. Default is \code{FALSE}}

\item{n_quantiles}{Integer. Number of quantile groups for continuous variables in \code{col_i}. Default is 3.}

\item{levels_discrete}{Integer. Maximum unique values to consider a variable discrete. Default is 10.}
}
\value{
A ggplot2 object
}
\description{
Function generates observed versus predicted (OBS vs PRED/IPRED) scatter plots,
a fundamental goodness-of-fit diagnostic tool in pharmacometric modeling.
This visualization assesses model adequacy by comparing observed clinical measurements against model-predicted values,
enabling identification of systematic bias, heteroscedasticity, and model misspecification patterns.
Function contains options for faceting, coloring by covariates, and trend lines.
}
\examples{
\donttest{
# Basic example with mock data
set.seed(123)  # For reproducibility
mock_obj <- list(
 SDTAB = data.frame(
   ID = rep(1:3, each = 5),
   TIME = rep(c(0, 1, 2, 4, 8), 3),
   DV = rnorm(15, mean = 10, sd = 2),
   PRED = rnorm(15, mean = 10, sd = 1.5),
   IPRED = rnorm(15, mean = 10, sd = 1.2),
   MDV = rep(0, 15)
 ),
 COTAB = data.frame(ID = 1:3, AGE = c(30, 45, 60)),
 CATAB = data.frame(ID = 1:3, RACE = c("Hispanic", "Hispanic", "Asian"))
)

# Basic plot
p <- sg_gof_obpr(mock_obj)

# With covariates and faceting
p <- sg_gof_obpr(
  mock_obj,
  cov_cols = "RACE",
  col_i = "RACE",
  facet_i = "RACE"
)
}

}
