Tutorials › Pharmacometric Workflows and Reproducible Modeling › Workshop: Assemble a Complete Diagnostic Report

Automating Diagnostics and Reports · Tutorial 316 of 399

Workshop: Assemble a Complete Diagnostic Report

Learn to turn aligned model predictions and residuals into a coherent diagnostic report, and verify that its summaries, plots, captions, and rendered files agree.

Intermediate 12 min read

What You'll Learn

  • Specify the observation-level inputs and checks needed before report generation.
  • Distinguish population predictions and residuals from individual predictions and residuals.
  • Calculate and report residual summaries with correct denominators, signs, and units.
  • Organize population and individual diagnostic plots with linked captions and tables.
  • Check rendered HTML or PDF output for missing, inconsistent, or misleading content.

From Diagnostic Outputs to a Complete Report

A diagnostic report is more than a collection of plots. It is a set of connected evidence: the plots and tables must describe the same analysis population, the captions must identify the quantities shown, and the rendered document must preserve the intended content. A report can look polished and still mislead if, for example, its population plot uses one set of records while its summary table uses another.

This workshop turns standardized prediction and residual outputs into a complete diagnostic report. The focus is on assembling and checking the report, not on making a model decision from any single diagnostic. The earlier material on automated diagnostic summaries provides context for the numerical summaries used here.

Definition: A population prediction, denoted PRED here, is the model-predicted observation without conditioning on an individual’s estimated random effects. An individual prediction, denoted IPRED, is the model-predicted observation conditional on those individual estimates. A raw residual is the observed value minus its corresponding prediction: \(DV-PRED\) or \(DV-IPRED\). A standardized residual, such as CWRES, is a residual transformed using an estimated residual-error structure; its exact definition and sign convention must be taken from the generating software and analysis specification.

Before assembling a report, establish what one row represents and which columns are required. For the examples below, each row is one included observation, DV and predictions are concentrations in mg/L, and CWRES is dimensionless. The raw residual convention is observed minus predicted. A report pipeline must preserve the subject and time identifiers as well as these quantities so that plots, summaries, and individual panels can be joined to the correct records.

The workflow also assumes that the predictions and residuals come from the same model run and analysis population, and that their records are aligned to the observations they describe. Numerical summaries below are descriptive and do not require normally distributed residuals. However, interpreting a standardized residual against a reference distribution does depend on how it was constructed and on the model and error assumptions behind that construction. State those assumptions rather than treating every standardized residual as interchangeable.

Prepare and Validate the Report Inputs

Use one standardized observation-level data set as the report’s source for plots and summaries. At a minimum, retain an analysis identifier, subject identifier, time, DV, PRED, IPRED, and any standardized residuals to be displayed. Keep units, transformations, prediction definitions, and residual sign conventions in report metadata rather than relying on a reader to infer them from column names.

Before plotting, check that the expected records are present, identifiers and times are usable, values have compatible units, and each output is matched to the intended observation. Count missing values by quantity: a missing CWRES need not remove a row from a DV-versus-IPRED plot, but it must not silently enter a CWRES summary as if it were observed. If different displays use different eligible record counts, state those counts.

Worked Example: Confirming the Input Record Set

Suppose a hypothetical report uses observations from subjects A, B, and C, with two scheduled observations per subject. The standardized input has six rows. For the first row, DV is 2.0 mg/L, PRED is 2.2 mg/L, and IPRED is 2.0 mg/L. Check the expected record count and calculate both raw residuals for that row.

There are three subjects with two observations each, so the expected total is \(3\times2=6\) rows. If the input contains six unique subject-time records and all six have DV, PRED, IPRED, and CWRES, it meets the basic completeness check for the planned displays. This check does not prove that the records are scientifically correct, but a mismatch would flag an input or filtering problem to resolve before rendering.

Using observed minus predicted, the population residual is \(2.0-2.2=-0.2\) mg/L, and the individual residual is \(2.0-2.0=0.0\) mg/L. The sign is meaningful: the observation is 0.2 mg/L below PRED and exactly equals IPRED. The report should use this same sign convention in its labels and tables.

Build Plots and Summaries From a Shared Source

A complete diagnostic report typically combines population-level views with subject-level views. A population plot can show DV against PRED, while residual plots can show a standardized residual against PRED or time. Individual panels commonly show DV and IPRED over time for each subject; if the report also shows PRED, distinguish its line or symbol clearly. The axes, units, transformations, and inclusion rules should be explicit. Plot limits should preserve relevant patterns rather than clipping observations.

Summary tables should identify the quantity, record count, units where applicable, and statistic definitions. For raw residuals \(e_i=DV_i-PRED_i\), the mean residual describes average signed discrepancy, while the root mean squared error (RMSE) summarizes squared discrepancies on the original measurement scale:

$$ \bar{e}=\frac{1}{n}\sum_{i=1}^{n}e_i,\qquad RMSE=\sqrt{\frac{1}{n}\sum_{i=1}^{n}e_i^2}. $$

Here \(n\) is the number of eligible records for that particular quantity. RMSE is nonnegative and has the same units as the residual. It is not the sample standard deviation: it incorporates both spread and any nonzero mean residual.

Worked Example: Calculating Residual Summaries Correctly

For six hypothetical observations, suppose the values of \(DV-IPRED\), in mg/L, are \(0,-1,1,0,-0.5,0\). Calculate the mean individual residual and its RMSE.

The signed residuals sum to \(0-1+1+0-0.5+0=-0.5\) mg/L. Thus the mean is \(\bar{e}=(-0.5)/6=-0.0833\) mg/L. The squared residuals sum to \(0^2+(-1)^2+1^2+0^2+(-0.5)^2+0^2=2.25\) (mg/L)\(^2\). Therefore \(RMSE=\sqrt{2.25/6}=\sqrt{0.375}=0.612\) mg/L.

The mean is slightly negative, not zero; the residuals are not all zero. RMSE is larger than the absolute mean because it also reflects the nonzero residuals in the set. Reporting both quantities preserves information that either statistic alone would omit.

A short identity explains why the two summaries answer different questions. Write each residual as \(e_i=(e_i-\bar{e})+\bar{e}\). On squaring and summing, the cross-product terms sum to zero because \(\sum_i(e_i-\bar{e})=0\). Dividing by \(n\) gives:

$$ \frac{1}{n}\sum_{i=1}^{n}e_i^2 = \frac{1}{n}\sum_{i=1}^{n}(e_i-\bar{e})^2+\bar{e}^{\,2}. $$

Thus the mean squared residual combines the average squared deviation around the mean with the squared mean itself. Taking its square root gives RMSE. This is why a report should not label RMSE as “residual variability” alone or substitute the signed mean for an overall error-size summary.

Worked Example: Assemble a Consistent Population Summary

Consider this hypothetical set of six observations, all with complete values. The population residuals \(DV-PRED\), in mg/L, are \(-0.2,-0.5,0.4,-0.2,-0.3,0.3\). Calculate the mean population residual and RMSE to enter in the report table.

The residual sum is \(-0.2-0.5+0.4-0.2-0.3+0.3=-0.5\) mg/L, so the mean is \(-0.5/6=-0.0833\) mg/L. The squared residual sum is \(0.04+0.25+0.16+0.04+0.09+0.09=0.67\) (mg/L)\(^2\). Therefore \(RMSE=\sqrt{0.67/6}=\sqrt{0.1117}=0.334\) mg/L, to three significant figures.

A suitable table entry is “Population residual, \(DV-PRED\): \(n=6\), mean \(-0.0833\) mg/L, RMSE \(0.334\) mg/L.” The table should not imply that these values summarize CWRES, which is standardized and dimensionless, or the individual residuals, which use IPRED instead of PRED.

Assemble Captions, Tables, and Rendered Output

A caption should say what is plotted, the population or record set included, and any essential display choices. Captions generated from metadata are more reliable than hand-written captions copied between analyses, provided the metadata are correct. For example, “Observed concentration (DV, mg/L) versus population prediction (PRED, mg/L); six observations from three hypothetical subjects” identifies both variables, units, and scope. A corresponding CWRES caption should say that CWRES is dimensionless and identify its horizontal variable.

Organize report sections so readers can move from analysis context and record counts to population plots, individual plots, summary tables, and a concise data-linked narrative. The narrative should report what the generated summaries and displays show, without turning a descriptive pattern into a causal claim or an unsupported model conclusion. The report’s source data and metadata should drive the values and captions together. HTML and PDF may differ in pagination or navigation, but should not disagree in analysis content.

Worked Example: Check a Report Before Release

A hypothetical report is generated for the six observations above. The planned output contains one DV-versus-PRED population panel, two population CWRES panels (against PRED and time), and one individual plot for each of the three subjects. Determine the expected number of plot panels and write a suitable caption for the population prediction panel.

The expected panel count is \(1+2+3=6\): one population prediction panel, two population residual panels, and three individual panels. The report contents should identify all six panels. If the rendered PDF contains only five, inspect whether a panel was omitted or whether pagination concealed it; do not assume that a successful render means every requested plot was included.

A suitable caption is: “Observed concentration (DV, mg/L) versus population prediction (PRED, mg/L), six observations from three hypothetical subjects.” Before release, check that the plotted points correspond to the same six records used in the population residual summary, that the caption units match the axes, and that the HTML and PDF both contain the six expected panels and the table values calculated above.

1
Freeze the report inputs.
Record the analysis identifier, observation population, prediction and residual definitions, units, and any inclusion rules used for the output.
2
Validate the records.
Check row counts, subject-time alignment, required fields, units, and missingness. Keep display-specific eligible counts where they differ.
3
Generate linked content.
Build population and individual plots, summary tables, captions, and narrative from the same standardized data and metadata.
4
Render and inspect.
Open the HTML or PDF and verify completeness, legibility, labels, units, panel counts, table values, and agreement between displayed content and source outputs.

Diagnostics, Alternatives, and Limitations

Useful report-generation checks include reconciling the number of observations in the input, plots, and tables; confirming that each subject panel is present; checking for duplicated or unexpected subject-time records; and verifying that captions and axes describe the same variables and units. Examine warnings and missing-value handling explicitly. A plot with no visible points may be a valid result, an empty filtered subset, or a rendering failure; the report should not silently treat these possibilities as equivalent.

A common mistake is to see a successful HTML or PDF render and conclude that the report is complete and numerically correct. Rendering confirms that a document was produced, not that it contains every intended figure or that its summaries used the right rows. The correction is to add explicit checks—such as expected record and panel counts—and compare key table entries with calculations from the standardized input. Another frequent error is to compare a raw residual in mg/L with a standardized residual as if they were on the same scale. Keep their labels, units, and interpretations distinct.

A scripted, metadata-driven report is generally more reproducible than manually assembling plots and captions in a spreadsheet or document editor: it reduces repeated transcription and makes consistent updates easier. Manual assembly can be useful for a small exploratory review, but it is more vulnerable to stale captions, inconsistent filters, and copy-and-paste errors. HTML is convenient for navigation and screen viewing; PDF is useful for stable pagination and printing. Neither format guarantees content accuracy, so the choice of format does not replace input and render checks.

Automation also has limits. A report template cannot determine whether the model, analysis population, or residual definition is scientifically appropriate, and a summary table cannot replace inspection of the diagnostic plots. A misleading input can produce a consistent-looking but misleading report. Treat report generation as a controlled transformation of defined outputs, and preserve the definitions and eligible counts needed to interpret each display.

Check Your Understanding

Answer each question, then compare with the solutions.

  1. If a report has four subjects with three observations each, how many observation-level rows are expected? What should be checked if the input has 11 rows?
  2. For raw residuals \(0.2,-0.2,0.4\) mg/L, calculate the mean residual and RMSE.
  3. Why should a report identify whether its residual is \(DV-PRED\) or \(DV-IPRED\)?
  4. A CWRES value is missing for one observation, but its DV and IPRED are present. Must that observation be omitted from every report display?

Solutions. (1) The expected count is \(4\times3=12\) rows. With 11 rows, check the observation selection, missing records, duplicate records, and any documented filtering before generating the report. (2) The mean is \((0.2-0.2+0.4)/3=0.133\) mg/L. The squared sum is \(0.04+0.04+0.16=0.24\) (mg/L)\(^2\), so \(RMSE=\sqrt{0.24/3}=\sqrt{0.08}=0.283\) mg/L. (3) PRED and IPRED are different predictions, so their residuals can differ in value and meaning; the formula and sign convention make the table interpretable and reproducible. (4) No. It may remain in a DV-versus-IPRED display, while being excluded from a CWRES display and summary. Report the eligible count for each quantity and do not impute a CWRES without a defined method.

Clinical Biostats