From 014bc9e490d6ed34bdd9fb17630f5cbcc19fc52b Mon Sep 17 00:00:00 2001 From: Bill Denney Date: Sat, 8 Aug 2026 08:30:20 -0400 Subject: [PATCH] docs: Tobit half-life now runs end-to-end through pk.nca() Upstream humanpred/pknca issue 553 (closed 2026-06-11) added an lloq argument to PKNCAconc() (numeric scalar or column name) and wired it through to pk.calc.half.life(), so hl_method = "tobit" set via PKNCAdata(options = ...) no longer needs the direct pk.calc.half.life() workaround. Verified against the installed PKNCA 0.12.1.9000 (GitHub eff79252, packaged 2026-07-24): the pipeline result matches the direct Tobit call exactly and errors only when lloq is absent from PKNCAconc. - user/halflife.qmd: replace the pipeline-workaround note with a runnable end-to-end example, tagged (>= 0.12.2) - CONTRIBUTING.md: update the Tobit known-gotcha to the remaining pitfall (lloq must be set on PKNCAconc) Co-Authored-By: Claude Fable 5 --- CONTRIBUTING.md | 2 +- user/halflife.qmd | 30 ++++++++++++++++++++++++++++-- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 7ea1b77..43cdca5 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -102,7 +102,7 @@ as.data.frame(o_nca) |> **Known gotchas:** -- **Tobit half-life** — `pk.nca()` does not wire `lloq` through to `pk.calc.half.life()`. Use `pk.calc.half.life()` directly and add a note in the docs. +- **Tobit half-life** — `hl_method = "tobit"` through `pk.nca()` requires the LLOQ on the concentration object: `PKNCAconc(..., lloq = )` (≥ 0.12.2). Without `lloq`, `pk.nca()` stops with "lloq must be provided when hl_method is 'tobit'". - **Sparse AUMC** — only set `sparse_aumclast = TRUE`. Explicitly requesting `sparse_auc_se = TRUE` alongside it triggers an internal type error. - **`normalize()`** — replaces the original parameters (does not append). To keep both, `bind_rows()` before and after. - **New option defaults** — always verify with `PKNCA.options("option_name")` before documenting the default. diff --git a/user/halflife.qmd b/user/halflife.qmd index cdb16fc..5629e57 100644 --- a/user/halflife.qmd +++ b/user/halflife.qmd @@ -245,7 +245,7 @@ Tobit regression is most beneficial when: ### Using Tobit (PKNCA ≥ 0.12.2) -Tobit is available by calling `pk.calc.half.life()` directly. Supply the full concentration-time vector and the LLOQ for each timepoint: +The mechanics are easiest to see with a direct `pk.calc.half.life()` call. Supply the full concentration-time vector and the LLOQ for each timepoint: ```{r} # Simulated profile — concentrations at 16h and 24h are below the LLOQ of 0.1 mg/L @@ -270,7 +270,33 @@ data.frame( ) ``` -> **Note:** Passing `hl_method = "tobit"` through the `pk.nca()` pipeline (via `PKNCAdata(options=...)`) also requires the LLOQ to be wired through from the concentration data, which is tracked for a future PKNCA update. For full pipeline support, use `hl_method = "log-linear"` (default) and call `pk.calc.half.life()` with `hl_method = "tobit"` directly for targeted analyses. +### Tobit through the `pk.nca()` pipeline (≥ 0.12.2) + +The full pipeline supports Tobit end-to-end. Supply the LLOQ with the `lloq` argument of `PKNCAconc()` — either a numeric scalar or the name of a column in the concentration data — and select the method with `PKNCAdata(options = list(hl_method = "tobit"))`: + +```{r} +d_conc_tobit <- data.frame(subject = 1, conc = conc_tobit, time = time_tobit) +d_dose_tobit <- data.frame(subject = 1, dose = 100, time = 0) + +o_conc_tobit <- PKNCAconc(d_conc_tobit, conc ~ time | subject, lloq = 0.1) +o_dose_tobit <- PKNCAdose(d_dose_tobit, dose ~ time | subject) + +tobit_interval <- data.frame(start = 0, end = Inf, + half.life = TRUE, lambda.z = TRUE, + lambda.z.n.points = TRUE) + +o_nca_tobit <- pk.nca(PKNCAdata(o_conc_tobit, o_dose_tobit, + intervals = tobit_interval, + options = list(hl_method = "tobit"))) + +as.data.frame(o_nca_tobit) |> + filter(PPTESTCD %in% c("half.life", "lambda.z", "lambda.z.n.points", + "lambda.z.n.points_blq", "tobit_residual", + "adj_tobit_residual")) |> + select(PPTESTCD, PPORRES) +``` + +The λz and half-life match the direct `pk.calc.half.life()` call above, and `lambda.z.n.points_blq` confirms that the two BLQ observations entered the regression as censored points. The LLOQ must be set on `PKNCAconc()` — with `hl_method = "tobit"` and no `lloq`, `pk.nca()` stops with an error. Tobit adds new output columns to the result: