Source: https://github.com/aipoch/medical-research-skills
Adaptive Trial Simulator
Statistical simulation platform for designing and validating adaptive clinical trial designs in silico. Enables optimization of interim analysis strategies, sample size adaptation, and early stopping rules while maintaining Type I error control.
Quick Check
Use this command to verify that the packaged script entry point can be parsed before deeper execution.
python -m py_compile scripts/main.py
Audit-Ready Commands
Use these concrete commands for validation. They are intentionally self-contained and avoid placeholder paths.
python -m py_compile scripts/main.py
python scripts/main.py --help
python scripts/main.py --design group_sequential --n-simulations 50
python scripts/main.py --design adaptive_reestimate --n-simulations 25 --optimize
When to Use
- Use this skill when the task is to Design and simulate adaptive clinical trials with interim analyses.
- Use this skill for protocol design tasks that require explicit assumptions, bounded scope, and a reproducible output format.
- Use this skill when the response must stay inside the documented task boundary instead of expanding into adjacent work.
Workflow
- Confirm the user objective, required inputs, and non-negotiable constraints before doing detailed work.
- Validate that the request matches the documented scope and stop early if the task would require unsupported assumptions.
- Use the packaged script path or the documented reasoning path with only the inputs that are actually available.
- Return a structured result that separates assumptions, deliverables, risks, and unresolved items.
- If execution fails or inputs are incomplete, switch to the fallback path and state exactly what blocked full completion.
Features
- Design Simulation: Monte Carlo validation of adaptive designs
- Sample Size Re-estimation: Adapt sample size based on interim data
- Early Stopping Rules: Futility and efficacy boundary optimization
- Type I Error Control: Validate alpha spending strategies
- Multi-Arm Designs: Drop-the-loser and seamless Phase II/III
- Power Optimization: Identify designs with maximum power efficiency
Usage
Basic Usage
# Run standard group sequential design
python scripts/main.py
# Adaptive design with sample size re-estimation
python scripts/main.py --design adaptive_reestimate
# Optimize design parameters
python scripts/main.py --optimize
Parameters
| Parameter |
Type |
Default |
Required |
Description |
--design |
str |
group_sequential |
No |
Trial design type |
--n-simulations |
int |
10000 |
No |
Number of Monte Carlo simulations |
--sample-size |
int |
200 |
No |
Initial sample size per arm |
--effect-size |
float |
0.3 |
No |
Effect size (Cohen's d) |
--alpha |
float |
0.05 |
No |
Type I error rate |
--power |
float |
0.80 |
No |
Target statistical power |
--interim-looks |
int |
1 |
No |
Number of interim analyses |
--spending-function |
str |
obrien_fleming |
No |
Alpha spending function |
--reestimate-method |
str |
promising_zone |
No |
Sample size re-estimation method |
--output |
str |
results.json |
No |
Output file path |
--visualize |
flag |
False |
No |
Generate visualization charts |
--optimize |
flag |
False |
No |
Search for optimal design parameters |
Advanced Usage
# Full adaptive design with visualization
python scripts/main.py \
--design adaptive_reestimate \
--n-simulations 50000 \
--sample-size 250 \
--effect-size 0.35 \
--interim-looks 2 \
--spending-function obrien_fleming \
--visualize \
--output adaptive_results.json
Design Types
| Design Type |
Description |
Use Case |
| Group Sequential |
Fixed interim looks with stopping boundaries |
Standard adaptive trials |
| Adaptive Re-estimate |
Sample size adjustment based on interim data |
Uncertain effect size |
| Drop the Loser |
Multi-arm trials dropping inferior arms |
Phase II dose selection |
Spending Functions
| Function |
Characteristics |
Early Boundary |
| O'Brien-Fleming |
Conservative early |
High Z-scores early |
| Pocock |
Aggressive early |
Lower Z-scores throughout |
| Power Family |
Moderate (ρ=3) |
Balanced approach |
Output Example
{
"design_config": {
"design_type": "adaptive_reestimate",
"sample_size_per_arm": 200,
"effect_size": 0.3,
"alpha": 0.05,
"target_power": 0.8
},
"simulation_results": {
"power": 0.8234,
"type_i_error": 0.0481,
"expected_sample_size": 385.2,
"early_stop_rate": {
"efficacy": 0.1523,
"futility": 0.0841
}
}
}
Technical Difficulty: HIGH
References
- references/audit-reference.md - Audit-ready assumptions, supported design modes, and fallback boundaries for constrained runs
⚠️ AI independent acceptance status: manual inspection required
This skill requires:
- Python 3.8+ environment
- NumPy, SciPy, and Matplotlib packages
- Understanding of clinical trial statistics
Dependencies
pip install -r requirements.txt
Requirements
numpy>=1.20.0
scipy>=1.7.0
matplotlib>=3.4.0
Risk Assessment
| Risk Indicator |
Assessment |
Level |
| Code Execution |
Python scripts with mathematical calculations |
Medium |
| Network Access |
No network access |
Low |
| File System Access |
Writes simulation results |
Low |
| Instruction Tampering |
Statistical parameters could affect results |
Medium |
| Data Exposure |
No sensitive data exposure |
Low |
Security Checklist
Prerequisites
pip install -r requirements.txt
python scripts/main.py --help
Evaluation Criteria
Success Metrics
Test Cases
- Basic Simulation: Default parameters → Valid results
- Different Designs: All design types → Appropriate behavior
- Optimization Mode: --optimize flag → Finds optimal parameters
- Visualization: --visualize flag → Charts generated
Lifecycle Status
- Current Stage: Draft
- Next Review Date: 2026-03-15
- Known Issues: Type checking warnings with numpy arrays
- Planned Improvements:
- Bayesian adaptive designs
- Multi-arm multi-stage (MAMS) support
- Enhanced visualization options
References
Available in references/:
- Adaptive design statistical theory
- Regulatory guidance documents
- Alpha spending function literature
- Sample size re-estimation methods
Limitations
- Statistical Complexity: Requires biostatistics expertise
- Simulation Time: Large simulations may take hours
- Simplified Models: Does not capture all real-world complexities
- Regulatory Consultation: Results should be validated with regulators
⚠️ DISCLAIMER: This tool provides simulation results for research and planning purposes only. All clinical trial designs should be reviewed by qualified biostatisticians and regulatory experts before implementation.
Output Requirements
Every final response should make these items explicit when they are relevant:
- Objective or requested deliverable
- Inputs used and assumptions introduced
- Workflow or decision path
- Core result, recommendation, or artifact
- Constraints, risks, caveats, or validation needs
- Unresolved items and next-step checks
Error Handling
- If required inputs are missing, state exactly which fields are missing and request only the minimum additional information.
- If the task goes outside the documented scope, stop instead of guessing or silently widening the assignment.
- If
scripts/main.py fails, report the failure point, summarize what still can be completed safely, and provide a manual fallback.
- Do not fabricate files, citations, data, search results, or execution outcomes.
Input Validation
This skill accepts requests that match the documented purpose of adaptive-trial-simulator and include enough context to complete the workflow safely.
Do not continue the workflow when the request is out of scope, missing a critical input, or would require unsupported assumptions. Instead respond:
adaptive-trial-simulator only handles its documented workflow. Please provide the missing required inputs or switch to a more suitable skill.
Response Template
Use the following fixed structure for non-trivial requests:
- Objective
- Inputs Received
- Assumptions
- Workflow
- Deliverable
- Risks and Limits
- Next Checks
If the request is simple, you may compress the structure, but still keep assumptions and limits explicit when they affect correctness.
When Not to Use
- Do not proceed when required input files, identifiers, parameters, or context are missing — ask the user to provide them first.
- Do not assume capabilities beyond this skill's declared scope when the user requests external operations or inferences.
- Do not proceed without user confirmation when overwriting existing results, executing high-cost batch operations, or expanding task scope.
Required Inputs
| Field |
Required |
Format/Source |
Example |
If Missing |
| User task description |
Yes |
Text |
Research question, writing goal, analysis objective |
Stop and ask user to provide |
| Primary input material |
Depends on task |
Text, file path, ID, table, or literature |
PMID, PDF, CSV, DOCX, keywords, etc. |
Specify which material type is missing |
| Output preference |
No |
Text |
Language, format, target journal, template |
Use skill default format |
Output Contract
- Primary output: Structured result or target file aligned with this skill's objective.
- Optional output: Intermediate check notes, issue list, supplementary suggestions, or generated file paths.
- Format requirement: Unless the user specifies otherwise, prefer stable, reviewable Markdown or JSON; if the skill's bundled script requires a fixed format, use that format.
- If partially complete: Must explicitly mark as PARTIAL and state which steps are completed and which remain.
Failure Handling
- Missing critical input: Explicitly state which fields, files, or identifiers are missing and pause.
- Script, template, or resource execution failure: Report the failing step, likely cause, and recovery suggestions — do not silently degrade.
- Partial completion only: Return the verified portion first, then list remaining blockers and suggested next steps.
User Checkpoints
- Before executing batch processing, overwriting files, long-running searches, or multi-stage generation, confirm scope and output format with the user.
- Before proceeding when a key judgment is ambiguous, evidence is insufficient, or the workflow is entering the next stage, confirm with the user.
Quick Validation
- Check that key scripts, templates, or reference file paths this skill depends on exist.
- Check that the final output contains the core fields, sections, or files specified for this task.
- Check that results clearly mark assumptions, limitations, and incomplete items.
1---2name: adaptive-trial-simulator3description: Design and simulate adaptive clinical trials with interim analyses, decision rules, and operating-characteristic summaries; use when planning adaptive designs or comparing stopping, enrichment, or sample-size re-estimation strategies.4license: MIT5---6> **Source**: [https://github.com/aipoch/medical-research-skills](https://github.com/aipoch/medical-research-skills)
7
8# Adaptive Trial Simulator
9
10Statistical simulation platform for designing and validating adaptive clinical trial designs in silico. Enables optimization of interim analysis strategies, sample size adaptation, and early stopping rules while maintaining Type I error control.
11
12## Quick Check
13
14Use this command to verify that the packaged script entry point can be parsed before deeper execution.
15
16```bash
17python -m py_compile scripts/main.py
18```
19
20## Audit-Ready Commands
21
22Use these concrete commands for validation. They are intentionally self-contained and avoid placeholder paths.
23
24```bash
25python -m py_compile scripts/main.py
26python scripts/main.py --help
27python scripts/main.py --design group_sequential --n-simulations 50
28python scripts/main.py --design adaptive_reestimate --n-simulations 25 --optimize
29```
30
31## When to Use
32
33- Use this skill when the task is to Design and simulate adaptive clinical trials with interim analyses.
34- Use this skill for protocol design tasks that require explicit assumptions, bounded scope, and a reproducible output format.
35- Use this skill when the response must stay inside the documented task boundary instead of expanding into adjacent work.
36
37## Workflow
38
391. Confirm the user objective, required inputs, and non-negotiable constraints before doing detailed work.
402. Validate that the request matches the documented scope and stop early if the task would require unsupported assumptions.
413. Use the packaged script path or the documented reasoning path with only the inputs that are actually available.
424. Return a structured result that separates assumptions, deliverables, risks, and unresolved items.
435. If execution fails or inputs are incomplete, switch to the fallback path and state exactly what blocked full completion.
44
45## Features
46
47- **Design Simulation**: Monte Carlo validation of adaptive designs
48- **Sample Size Re-estimation**: Adapt sample size based on interim data
49- **Early Stopping Rules**: Futility and efficacy boundary optimization
50- **Type I Error Control**: Validate alpha spending strategies
51- **Multi-Arm Designs**: Drop-the-loser and seamless Phase II/III
52- **Power Optimization**: Identify designs with maximum power efficiency
53
54## Usage
55
56### Basic Usage
57
58```text
59# Run standard group sequential design
60python scripts/main.py
61
62# Adaptive design with sample size re-estimation
63python scripts/main.py --design adaptive_reestimate
64
65# Optimize design parameters
66python scripts/main.py --optimize
67```
68
69### Parameters
70
71| Parameter | Type | Default | Required | Description |
72|-----------|------|---------|----------|-------------|
73| `--design` | str | group_sequential | No | Trial design type |
74| `--n-simulations` | int | 10000 | No | Number of Monte Carlo simulations |
75| `--sample-size` | int | 200 | No | Initial sample size per arm |
76| `--effect-size` | float | 0.3 | No | Effect size (Cohen's d) |
77| `--alpha` | float | 0.05 | No | Type I error rate |
78| `--power` | float | 0.80 | No | Target statistical power |
79| `--interim-looks` | int | 1 | No | Number of interim analyses |
80| `--spending-function` | str | obrien_fleming | No | Alpha spending function |
81| `--reestimate-method` | str | promising_zone | No | Sample size re-estimation method |
82| `--output` | str | results.json | No | Output file path |
83| `--visualize` | flag | False | No | Generate visualization charts |
84| `--optimize` | flag | False | No | Search for optimal design parameters |
85
86### Advanced Usage
87
88```text
89# Full adaptive design with visualization
90python scripts/main.py \
91 --design adaptive_reestimate \
92 --n-simulations 50000 \
93 --sample-size 250 \
94 --effect-size 0.35 \
95 --interim-looks 2 \
96 --spending-function obrien_fleming \
97 --visualize \
98 --output adaptive_results.json
99```
100
101## Design Types
102
103| Design Type | Description | Use Case |
104|-------------|-------------|----------|
105| **Group Sequential** | Fixed interim looks with stopping boundaries | Standard adaptive trials |
106| **Adaptive Re-estimate** | Sample size adjustment based on interim data | Uncertain effect size |
107| **Drop the Loser** | Multi-arm trials dropping inferior arms | Phase II dose selection |
108
109## Spending Functions
110
111| Function | Characteristics | Early Boundary |
112|----------|----------------|----------------|
113| **O'Brien-Fleming** | Conservative early | High Z-scores early |
114| **Pocock** | Aggressive early | Lower Z-scores throughout |
115| **Power Family** | Moderate (ρ=3) | Balanced approach |
116
117## Output Example
118
119```json
120{
121 "design_config": {
122 "design_type": "adaptive_reestimate",
123 "sample_size_per_arm": 200,
124 "effect_size": 0.3,
125 "alpha": 0.05,
126 "target_power": 0.8
127 },
128 "simulation_results": {
129 "power": 0.8234,
130 "type_i_error": 0.0481,
131 "expected_sample_size": 385.2,
132 "early_stop_rate": {
133 "efficacy": 0.1523,
134 "futility": 0.0841
135 }
136 }
137}
138```
139
140## Technical Difficulty: **HIGH**
141
142## References
143
144- [references/audit-reference.md](references/audit-reference.md) - Audit-ready assumptions, supported design modes, and fallback boundaries for constrained runs
145
146⚠️ **AI independent acceptance status**: manual inspection required
147This skill requires:
148- Python 3.8+ environment
149- NumPy, SciPy, and Matplotlib packages
150- Understanding of clinical trial statistics
151
152## Dependencies
153
154```text
155pip install -r requirements.txt
156```
157
158### Requirements
159
160```
161numpy>=1.20.0
162scipy>=1.7.0
163matplotlib>=3.4.0
164```
165
166## Risk Assessment
167
168| Risk Indicator | Assessment | Level |
169|----------------|------------|-------|
170| Code Execution | Python scripts with mathematical calculations | Medium |
171| Network Access | No network access | Low |
172| File System Access | Writes simulation results | Low |
173| Instruction Tampering | Statistical parameters could affect results | Medium |
174| Data Exposure | No sensitive data exposure | Low |
175
176## Security Checklist
177
178- [x] No hardcoded credentials or API keys
179- [x] No unauthorized file system access
180- [x] Output does not expose sensitive information
181- [x] Input parameters validated
182- [x] Error messages sanitized
183- [x] Dependencies audited
184
185## Prerequisites
186
187```text
188pip install -r requirements.txt
189python scripts/main.py --help
190```
191
192## Evaluation Criteria
193
194### Success Metrics
195- [ ] Simulations run without errors
196- [ ] Type I error controlled at nominal level
197- [ ] Power estimates are accurate
198- [ ] Visualizations generated correctly
199
200### Test Cases
2011. **Basic Simulation**: Default parameters → Valid results
2022. **Different Designs**: All design types → Appropriate behavior
2033. **Optimization Mode**: --optimize flag → Finds optimal parameters
2044. **Visualization**: --visualize flag → Charts generated
205
206## Lifecycle Status
207
208- **Current Stage**: Draft
209- **Next Review Date**: 2026-03-15
210- **Known Issues**: Type checking warnings with numpy arrays
211- **Planned Improvements**:
212 - Bayesian adaptive designs
213 - Multi-arm multi-stage (MAMS) support
214 - Enhanced visualization options
215
216## References
217
218Available in `references/`:
219- Adaptive design statistical theory
220- Regulatory guidance documents
221- Alpha spending function literature
222- Sample size re-estimation methods
223
224## Limitations
225
226- **Statistical Complexity**: Requires biostatistics expertise
227- **Simulation Time**: Large simulations may take hours
228- **Simplified Models**: Does not capture all real-world complexities
229- **Regulatory Consultation**: Results should be validated with regulators
230
231---
232
233**⚠️ DISCLAIMER: This tool provides simulation results for research and planning purposes only. All clinical trial designs should be reviewed by qualified biostatisticians and regulatory experts before implementation.**
234
235## Output Requirements
236
237Every final response should make these items explicit when they are relevant:
238
239- Objective or requested deliverable
240- Inputs used and assumptions introduced
241- Workflow or decision path
242- Core result, recommendation, or artifact
243- Constraints, risks, caveats, or validation needs
244- Unresolved items and next-step checks
245
246## Error Handling
247
248- If required inputs are missing, state exactly which fields are missing and request only the minimum additional information.
249- If the task goes outside the documented scope, stop instead of guessing or silently widening the assignment.
250- If `scripts/main.py` fails, report the failure point, summarize what still can be completed safely, and provide a manual fallback.
251- Do not fabricate files, citations, data, search results, or execution outcomes.
252
253## Input Validation
254
255This skill accepts requests that match the documented purpose of `adaptive-trial-simulator` and include enough context to complete the workflow safely.
256
257Do not continue the workflow when the request is out of scope, missing a critical input, or would require unsupported assumptions. Instead respond:
258
259> `adaptive-trial-simulator` only handles its documented workflow. Please provide the missing required inputs or switch to a more suitable skill.
260
261## Response Template
262
263Use the following fixed structure for non-trivial requests:
264
2651. Objective
2662. Inputs Received
2673. Assumptions
2684. Workflow
2695. Deliverable
2706. Risks and Limits
2717. Next Checks
272
273If the request is simple, you may compress the structure, but still keep assumptions and limits explicit when they affect correctness.
274
275## When Not to Use
276
277- Do not proceed when required input files, identifiers, parameters, or context are missing — ask the user to provide them first.
278- Do not assume capabilities beyond this skill's declared scope when the user requests external operations or inferences.
279- Do not proceed without user confirmation when overwriting existing results, executing high-cost batch operations, or expanding task scope.
280
281## Required Inputs
282
283| Field | Required | Format/Source | Example | If Missing |
284|---|---|---|---|---|
285| User task description | Yes | Text | Research question, writing goal, analysis objective | Stop and ask user to provide |
286| Primary input material | Depends on task | Text, file path, ID, table, or literature | PMID, PDF, CSV, DOCX, keywords, etc. | Specify which material type is missing |
287| Output preference | No | Text | Language, format, target journal, template | Use skill default format |
288
289## Output Contract
290
291- Primary output: Structured result or target file aligned with this skill's objective.
292- Optional output: Intermediate check notes, issue list, supplementary suggestions, or generated file paths.
293- Format requirement: Unless the user specifies otherwise, prefer stable, reviewable Markdown or JSON; if the skill's bundled script requires a fixed format, use that format.
294- If partially complete: Must explicitly mark as PARTIAL and state which steps are completed and which remain.
295
296## Failure Handling
297
298- Missing critical input: Explicitly state which fields, files, or identifiers are missing and pause.
299- Script, template, or resource execution failure: Report the failing step, likely cause, and recovery suggestions — do not silently degrade.
300- Partial completion only: Return the verified portion first, then list remaining blockers and suggested next steps.
301
302## User Checkpoints
303
304- Before executing batch processing, overwriting files, long-running searches, or multi-stage generation, confirm scope and output format with the user.
305- Before proceeding when a key judgment is ambiguous, evidence is insufficient, or the workflow is entering the next stage, confirm with the user.
306
307## Quick Validation
308
309- Check that key scripts, templates, or reference file paths this skill depends on exist.
310- Check that the final output contains the core fields, sections, or files specified for this task.
311- Check that results clearly mark assumptions, limitations, and incomplete items.