library(tidyverse)
library(nlmixr2)
library(nlmixr2data)
library(ggPMX)Model Diagnostics
Module goal: Learn how to evaluate whether a fitted population PK model is adequate for its intended purpose.
Module Overview
In earlier modules, we built the main pieces of a population PK model.
We learned how to:
- define structural PK assumptions
- estimate model parameters
- represent variability
- add covariate effects
- interpret predictions and residuals
Now we move from model building to model evaluation.
A model is not useful simply because it runs.
After fitting, we need to ask:
- Do predictions agree with observations?
- Are residuals centered around zero?
- Do residuals show trends over time or prediction magnitude?
- Does the model reproduce observed variability?
- Do covariate and variability assumptions behave reasonably?
- Is the model adequate for the current question?
This module introduces the diagnostic thinking needed to evaluate population PK models.
Learning Objectives
By the end of this module, you will be able to:
- explain why diagnostics are essential after model building
- distinguish convergence from model adequacy
- create basic goodness-of-fit plots
- interpret observed versus predicted plots
- inspect residual patterns over time and prediction magnitude
- distinguish population and individual diagnostic views
- understand the purpose of visual predictive checks
- recognize parameter precision as part of model evaluation
- decide whether a model is adequate for a specific purpose
Lessons in This Module
Lesson 1: Why Model Diagnostics Matter
This lesson introduces the purpose of diagnostics and explains why convergence is not enough.
Diagnostics evaluate whether model assumptions behave reasonably after fitting.
Lesson 2: Goodness-of-Fit Plots
This lesson creates and interprets core plots such as observed versus population prediction and observed versus individual prediction.
Lesson 3: Residual Diagnostics
This lesson examines residual patterns using variables such as RES, IRES, WRES, IWRES, and CWRES.
Lesson 4: Visual Predictive Checks
This lesson introduces VPC concepts and shows how simulations help evaluate whether the model reproduces observed central tendency and variability.
Lesson 5: Parameter Precision and Model Qualification
This lesson introduces practical model qualification, parameter precision, and how to communicate whether a model is adequate for its intended use.
Software Used
This module continues using nlmixr2 and introduces diagnostic-support packages.
We will use simple ggplot2 code when it helps explain diagnostic concepts.
We will also use ggPMX for standardized pharmacometric diagnostic visualizations.
Dataset Used
We continue with:
data("theo_sd", package = "nlmixr2data")Keeping the same dataset and model helps us focus on interpretation rather than switching contexts.
Module Workflow
Conceptually, this module follows:
Structural Model
↓
Population Model
↓
Variability
↓
Covariates
↓
Predictions
↓
Residuals
↓
Diagnostics
↓
Model Qualification
This is the evaluation phase of the population modeling workflow.
How This Module Connects to Previous Modules
Previous modules answered:
Can we build and estimate the model?
and:
Can we describe and explain variability?
This module asks:
Is the fitted model useful?
This distinction matters.
A model can converge and still be inadequate.
Diagnostics help reveal whether the model:
- captures central tendency
- represents variability reasonably
- avoids systematic bias
- supports the intended decision
What This Module Does Not Do Yet
This module does not focus on:
- new covariate model building
- forward inclusion or backward elimination
- dose optimization
- PK/PD response modeling
Those topics belong elsewhere.
Here, the focus is model evaluation.
Expected Outputs
By the end of this module, you should have:
- generated core goodness-of-fit plots
- inspected residual patterns
- interpreted prediction quality
- understood the purpose of VPCs
- described model adequacy in practical terms
- connected diagnostics to model qualification
Next Step
Start with Lesson 1 to understand why diagnostics are essential after model fitting.