Skip to content

Add run_sim_with_uncertainty() — PsN vpc uncertainty sampling wrapper#51

Open
roninsightrx wants to merge 1 commit intomainfrom
sim-uncertainty-vpc
Open

Add run_sim_with_uncertainty() — PsN vpc uncertainty sampling wrapper#51
roninsightrx wants to merge 1 commit intomainfrom
sim-uncertainty-vpc

Conversation

@roninsightrx
Copy link
Copy Markdown
Contributor

Summary

  • Adds run_sim_with_uncertainty() which wraps PsN's vpc --uncertainty_sample=N to simulate from a NONMEM model while incorporating parameter uncertainty from the covariance step
  • Samples N parameter vectors from the multivariate normal distribution defined by the covariance matrix, runs one NONMEM simulation per draw, and returns a single data.frame with a sample_id column
  • Adds two private helpers: extract_fit_folder() (resolves run folder from a fit object) and read_vpc_sim_tables() (parses PsN vpc output directory structure)
  • Bumps version to 0.0.0.9029

Usage

# Basic usage — pass a fit object from run_nlme() (must have been run with $COVARIANCE)
out <- run_sim_with_uncertainty(fit = my_fit, n_samples = 200)

# With a custom simulation dataset (different obs times / subjects)
out <- run_sim_with_uncertainty(fit_folder = "run1/", data = sim_dat, n_samples = 200)

Test plan

  • 26 tests in test-run_sim_with_uncertainty.R
  • 20 pass without NONMEM (pure R / file I/O)
  • 6 skip unless Pharmpy is configured; mock call_psn() to test end-to-end pipeline without actually running PsN
  • Verify FAIL 0 | WARN 0 with devtools::test(filter = "run_sim_with_uncertainty")

🤖 Generated with Claude Code

Wraps PsN's `vpc --uncertainty_sample=N` to simulate from a NONMEM model
while incorporating parameter uncertainty from the covariance step. Samples
N parameter vectors from MVN(estimates, cov_matrix), runs one simulation per
draw via PsN, and returns all results in a single data.frame with a
`sample_id` column.

Includes 26 tests (20 run without NONMEM; 6 skip unless Pharmpy configured).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant