Learn R Programming

quickcode (version 1.2.0)

nonmem_scaling: Compute S1 scaling expression for NONMEM

Description

Given the units used in your dataset/model for the dependent variable (DV, a concentration like "ng/mL"), the dosing amount (AMT, e.g. "mg") and the model volume parameter V (e.g. "L" or "mL"), this function returns a robust NONMEM-ready S1 expression so that A(n)/S1 has the same units as DV.

The function:

  • parses common unit notations and synonyms (e.g. "ug", "mcg"),

  • validates input and provides informative errors,

  • computes the numeric factor such that S1 = V * factor,

  • returns a human-readable explanation and an optional numeric example.

Usage

nonmem_scaling(
  dv_unit,
  amt_unit,
  v_unit,
  sig_digits = 8L,
  example = FALSE,
  example_amt = 1,
  example_v = 1
)

Value

A list with elements:

factor

Numeric. The multiplicative factor such that S1 = V * factor.

S1_expression

Character. NONMEM-ready expression (e.g. "S1 = V/1000").

explanation

Character. Human-readable explanation of the derivation.

example

Named list (present only when example = TRUE) with numeric example.

Arguments

dv_unit

Character scalar. DV concentration unit, e.g. "ng/mL", "mg/L", "ug per mL".

amt_unit

Character scalar. AMT unit (mass), e.g. "mg", "ug", "ng".

v_unit

Character scalar. Unit for model volume parameter V, e.g. "L", "mL".

sig_digits

Integer scalar. Significant digits for formatted output (default = 8).

example

Logical scalar. If TRUE, include a numeric example (default = FALSE).

example_amt

Numeric scalar. Example AMT value (default = 1).

example_v

Numeric scalar. Example V value (default = 1).

Details

Compute NONMEM S1 scaling from concentration, amount, and volume units

Examples

Run this code
# Typical PK: DV in ng/mL, AMT in mg, V in L -> S1 = V * 1e+06 / 1000 = V * 1000
nonmem_scaling("ng/mL", "mg", "L")

# If V is stored in mL:
nonmem_scaling("ng/mL", "mg", "mL")

# With numeric example
nonmem_scaling("ng/mL", "mg", "L", example = TRUE, example_amt = 100, example_v = 40)

# Microgram dosing
nonmem_scaling("pg/mL", "ug", "L")

Run the code above in your browser using DataLab