| Title: | Pharmacology Model Simulation and Bounded Estimation |
|---|---|
| Description: | Compile pharmacokinetic, pharmacodynamic and quantitative systems pharmacology models with explicit physical units, then simulate dosing regimens, run parameter scans and Morris (1991) <doi:10.1080/00401706.1991.10484804> elementary-effects screens. Parameters are estimated within declared bounds by maximum likelihood or maximum a posteriori fitting for individual and pooled data, and by first-order conditional estimation with interaction (Wang 2007 <doi:10.1007/s10928-007-9060-6>) or stochastic approximation expectation-maximization (Kuhn and Lavielle 2005 <doi:10.1016/j.csda.2004.07.002>) for population data. Count and correlated binomial data can be fitted with Gamma-Poisson and probit-normal mixture models. A documented subset of 'NONMEM'-style dosing and observation records can be converted to model requests with source-row provenance. Computation uses the 'QSPQuest' engine, written in 'Rust', with stiff ordinary differential equation solvers from the 'diffsol' library. |
| Authors: | Vivek Kohar [aut, cre], UniBio Intelligence [cph, fnd], Authors of the dependency Rust crates [ctb, cph] (see inst/COPYRIGHTS and inst/THIRD-PARTY-NOTICES.txt) |
| Maintainer: | Vivek Kohar <[email protected]> |
| License: | Apache License (== 2.0) |
| Version: | 0.1.0 |
| Built: | 2026-11-18 00:17:05 UTC |
| Source: | https://github.com/cran/qspquest |
Compile pharmacology models with explicit units and run simulation, parameter scans, sensitivity analysis and bounded estimation using a native Rust engine. Native simulation and fitting do not require Python or network services.
A complete runnable tutorial is installed at
system.file("doc", "quickstart.R", package = "qspquest").
Run it with source() after installation. A second example uses the
synthetic model and request in the installed extdata directory.
Always inspect fitting status and declared limitations before interpreting
results.
compile_model, fit_gamma_poisson,
fit_data_requests, population_fit_data_requests
Compile a model once and execute versioned simulation, bounded fitting, parameter scan, or Morris sensitivity requests with the Rust engine.
compile_model(source) simulate_model(model, request) fit_model(model, request) scan_model(model, request) morris_model(model, request)compile_model(source) simulate_model(model, request) fit_model(model, request) scan_model(model, request) morris_model(model, request)
source |
A model document as an R list or JSON string, or a model text string. |
model |
The session-local compiled model returned by |
request |
A versioned request as an R list or JSON string. Use the run, fit, scan, or Morris schema corresponding to the operation. Arrays should be R lists, including arrays containing just one item. |
Compiled pointers cannot be transferred to another process or restored
from saved R data. Recompile the source in each process. Fitting compiles its
selected sensitivities for each call. JSON models have a four-million-byte
limit; model text and requests retain a one-million-byte limit.
Units, bounds, event semantics and computational budgets are validated by
the engine. Scientific errors are R conditions of class qspquest_error,
with code, message and any available location fields.
Fitting supports bounded individual and pooled Gaussian MLE/MAP with fixed event
times and fixed residual-error parameters. Population random effects and censored
likelihoods are not supported by these operations.
compile_model returns a qspquest_model containing an external
pointer. The execution functions return parsed, versioned result lists with
execution identity and scientific values. Inspect result$fit$status
after fitting; a returned result does not imply convergence.
result_data_frame, nonmem_requests,
fit_data_requests
source <- paste( "model synthetic_decay", "time_unit = h", "parameters", " k = 0.1 [1/h] log", "states", " amount = 6 [mg]", "dynamics", " d/dt(amount) = -k * amount", "outputs", " remaining = amount [mg]", "end", sep = "\n") model <- compile_model(source) quantity <- function(value, unit) list(value = value, unit = unit) request <- list( schema = "qspquest.run/v0.1", solver = "diffsol_bdf", budgets = list(solver_callbacks = 100000L, events = 100L, output_values = 1000L), regimen = list(end = quantity(24, "h"), samples = lapply(c(0, 6, 12, 24), quantity, unit = "h"), administrations = list(), rtol = 1e-9, atol = 1e-11)) result <- simulate_model(model, request) trajectory <- result_data_frame(result) stopifnot(max(abs(trajectory$VALUE - 6 * exp(-0.1 * trajectory$TIME))) < 1e-6) trajectorysource <- paste( "model synthetic_decay", "time_unit = h", "parameters", " k = 0.1 [1/h] log", "states", " amount = 6 [mg]", "dynamics", " d/dt(amount) = -k * amount", "outputs", " remaining = amount [mg]", "end", sep = "\n") model <- compile_model(source) quantity <- function(value, unit) list(value = value, unit = unit) request <- list( schema = "qspquest.run/v0.1", solver = "diffsol_bdf", budgets = list(solver_callbacks = 100000L, events = 100L, output_values = 1000L), regimen = list(end = quantity(24, "h"), samples = lapply(c(0, 6, 12, 24), quantity, unit = "h"), administrations = list(), rtol = 1e-9, atol = 1e-11)) result <- simulate_model(model, request) trajectory <- result_data_frame(result) stopifnot(max(abs(trajectory$VALUE - 6 * exp(-0.1 * trajectory$TIME))) < 1e-6) trajectory
Map measurement records to explicit model outputs, units and fixed Gaussian error models, then fit subjects independently or pool selected parameters.
fit_data_requests(dataset, template, endpoints, mode = c("individual", "pooled")) fit_data(model, dataset)fit_data_requests(dataset, template, endpoints, mode = c("individual", "pooled")) fit_data(model, dataset)
dataset |
For preparation, a |
template |
An individual |
endpoints |
Named list keyed by observation CMT. Each entry contains exactly
|
mode |
|
model |
A compiled model from |
Included DV values must be finite; use MDV to exclude missing measurements. Observation CMT requires an explicit endpoint mapping. Duplicate observations remain independent likelihood terms. SOURCE_ROW is one-based in the original data; RESULT_ROW is zero-based in that subject's native simulation. The engine converts compatible measurement/error units. A pooled MAP prior is counted once; independent fits each receive the template prior. Subjects' requests execute sequentially. This supports fixed-error Gaussian fits, without population random effects, censoring, residual-error estimation or inferred covariate mappings.
Preparation returns inspectable requests, mapping,
subject_ids, mode and original source.
Execution returns the same mapping and source plus results and the
inspectable versioned requests for optional prediction replay.
Inspect every result's fit$status before using estimates.
nonmem_requests, fit_model,
fit_parameter_data_frame
q <- function(value, unit) list(value = value, unit = unit) model <- compile_model(paste( "model one_compartment", "time_unit = h", "parameters", " cl = 0.6 [L/h] log", " v = 4.5 [L] log", "states", " central = 0 [mg]", "dynamics", " d/dt(central) = input_central - cl / v * central", "outputs", " cp = central / v [mg/L]", "dosing", " central [mg] = 1", "end", sep = "\n")) run_template <- list(schema = "qspquest.run/v0.1", solver = "diffsol_bdf", budgets = list(solver_callbacks = 1000000L, events = 100L, output_values = 10000L), regimen = list(end = q(4, "h"), samples = list(), administrations = list(), rtol = 1e-10, atol = 1e-12)) rows <- do.call(rbind, lapply(c("A", "B"), function(id) data.frame( ID = id, TIME = c(0, 1, 2, 4), EVID = c(1L, 0L, 0L, 0L), CMT = c(1L, 2L, 2L, 2L), AMT = c(6, 0, 0, 0), MDV = c(1L, 0L, 0L, 0L), DV = c(NA, 6 / 4.5 * exp(-0.6 * c(1, 2, 4) / 4.5))))) dataset <- nonmem_requests(rows, run_template, c("1" = "central"), "h", "mg") template <- list(schema = "qspquest.fit/v0.1", problem = list( kind = "individual", request = list( objective = list(simulation = list(schema = "qspquest.sensitivity/v0.1", with_respect_to = list("cl"), derivative_absolute_tolerances = list(cl = list(central = q(1e-12, "mg.h/L")))), observations = list(), priors = list()), bounds = list(list(parameter = "cl", lower = q(0.05, "L/h"), upper = q(1.2, "L/h"))), max_evaluations = 400L, max_iterations = 100L, gradient_tolerance = 1e-5))) endpoints <- list("2" = list(output = "cp", value_unit = "mg/L", error = list(additive_sd = q(0.1, "mg/L"), proportional_sd = 0))) prepared <- fit_data_requests(dataset, template, endpoints, mode = "pooled") fitted <- fit_data(model, prepared) stopifnot(fitted$results[[1]]$fit$status == "converged") fitted$results[[1]]$fit$parameters head(prepared$mapping)q <- function(value, unit) list(value = value, unit = unit) model <- compile_model(paste( "model one_compartment", "time_unit = h", "parameters", " cl = 0.6 [L/h] log", " v = 4.5 [L] log", "states", " central = 0 [mg]", "dynamics", " d/dt(central) = input_central - cl / v * central", "outputs", " cp = central / v [mg/L]", "dosing", " central [mg] = 1", "end", sep = "\n")) run_template <- list(schema = "qspquest.run/v0.1", solver = "diffsol_bdf", budgets = list(solver_callbacks = 1000000L, events = 100L, output_values = 10000L), regimen = list(end = q(4, "h"), samples = list(), administrations = list(), rtol = 1e-10, atol = 1e-12)) rows <- do.call(rbind, lapply(c("A", "B"), function(id) data.frame( ID = id, TIME = c(0, 1, 2, 4), EVID = c(1L, 0L, 0L, 0L), CMT = c(1L, 2L, 2L, 2L), AMT = c(6, 0, 0, 0), MDV = c(1L, 0L, 0L, 0L), DV = c(NA, 6 / 4.5 * exp(-0.6 * c(1, 2, 4) / 4.5))))) dataset <- nonmem_requests(rows, run_template, c("1" = "central"), "h", "mg") template <- list(schema = "qspquest.fit/v0.1", problem = list( kind = "individual", request = list( objective = list(simulation = list(schema = "qspquest.sensitivity/v0.1", with_respect_to = list("cl"), derivative_absolute_tolerances = list(cl = list(central = q(1e-12, "mg.h/L")))), observations = list(), priors = list()), bounds = list(list(parameter = "cl", lower = q(0.05, "L/h"), upper = q(1.2, "L/h"))), max_evaluations = 400L, max_iterations = 100L, gradient_tolerance = 1e-5))) endpoints <- list("2" = list(output = "cp", value_unit = "mg/L", error = list(additive_sd = q(0.1, "mg/L"), proportional_sd = 0))) prepared <- fit_data_requests(dataset, template, endpoints, mode = "pooled") fitted <- fit_data(model, prepared) stopifnot(fitted$results[[1]]$fit$status == "converged") fitted$results[[1]]$fit$parameters head(prepared$mapping)
Bounded native point estimation for independent Gamma-Poisson count/exposure rows or two groups of independent binomial litters with normally distributed probit effects.
fit_gamma_poisson(request) fit_probit_normal_binomial(request)fit_gamma_poisson(request) fit_probit_normal_binomial(request)
request |
A complete request as an R list or a JSON string, using the
|
Gamma rates have exposure units in the shape-rate convention. Probit means and SDs are dimensionless, with optimization in mean and variance coordinates. The probit-normal mixture integrates over an unbounded normal distribution and supports zero SD. These functions calculate point estimates without confidence intervals.
A list with the fit status, estimates, normalized negative log likelihood,
work counts, projected gradient norm and source/request identities.
Check status before interpreting estimates. Quadrature-budget exhaustion
raises a structured qspquest_error.
q <- function(value) list(value = value, unit = "h") request <- list( schema = "qspquest.gamma-poisson-fit/v0.1", observations = list(list(count = 0L, exposure = q(1)), list(count = 1L, exposure = q(1))), initial_shape = 1, shape_bounds = c(0.01, 100), initial_rate = q(1), rate_bounds = list(q(0.01), q(100)), max_evaluations = 1000L, max_iterations = 200L, gradient_tolerance = 1e-7) fit <- fit_gamma_poisson(request) stopifnot(fit$status == "converged") fit$parametersq <- function(value) list(value = value, unit = "h") request <- list( schema = "qspquest.gamma-poisson-fit/v0.1", observations = list(list(count = 0L, exposure = q(1)), list(count = 1L, exposure = q(1))), initial_shape = 1, shape_bounds = c(0.01, 100), initial_rate = q(1), rate_bounds = list(q(0.01), q(100)), max_evaluations = 1000L, max_iterations = 200L, gradient_tolerance = 1e-7) fit <- fit_gamma_poisson(request) stopifnot(fit$status == "converged") fit$parameters
Extract unit-bearing parameter estimates or replay converged fits at their final estimates to obtain source-row-aligned observations and predictions.
fit_parameter_data_frame(fitted) fit_observation_data_frame(model, fitted)fit_parameter_data_frame(fitted) fit_observation_data_frame(model, fitted)
fitted |
A result returned by |
model |
The compiled model used by |
Prediction replay runs one simulation per subject on demand, using the
fitted parameters and the original request. It requires every fit to have
status == "converged". Original subject-specific execution results remain
available in the fit_data result. These helpers cover the individual and
pooled fixed-error Gaussian dataset adapter; they do not infer random effects,
covariates, censoring, or residual-error models.
fit_parameter_data_frame returns ID, PARAMETER, ESTIMATE, UNIT,
STATUS and OBJECTIVE columns. Pooled fits have a missing ID because estimates
are shared. fit_observation_data_frame returns ID, SOURCE_ROW, RESULT_ROW,
TIME, SIDE, OUTPUT, DV, DV_UNIT, PRED, PRED_UNIT and RESID. RESID is missing when
DV and PRED use different units; the package never subtracts incompatible
values. Row order matches the source observations within each subject.
fit_data_requests, nonmem_requests
q <- function(value, unit) list(value = value, unit = unit) model <- compile_model(paste( "model one_compartment", "time_unit = h", "parameters", " cl = 0.6 [L/h] log", " v = 4.5 [L] log", "states", " central = 0 [mg]", "dynamics", " d/dt(central) = input_central - cl / v * central", "outputs", " cp = central / v [mg/L]", "dosing", " central [mg] = 1", "end", sep = "\n")) run_template <- list(schema = "qspquest.run/v0.1", solver = "diffsol_bdf", budgets = list(solver_callbacks = 1000000L, events = 100L, output_values = 10000L), regimen = list(end = q(4, "h"), samples = list(), administrations = list(), rtol = 1e-10, atol = 1e-12)) rows <- do.call(rbind, lapply(c("A", "B"), function(id) data.frame( ID = id, TIME = c(0, 1, 2, 4), EVID = c(1L, 0L, 0L, 0L), CMT = c(1L, 2L, 2L, 2L), AMT = c(6, 0, 0, 0), MDV = c(1L, 0L, 0L, 0L), DV = c(NA, 6 / 4.5 * exp(-0.6 * c(1, 2, 4) / 4.5))))) dataset <- nonmem_requests(rows, run_template, c("1" = "central"), "h", "mg") template <- list(schema = "qspquest.fit/v0.1", problem = list( kind = "individual", request = list( objective = list(simulation = list(schema = "qspquest.sensitivity/v0.1", with_respect_to = list("cl"), derivative_absolute_tolerances = list(cl = list(central = q(1e-12, "mg.h/L")))), observations = list(), priors = list()), bounds = list(list(parameter = "cl", lower = q(0.05, "L/h"), upper = q(1.2, "L/h"))), max_evaluations = 400L, max_iterations = 100L, gradient_tolerance = 1e-5))) endpoints <- list("2" = list(output = "cp", value_unit = "mg/L", error = list(additive_sd = q(0.1, "mg/L"), proportional_sd = 0))) prepared <- fit_data_requests(dataset, template, endpoints, mode = "pooled") fitted <- fit_data(model, prepared) stopifnot(fitted$results[[1]]$fit$status == "converged") print(fit_parameter_data_frame(fitted)) print(fit_observation_data_frame(model, fitted))q <- function(value, unit) list(value = value, unit = unit) model <- compile_model(paste( "model one_compartment", "time_unit = h", "parameters", " cl = 0.6 [L/h] log", " v = 4.5 [L] log", "states", " central = 0 [mg]", "dynamics", " d/dt(central) = input_central - cl / v * central", "outputs", " cp = central / v [mg/L]", "dosing", " central [mg] = 1", "end", sep = "\n")) run_template <- list(schema = "qspquest.run/v0.1", solver = "diffsol_bdf", budgets = list(solver_callbacks = 1000000L, events = 100L, output_values = 10000L), regimen = list(end = q(4, "h"), samples = list(), administrations = list(), rtol = 1e-10, atol = 1e-12)) rows <- do.call(rbind, lapply(c("A", "B"), function(id) data.frame( ID = id, TIME = c(0, 1, 2, 4), EVID = c(1L, 0L, 0L, 0L), CMT = c(1L, 2L, 2L, 2L), AMT = c(6, 0, 0, 0), MDV = c(1L, 0L, 0L, 0L), DV = c(NA, 6 / 4.5 * exp(-0.6 * c(1, 2, 4) / 4.5))))) dataset <- nonmem_requests(rows, run_template, c("1" = "central"), "h", "mg") template <- list(schema = "qspquest.fit/v0.1", problem = list( kind = "individual", request = list( objective = list(simulation = list(schema = "qspquest.sensitivity/v0.1", with_respect_to = list("cl"), derivative_absolute_tolerances = list(cl = list(central = q(1e-12, "mg.h/L")))), observations = list(), priors = list()), bounds = list(list(parameter = "cl", lower = q(0.05, "L/h"), upper = q(1.2, "L/h"))), max_evaluations = 400L, max_iterations = 100L, gradient_tolerance = 1e-5))) endpoints <- list("2" = list(output = "cp", value_unit = "mg/L", error = list(additive_sd = q(0.1, "mg/L"), proportional_sd = 0))) prepared <- fit_data_requests(dataset, template, endpoints, mode = "pooled") fitted <- fit_data(model, prepared) stopifnot(fitted$results[[1]]$fit$status == "converged") print(fit_parameter_data_frame(fitted)) print(fit_observation_data_frame(model, fitted))
Browse the catalog and execute named scenarios with the model library's verified loader. The library and its Python loader are distributed separately from this package; the QSPQuest Docker Compose deployment provides both.
model_library(root = Sys.getenv("QSPQUEST_LIBRARY_DIR"), python = Sys.getenv("QSPQUEST_PYTHON", "python3"))model_library(root = Sys.getenv("QSPQUEST_LIBRARY_DIR"), python = Sys.getenv("QSPQUEST_PYTHON", "python3"))
root |
Directory containing |
python |
Python executable with QSPQuest installed, or access to the QSPQuest CLI. |
Pass a nonempty exact version string to pin the catalog selection. The default NULL selects the current catalog version. An unavailable pin fails before simulation and is never replaced automatically. Availability does not establish numerical qualification. The optional shared-library workflow requires Python and the separately distributed model-library package. Native R simulation and fitting do not require Python. Read each model's card and qualification limits before interpreting results. Inspection-only models have no executable scenarios.
A list of functions: models() returns catalog rows; scenarios(model, version = NULL) returns available scenario IDs; run(model, scenario, version = NULL) returns a parsed simulation result, including units, event sides and archive checksum.
# Requires a separately installed QSPQuest model library and Python loader. if (nzchar(Sys.getenv("QSPQUEST_LIBRARY_DIR"))) { library_api <- model_library() catalog <- library_api$models() length(catalog) }# Requires a separately installed QSPQuest model library and Python loader. if (nzchar(Sys.getenv("QSPQUEST_LIBRARY_DIR"))) { library_api <- model_library() catalog <- library_api$models() length(catalog) }
Convert a supported subset of observation and dosing records into one simulation request per subject, preserving original source-row mappings.
nonmem_requests(data, template, compartments, time_unit, amount_unit, rate_unit = NULL, observation_side = "post") simulate_data(model, dataset)nonmem_requests(data, template, compartments, time_unit, amount_unit, rate_unit = NULL, observation_side = "post") simulate_data(model, dataset)
data |
A nonempty data frame with ID, TIME and EVID. Optional columns are DV, MDV, AMT, CMT, RATE, ADDL, II and SS. Additional columns are rejected. |
template |
A versioned run request as a list or JSON string. Its regimen administrations, resets, covariate changes, checkpoints, samples and observations must be empty. It supplies start/end, parameters, static covariates, solver, tolerances and per-subject budgets. |
compartments |
Named character vector mapping dose CMT values to model targets. |
time_unit, amount_unit
|
Explicit unit strings for TIME/II and AMT. |
rate_unit |
Explicit RATE unit, required for positive RATE. |
observation_side |
Either |
model |
A compiled model from |
dataset |
A |
EVID 0 with MDV 0 requests an observation; EVID 1 doses require positive AMT and a mapped CMT. RATE 0 is bolus and positive RATE is finite infusion. ADDL/II specify repeat doses. Missing dose fields and MDV default to zero. DV is retained without inferring missingness: set MDV explicitly. Each subject must have an observation. Duplicate and unsorted observations retain their order. Negative RATE, nonzero SS, EVID 2/3/4 and dose fields on observations are rejected. The engine checks unit compatibility, model targets and the template horizon; conversion never extends the horizon. Subjects execute sequentially. This is not a general NONMEM importer; covariates and censoring are not inferred.
nonmem_requests returns a qspquest_dataset with per-subject
requests, source rows, observation rows and original data. simulate_data
returns subjects with native results and long data, combined data,
and original source. Output includes character ID and one-based SOURCE_ROW.
Execution identities remain on each subject result.
fit_data_requests, result_data_frame
request <- list(schema = "qspquest.run/v0.1", solver = "diffsol_bdf", budgets = list(solver_callbacks = 100000, events = 100, output_values = 1000), regimen = list(end = list(value = 4, unit = "h"), samples = list(), administrations = list(), rtol = 1e-8, atol = 1e-10)) data <- data.frame(ID = c("A", "A"), TIME = c(0, 1), EVID = c(1, 0), AMT = c(6, 0), CMT = c(1, 0)) prepared <- nonmem_requests(data, request, c("1" = "central"), "h", "mg") prepared$subjects[[1]]$observation_rowsrequest <- list(schema = "qspquest.run/v0.1", solver = "diffsol_bdf", budgets = list(solver_callbacks = 100000, events = 100, output_values = 1000), regimen = list(end = list(value = 4, unit = "h"), samples = list(), administrations = list(), rtol = 1e-8, atol = 1e-10)) data <- data.frame(ID = c("A", "A"), TIME = c(0, 1), EVID = c(1, 0), AMT = c(6, 0), CMT = c(1, 0)) prepared <- nonmem_requests(data, request, c("1" = "central"), "h", "mg") prepared$subjects[[1]]$observation_rows
Build a FOCEI or SAEM request from an explicit subset of NONMEM records, preserving subject and source-row provenance. Execute the request and extract subject estimates or row-aligned predictions.
population_fit_data_requests(data, template, compartments, endpoints, time_unit, amount_unit, rate_unit = NULL, observation_side = "post") fit_population_data(model, dataset) population_fit_subject_data_frame(fitted) population_fit_observation_data_frame(fitted)population_fit_data_requests(data, template, compartments, endpoints, time_unit, amount_unit, rate_unit = NULL, observation_side = "post") fit_population_data(model, dataset) population_fit_subject_data_frame(fitted) population_fit_observation_data_frame(fitted)
data |
A nonempty data frame with unique columns and required ID, TIME and EVID. Supported optional columns are DV, MDV, AMT, CMT, RATE, ADDL, II and SS. |
template |
A versioned |
compartments |
Named character vector mapping dose CMT values to model targets. |
endpoints |
Named list mapping observation CMT values to lists containing
exactly |
time_unit, amount_unit, rate_unit
|
Explicit unit strings. A positive RATE requires rate_unit. |
observation_side |
Either |
model |
A model from |
dataset |
The prepared population dataset returned by
|
fitted |
A result returned by |
Only EVID 0 observations and EVID 1 doses are supported; MDV 1 omits an observation. Included DV values must be finite. Nonzero SS, negative RATE, unmapped compartments/endpoints, extra columns, covariate records and censoring are rejected. The native engine performs model, unit, time and fitting checks. FOCEI and SAEM objectives differ and their numerical values are not directly interchangeable.
population_fit_data_requests returns a prepared request,
subject IDs, the original data frame and a mapping. SOURCE_ROW is one-based in
R; SUBJECT_INDEX, OBSERVATION_INDEX and RESULT_ROW are zero-based native indices.
fit_population_data returns the native versioned result and that mapping,
after checking subject and fitted-observation alignment.
population_fit_subject_data_frame returns one row per subject and random
effect with ID, eta, fixed effect, derived individual estimate, parameter unit,
conditional negative log likelihood and fit status.
population_fit_observation_data_frame returns FOCEI fitted observations
with ID, source and native row indices, time, side, DV, PRED, IPRED, units and
residuals. It returns NULL when SAEM has no fitted observations. Residuals
are missing when the compared units differ.
nonmem_requests, fit_data_requests
q <- function(value, unit) list(value = value, unit = unit) model <- compile_model(paste( "model one_compartment", "time_unit = h", "parameters", " cl = 0.6 [L/h] log", " v = 4.5 [L] log", "states", " central = 0 [mg]", "dynamics", " d/dt(central) = input_central - cl / v * central", "outputs", " cp = central / v [mg/L]", "dosing", " central [mg] = 1", "end", sep = "\n")) run_template <- list(schema = "qspquest.run/v0.1", solver = "diffsol_bdf", budgets = list(solver_callbacks = 1000000L, events = 100L, output_values = 10000L), regimen = list(end = q(4, "h"), samples = list(), administrations = list(), rtol = 1e-10, atol = 1e-12)) etas <- c(-0.22, -0.08, 0.08, 0.22) rows <- do.call(rbind, lapply(seq_along(etas), function(i) data.frame( ID = paste0("S", i), TIME = c(0, 1, 2, 4), EVID = c(1L, 0L, 0L, 0L), CMT = c(1L, 2L, 2L, 2L), AMT = c(6, 0, 0, 0), MDV = c(1L, 0L, 0L, 0L), DV = c(NA, 6 / 4.5 * exp(-0.6 * exp(etas[i]) * c(1, 2, 4) / 4.5))))) simulation <- list(schema = "qspquest.sensitivity/v0.1", run = run_template, with_respect_to = list("cl"), derivative_absolute_tolerances = list(cl = list(central = q(1e-12, "mg.h/L")))) simulation$run$parameters <- list(cl = q(0.5, "L/h"), v = q(4.5, "L")) template <- list(schema = "qspquest.fit/v0.1", problem = list( kind = "focei", request = list( subjects = list(list(simulation = simulation, observations = list(), priors = list())), fixed_effects = list(list(parameter = "cl", lower = q(0.35, "L/h"), upper = q(0.85, "L/h"))), random_effects = list(list(parameter = "cl")), omega = list(list(0.04)), omega_diagonal_bounds = list(list(0.04, 0.04)), eta_bound = 1.5, max_evaluations = 30000L, max_iterations = 80L, gradient_tolerance = 0.005, seed = 17L))) endpoints <- list("2" = list(output = "cp", value_unit = "mg/L", error = list(additive_sd = q(0.05, "mg/L"), proportional_sd = 0))) prepared <- population_fit_data_requests(rows, template, c("1" = "central"), endpoints, time_unit = "h", amount_unit = "mg") fitted <- fit_population_data(model, prepared) stopifnot(fitted$result$population$status == "converged") print(population_fit_subject_data_frame(fitted)) print(head(population_fit_observation_data_frame(fitted)))q <- function(value, unit) list(value = value, unit = unit) model <- compile_model(paste( "model one_compartment", "time_unit = h", "parameters", " cl = 0.6 [L/h] log", " v = 4.5 [L] log", "states", " central = 0 [mg]", "dynamics", " d/dt(central) = input_central - cl / v * central", "outputs", " cp = central / v [mg/L]", "dosing", " central [mg] = 1", "end", sep = "\n")) run_template <- list(schema = "qspquest.run/v0.1", solver = "diffsol_bdf", budgets = list(solver_callbacks = 1000000L, events = 100L, output_values = 10000L), regimen = list(end = q(4, "h"), samples = list(), administrations = list(), rtol = 1e-10, atol = 1e-12)) etas <- c(-0.22, -0.08, 0.08, 0.22) rows <- do.call(rbind, lapply(seq_along(etas), function(i) data.frame( ID = paste0("S", i), TIME = c(0, 1, 2, 4), EVID = c(1L, 0L, 0L, 0L), CMT = c(1L, 2L, 2L, 2L), AMT = c(6, 0, 0, 0), MDV = c(1L, 0L, 0L, 0L), DV = c(NA, 6 / 4.5 * exp(-0.6 * exp(etas[i]) * c(1, 2, 4) / 4.5))))) simulation <- list(schema = "qspquest.sensitivity/v0.1", run = run_template, with_respect_to = list("cl"), derivative_absolute_tolerances = list(cl = list(central = q(1e-12, "mg.h/L")))) simulation$run$parameters <- list(cl = q(0.5, "L/h"), v = q(4.5, "L")) template <- list(schema = "qspquest.fit/v0.1", problem = list( kind = "focei", request = list( subjects = list(list(simulation = simulation, observations = list(), priors = list())), fixed_effects = list(list(parameter = "cl", lower = q(0.35, "L/h"), upper = q(0.85, "L/h"))), random_effects = list(list(parameter = "cl")), omega = list(list(0.04)), omega_diagonal_bounds = list(list(0.04, 0.04)), eta_bound = 1.5, max_evaluations = 30000L, max_iterations = 80L, gradient_tolerance = 0.005, seed = 17L))) endpoints <- list("2" = list(output = "cp", value_unit = "mg/L", error = list(additive_sd = q(0.05, "mg/L"), proportional_sd = 0))) prepared <- population_fit_data_requests(rows, template, c("1" = "central"), endpoints, time_unit = "h", amount_unit = "mg") fitted <- fit_population_data(model, prepared) stopifnot(fitted$result$population$status == "converged") print(population_fit_subject_data_frame(fitted)) print(head(population_fit_observation_data_frame(fitted)))
Exports model syntax, numeric fixed-effect initial values, state order and runtime
versions. Install rxode2 separately. The snapshot is read by the import_rxode2_snapshot
adapter of the separately distributed QSPQuest Python package, which checks its
own supported structural subset; this helper does not run a fit or
qualify population-estimation equivalence.
qspquest_export_rxode2_ui(ui, path)qspquest_export_rxode2_ui(ui, path)
ui |
An existing rxode2/nlmixr2-compatible UI object with an explicit model block. |
path |
Destination JSON file. |
The snapshot invisibly, after writing its JSON representation.
if (requireNamespace("rxode2", quietly = TRUE)) { ui <- rxode2::rxode2(function() { ini({ ka <- 1.1; cl <- 0.3; v <- 3 }) model({ d/dt(depot) <- -ka * depot d/dt(central) <- ka * depot - cl / v * central cp <- central / v }) }) path <- tempfile(fileext = ".json") snapshot <- qspquest_export_rxode2_ui(ui, path) names(snapshot$parameters) unlink(path) }if (requireNamespace("rxode2", quietly = TRUE)) { ui <- rxode2::rxode2(function() { ini({ ka <- 1.1; cl <- 0.3; v <- 3 }) model({ d/dt(depot) <- -ka * depot d/dt(central) <- ka * depot - cl / v * central cp <- central / v }) }) path <- tempfile(fileext = ".json") snapshot <- qspquest_export_rxode2_ui(ui, path) names(snapshot$parameters) unlink(path) }
Produce long-format output suitable for plotting or joining with
observation records. Missing values remain present as NA.
result_data_frame(result)result_data_frame(result)
result |
A parsed |
A data frame with TIME, SIDE, OUTPUT, VALUE
and UNIT columns. Attributes time_unit and execution_identity
retain simulation metadata. Rows are grouped by output, retaining the native
observation order within each output.
# A parsed simulation result, as returned by simulate_model(). result <- list(schema = "qspquest.result/v0.1", time_unit = "h", times = list(0, 1), sides = list("post", "post"), outputs = list(list(name = "cp", unit = "mg/L", values = list(2, 1.81))), identity = list()) result_data_frame(result)# A parsed simulation result, as returned by simulate_model(). result <- list(schema = "qspquest.result/v0.1", time_unit = "h", times = list(0, 1), sides = list("post", "post"), outputs = list(list(name = "cp", unit = "mg/L", values = list(2, 1.81))), identity = list()) result_data_frame(result)