Skip to content

Commit 7c252f4

Browse files
roninsightrxclaude
andauthored
add CLAUDE.md for Claude Code guidance (#41)
* add CLAUDE.md for Claude Code guidance Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * update VPC snapshots for vpc package rendering changes Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * update claude md --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent ea8242e commit 7c252f4

3 files changed

Lines changed: 440 additions & 362 deletions

File tree

CLAUDE.md

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# CLAUDE.md
2+
3+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4+
5+
## Package Overview
6+
7+
`mipdeval` is an R package for evaluating predictive performance of PK/PD models in historical datasets for model-informed precision dosing (MIPD). It iteratively loops through NONMEM-style datasets, performing MAP Bayesian updating and forecasting at each step—similar to PsN's `proseval` tool, but with MIPD-specific features like prior flattening, time-based weighting, and sample grouping.
8+
9+
Core dependencies:
10+
- **PKPDmap** (InsightRX/PKPDmap): MAP Bayesian fitting via `get_map_estimates()`
11+
- **PKPDsim** (InsightRX/PKPDsim): PK/PD model objects and regimen handling
12+
13+
## Common Commands
14+
15+
```r
16+
# Load package for development
17+
devtools::load_all()
18+
19+
# Run all tests
20+
devtools::test()
21+
22+
# Run a single test file
23+
devtools::test(filter = "run_eval")
24+
25+
# Regenerate documentation (required after changing roxygen2 comments)
26+
devtools::document()
27+
28+
# Full package check
29+
devtools::check()
30+
31+
## Create documentation
32+
devtools::document()
33+
```
34+
35+
## Architecture
36+
37+
### Core Evaluation Flow
38+
39+
The main entry point is `run_eval()` (`R/run_eval.R`), which orchestrates:
40+
41+
1. **Model parsing** (`parse_model.R`): S3 dispatch handles PKPDsim objects, character strings (model library names), or PKPDsim object types. Extracts parameters, omega, ruv, fixed effects, and IOV bins.
42+
43+
2. **Data parsing** (`parse_input_data.R`): Splits NONMEM-style data by subject ID, creates regimen/observation/covariate structures, applies grouping logic.
44+
45+
3. **Core iterative loop** (`run_eval_core.R`): Called per-subject (parallelized via `furrr`). For each iterative observation group: applies sample weights, censors future covariates to prevent data leakage, calls `PKPDmap::get_map_estimates()`, and generates population/individual/iterative predictions.
46+
47+
4. **Statistics** (`calculate_stats.R`, `calculate_shrinkage.R`, `calculate_bayesian_impact.R`): Computes RMSE, NRMSE, MAPE, MPE, accuracy, shrinkage, and Bayesian impact metrics.
48+
49+
### Output Structure
50+
51+
`run_eval()` returns a list with class `"mipdeval_results"`:
52+
- `results`: Full prediction and parameter data
53+
- `mod_obj`: Parsed model information
54+
- `data`: Input dataset
55+
- `sim`: VPC simulations (if requested)
56+
- `stats_summ`: Summary statistics
57+
- `shrinkage`: Shrinkage metrics
58+
- `bayesian_impact`: Bayesian updating impact
59+
60+
### Key Design Patterns
61+
62+
- **Configuration helpers**: `vpc_options()`, `fit_options()`, `stats_summ_options()` return typed option lists—use these instead of raw lists for arguments.
63+
- **Sample weighting** (`calculate_fit_weights.R`): Multiple schemes (weight_all, weight_last_only, weight_last_two_only, weight_gradient_linear, weight_gradient_exponential).
64+
- **Grouping columns** (`add_grouping_column.R`): Group observations by dose or time range with `group_by_dose()` / `group_by_time()`.
65+
- **Parallelism**: `run.R` wraps `purrr::map()` with optional `furrr` parallelism.
66+
67+
### Test Infrastructure
68+
69+
Tests use testthat edition 3. `tests/testthat/setup.R` installs required PKPDsim model libraries (`pkvancothomson`, `pkvbusulfanshukla`) before tests run. Visual regression tests use `vdiffr`. Reference PsN proseval results live in `inst/extdata/vanco_thomson.csv` and are used to validate results within ~10% tolerance.
70+
71+
## Development Rules
72+
73+
74+
## General notes
75+
76+
- After any change that affects project structure, file locations, or architecture, update this file to reflect the new state.
77+
- **Documentation**: After making any change in function description, always update the package documentation by running `devtools::document()` to regenerate `man/` files. Files in `man/` themselves can be ignored.
78+

0 commit comments

Comments
 (0)