Understanding Nonlinear Mixed Effects Modeling for Population Pharmacokinetics
Overview
This shows how 'NONMEM' (Beal SL, Sheiner LB, Boeckmann AJ, Bauer RJ. NONMEM 7.5 Users Guides. Icon plc, 2020) software works. 'NONMEM' classical estimation methods such as 'First Order (FO) approximation', 'First Order Conditional Estimation (FOCE)', and 'Laplacian approximation' are explained. Functions are also provided for post-run processing of NONMEM output files, generating PDF or Markdown diagnostic reports including objective function value analysis, parameter estimates, prediction and residual diagnostics, empirical Bayes estimate (EBE) analysis, input data summary, and individual pharmacokinetic parameter distributions. Helper utilities for building NONMEM-ready datasets from SDTM-style source tables are also included.
- Requires
simPDF0.1.2. Report generation could stop with "attempt to apply non-function" when a block's height equalled the space left on the page to within floating-point error; that was a defect insimPDF0.1.1, fixed in 0.1.2, and the report writer now relies on the fix instead of working around it. - The eight diagnostic report functions and
nmw_run()gain aformatargument:"pdf"(default),"md", orc("pdf", "md"). With"md"the report is written as a Markdown file (thefilename with its extension replaced by.md): headings, text, preformatted dumps and tables become GitHub-flavoured Markdown, and every figure page or inline plot is saved as an SVG file (or PNG withfig_format = "png") in a sibling<name>_filesdirectory and linked from the Markdown. The directory is emptied before each run. Outline()gainsTarget = "md": the model development flow diagram is written as a Markdown file (file, default<MDLName>-Model-Flow.md) with the diagram as an SVG (or PNG,fig_format) figure followed by the table of runs fromSumOut(). The figure is sized to the tree (about 1.6 in per leaf column), so folders with dozens of sibling runs stay legible. The defaultTarget = "PDF"still draws on the graphics device opened by the caller, as before; when no device is open (e.g. underRscript) it now writes a PDF sized to the tree instead of failing.SumOut()no longer aborts on a run folder it cannot summarise (e.g. the empty.extof a simulation run, or a corrupt output file): the run is listed withReason = "NOESTIMATION"or"UNREADABLE"and a warning names it, andGetEstMethod()returnsNAfor an empty.ext.- The report functions now describe their content with a small internal block layer (
R/report_writer.R) that is rendered tosimPDFfor the PDF and to Markdown for the.md. The statistics and the PDF layout are unchanged. - Fixed: headings of blocks that
nmw_report_resid()andnmw_report_ebe()build in loops showed the last loop value in the PDF, becausesimPDF::block_para()evaluates its text lazily. In 0.5.x all three residual-count sections ofS4-Residuals.PDFwere titled "IWRES" and all extreme-value tables "Extreme IWRES values", and inS5-EBE.PDFevery matrix in "Estimation vs EBE" was titled "Ratios of Cor(EBE)/(Cor from OM)" and every ETA section "ETA <last>". The new block layer evaluates text when the block is built. - Fixed:
nmw_report_indipk()drew its "Individual PK Parameters" heading and the first rows of the table onto the last figure page, where they were invisible, and only the overflow rows reached a fresh page. Flowing text that follows figure pages now always starts on a new page. The report also gained a title page ("Summary C - Individual PK Parameters"), likeS3-Predictions.PDF. nmw_report_ebe()drops continuous covariates whose per-subject values are all equal (for example nominal time, day or occasion counters that start at the same value for every subject) from the covariate/EBE correlation matrix, the regressions and the ETA-vs-covariate panels. They produced all-NArows and columns and flat panels.nmw_report_param()recognises runs without a successful$COVstep (no<nm:thetase>in the XML): SE, LL, UL, ZERO and ONE are reported asNAwith an explanatory note, fixed thetas are identified from the.extfixed-parameter row, and the Omega SE/RSE matrices are replaced by a note. Previously such runs showed SE = 0 for every theta and RSE of about 1e+12 for every omega. With a$COVstep, fixed or structurally zero Omega elements are now shown asNAin the SE and RSE matrices instead of 1e+10 and Inf.nmw_report_ebe()showsNAinstead of +/-Inf in the "Ratios of Cov(EBE)/OM" and "Ratios of Cor(EBE)/(Cor from OM)" matrices where the Omega element is zero, and in the individual RSE column where an ETA is exactly zero (e.g. an inter-occasion ETA of an absent occasion).- Robustness fixes found by regenerating the reports for several hundred real runs: the ETA distribution panels no longer fail when an ETA has fewer than two non-zero values (e.g. an inter-occasion ETA in a single-occasion sensitivity run) or is constant; the pairs-plot panels restore
par("usr")correctly (they emitted "argument 1 does not name a graphical parameter" on every S5 report); TAB characters in preformatted text (e.g. thesummary.lmR-squared line) are expanded to spaces instead of triggering "font width unknown" warnings; and large matrices or tables are no longer forced onto one page with their heading, which overflowed the page for models with many ETAs and covariates. - Data sets of
$PREDmodels that lackMDVand/orAMT(for example the bundled theophylline examples) no longer make S1, S3, S4, S5 and SA fail with "undefined columns selected" or "subscript out of bounds": the missing items are added with NONMEM's implicit values (AMT = 0;MDV = 1for dosing records, otherwise 0), ansdtabwithoutMDVorCMTtakes them from the record-aligned data set, and SA-Input notes which items were assumed and skips the "Individuals with no dosing" check when the data set has noAMT. ETAs that are zero for every subject are omitted from the covariate/EBE correlation matrix with a note instead of producing all-NArows. The EBE regression no longer fails when there is exactly one covariate (RemoveNA()now keeps a one-column input as a data frame and accepts plain vectors). nmw_report_ebe()writes a short report stating that no empirical Bayes estimates are available when all ETAs in the.phifile are zero (First Order estimation) andpatabis missing or also all zero, instead of failing.
Show all changes in 0.6.0Hide the rest of the changes in 0.6.0
- Text that is not valid UTF-8, such as control-stream comments in a legacy code page that NONMEM echoes into
PRINT.OUT, no longer crashes R when drawn on the PDF device: it is converted from the code page ingetOption("nmw.codepage")(default"CP949") when that yields valid text, otherwise the offending bytes are shown as<xx>. IPREis optional insdtab(e.g. a PD model withoutIPREDin$TABLE): S3-Predictions omits the IPRE panels and curves with a note, and S4-Residuals plots CWRES and IWRES against PRED.IPRED,IWRESandCWRESIare accepted forIPRE,IWREandCWRES. The influence-diagnostic panels of S5-EBE skip non-finite values instead of failing onylim. A malformed table file (e.g. one containing merge-conflict markers) is reported by name.- Worked around a
simPDF(<= 0.1.1) edge case in which a block whose height equals the remaining page space up to floating-point error made the flow fail with "attempt to apply non-function" after the block had been drawn; the report writer now places blocks one at a time and continues. - Missing run files now give a clear error naming the file, the run directory and the report that needs it (e.g.
patabfor SC-IndiPK,sdtabfor S3/S4/S5,FDATA.CSVfor the data-based reports) instead of "cannot open the connection".FDATA.csvis accepted as well asFDATA.CSVon case-sensitive file systems. nmw_report_pred()andnmw_report_indipk()no longer open a graphics device (Rplots.pdfunderRscript) when none is open: the caller'spar()state is saved and restored only if a device exists.- Tables of individuals always carry an explicit
IDcolumn: the "Individual Statistics", "Individuals with no dosing" and "Individuals with no DV" tables of SA-Input (previously the ID was the row name, which was dropped when the IDs were 1..n), the "Variable Statistics" table gains aVariablecolumn, and SC-IndiPK takes the subject IDs from the record-aligned data set whenpatabwas written withoutID. - The invisible return value of every report function now also contains
md_fileandfigures;fileandpagesareNAwhen no PDF was requested.
From inst/NEWS.Rd in the release
Install
Health
- OK13 OK2026-08-05
- NOTE12 OK, 1 NOTE2026-08-01
- OK13 OK2026-06-09
- NOTE12 OK, 1 NOTE2026-06-08
- OK14 OK2026-03-10
Documentation
- Help pages
- 109 (52 internal)includes a package overview page
- Examples that run
- 43%3 run in a plain check · 1 never run · 3 hold no code
- Exported functions with examples
- 10%
- Documented parameters
- 100%
- Return-value docs
- 90%
- Help pages citing references
- 6%
Downloads
Dependencies
Installing nmw adds 2 packages (0 with compiled code, 121 KB of source tarballs). Heaviest: numDeriv 74 KB, simPDF 47 KB.
Code & Tests
Datasets
People & History
Pick two releases to compare their code metrics.
- 0.6.0Latest
- 0.5.12026-06-09 · diff ↗ ·
removed 5 exports
AddPage, ClosePDF, PrepPDF, PrinMTxt, PrinTxtadded 2 exports
ctl2nmw, e - 0.3.12026-06-09 · diff ↗
- 0.3.02026-05-08 · diff ↗ ·
added 12 exports
add_crcl_cg, build_dose_records, build_nm_dataset, build_obs_records, code_race, code_sex, crcl_cg, dat2_time_to_posix, locf_value, merge_cov_locf, nm_to_molar, parse_dtc - RR 4.6.0 released · 2026-04-24
- 0.2.02026-04-07 · diff ↗ ·
removed 1 export
pattern:^[[:alpha:]]+added 65 exports
AddCox, CalcSmat, CombDmExPc, CovStep, DECN, DesclVar, EstStep, InitStep, Mx, Obj, ObjEta, Oi, Oi0, Oi1, OiS0, OiS1, PostHocEta, ScaleVar, SqrtInvCov, TabStep, TrimOut, ltv2mat, mat2ltv, mat2utv, utv2mat, AddDoNoTaLD, AddPage, BtwTagMat, BtwTagVals, ClosePDF and 35 more - 0.1.62026-03-08 · diff ↗
- RR 4.5.0 released · 2025-04-11
- RR 4.4.0 released · 2024-04-24
- 0.1.52023-05-10 · diff ↗
- RR 4.3.0 released · 2023-04-21
- RR 4.2.0 released · 2022-04-22
- RR 4.1.0 released · 2021-05-18
- RR 4.0.0 released · 2020-04-24
- RR 3.6.0 released · 2019-04-26
- RR 3.5.0 released · 2018-04-23
Package metadata
- First published
- 2017-03-14
- Total releases
- 10 / 9 yrs
- License
- GPL-3 OSI
- Copyright
- 2017-, Kyun-Seop Bae
- Minimum R
- ≥ 3.6.0
- Download size
- 227 KB
Cite
Cite this package
Run in R for the authors' preferred citation:
citation("nmw")This package has no citation file, so citation() returns this entry built from DESCRIPTION.
Cite the R Observatory
For a number measured here: a download total, a coverage figure, an archival date.
From data release v2026-10-21, which the citation names so these numbers can be found later. More on citing and the projects behind them.