{
  "id": "fda-ir-replication-instructions",
  "title": "Plan a replication of the primary ADAS-Cog table from ADSL and ADQSADAS, then run the plan in R",
  "study": {
    "name": "CDISCPILOT01 (CDISC SDTM/ADaM Pilot Project, xanomeline TTS in mild to moderate Alzheimer's disease)",
    "source_url": "https://github.com/cdisc-org/sdtm-adam-pilot-project",
    "licence_note": "Datasets, define.xml, SAP and CSR are CDISC Pilot Project materials, used unmodified and attributed to CDISC under the Terms of Use in the repository README (no modification, no sale of the data, attribution required). The study is a CDISC mock submission with fictional dates. The agency request in this example is INVENTED for this example, not a real document. Not legal advice."
  },
  "task": "INVENTED for this example, not a real document: a paraphrased agency request asks for step-by-step instructions and simplified code showing how CSR Table 14-3.01 (primary ADAS-Cog (11) change from baseline at Week 24, LOCF) was derived from ADSL and ADQSADAS. The model drafts the response plan from real excerpts (variable labels, define.xml comments, SAP text). The check: execute the plan step by step in R on the unmodified xpt files and see whether the Table 14-3.01 values are reproduced. Pass or fail.",
  "time_to_try_minutes": "About 45 (estimate, not measured), including pasting the excerpts and implementing the plan yourself",
  "good": {
    "input_excerpt": "[INVENTED for this example, not a real document. Paraphrase of an agency request, written by the page author.]\n\"Please provide step-by-step instructions, with simplified code, showing how the primary analysis of the change from baseline in ADAS-Cog (11) at Week 24 (LOCF) was derived from the submitted ADaM datasets ADSL and ADQSADAS: the summary statistics, the test of dose response, and the pairwise treatment comparisons.\"\n\n[REAL: CDISC SDTM/ADaM Pilot Project, CDISCPILOT01. Variable labels read from adam_adsl.xpt and adam_adqsadas.xpt; comments quoted from adam_define.xml.]\nADSL (one row per subject, 254 rows): USUBJID Unique Subject Identifier; SITEGR1 Pooled Site Group 1; TRT01P Planned Treatment for Period 01 (values Placebo, Xanomeline Low Dose, Xanomeline High Dose); TRT01PN Planned Treatment for Period 01 (N); ITTFL Intent-to-Treat Population Flag; SAFFL Safety Population Flag; EFFFL Efficacy Population Flag; COMP24FL Completers of Week 24 Population Flag.\nADQSADAS (12463 rows): USUBJID; SITEGR1 Pooled Site Group 1 (comment: ADSL.SITEGR1); TRTP Planned Treatment; TRTPN Planned Treatment (N); EFFFL Efficacy Population Flag; COMP24FL; AVISIT Analysis Visit (comment: \"Derived based on windowing algorithm described in SAP, Section 8.2\"); AVISITN Analysis Visit (N); PARAM Parameter; PARAMCD Parameter Code (value ACTOT is labelled \"Adas-Cog(11) Subscore\"; ACITM01 to ACITM14 are the items); AVAL Analysis Value; BASE Baseline Value (comment: \"QS.QSSTRESN when QS.QSBLFL=Y (QS.VISITNUM=3)\"); CHG, label \"Baseline Value\" in the file, comment \"AVAL - BASE\"; ABLFL; ANL01FL Analysis Record Flag 01 (comment: \"If multiple visits fall into the same visit window, then the one closest to the target date is chosen for analysis. These are flagged with ANL01FL=Y.\"); DTYPE Derivation Type (for ACTOT, comment: \"Value: LOCF denotes that the LOCF imputation method was used to impute the value for the given parameter and analysis visit.\").\n\n[REAL: Statistical Analysis Plan, CSR Appendix 9 (CSR PDF pages 424 to 429; SAP pp. 8, 9, 13)]\nSAP 6: \"Efficacy population: All patients who were randomized and took drug, and have at least 1 post-baseline measure for both ADAS-Cog and CIBIC+.\"\nSAP 7.1: \"Sites that enroll fewer than 3 patients in any one treatment group will be grouped together, with a new pooled site identifier assigned for the purpose of analysis.\"\nSAP 8.1: \"Missing postbaseline efficacy values will be imputed using last observation carried forward (LOCF).\"\nSAP 10.1.1: \"The primary analysis of the ADAS-Cog (11) at Week 24 will use the efficacy population with LOCF imputation for any missing values at Week 24. ... an ANCOVA model will be used with the baseline score, site, and treatment included as independent variables. Treatment will be included as a continuous variable, and results for a test of dose response will be produced. Interaction terms will not be investigated. If the test for dose response is statistically significant, pairwise comparisons among the 3 groups will be performed and evaluated at a significance level of 0.05.\"\n\n[REAL: result to replicate, in words] CSR Table 14-3.01, \"Primary Endpoint Analysis: ADAS Cog (11) - Change from Baseline to Week 24 - LOCF\", Population: Efficacy. It shows, by treatment group, n, mean (SD) and median (range) for baseline, Week 24 and change from baseline; a dose-response p-value; and for each pairwise comparison a p-value, the difference of least-squares means (SE) and a 95% confidence interval. Footnotes: \"[1] Based on Analysis of covariance (ANCOVA) model with treatment and site group as factors and baseline value as a covariate. [2] Test for a non-zero coefficient for treatment (dose) as a continuous variable. [3] Pairwise comparison with treatment as a categorical variable: p-values without adjustment for multiple comparisons.\"\n\nSource: CDISC SDTM/ADaM Pilot Project (https://github.com/cdisc-org/sdtm-adam-pilot-project), used unmodified, attribution to CDISC. Excerpts shortened where marked \"...\".",
    "prompt": "You are a senior biostatistician preparing a response plan to an agency information request. Use only the INPUT below. Where something needed to reproduce the result is not in the INPUT, say so in OPEN QUESTIONS instead of filling it in. Do not state any numerical result. Your plan is a draft for a qualified biostatistician to implement and check.\n\nGive me:\nA. A numbered procedure from the submitted datasets to the requested result: step, action, dataset and variables, and which sentence of the INPUT supports it.\nB. A pseudo-code outline, precise enough that a programmer could implement each step in R or SAS without asking you anything (filters, record selection, model terms, how each requested statistic is obtained). No macros.\nC. The datasets and variables read.\nD. A pre-send checklist for the team.\nE. Neutral cover text, 3 to 5 sentences, no claims about study conclusions.\nOPEN QUESTIONS, each once.",
    "output": "DRAFT response plan for a qualified biostatistician to implement and check. No numerical results are stated. Items the INPUT does not specify are in OPEN QUESTIONS and are not filled in.\n\nQuote labels used below:\n- REQ = the agency request sentence.\n- SAP6, SAP7.1, SAP8.1 and SAP10.1.1 = the SAP sections quoted in the INPUT.\n- FN1, FN2, FN3 = the Table 14-3.01 footnotes.\n- T = the description of Table 14-3.01 in the INPUT.\n- DEF:<var> = the define.xml comment quoted for that variable.\n\nA. NUMBERED PROCEDURE\n\n| # | Action | Dataset and variables | Support |\n|---|--------|----------------------|---------|\n| 1 | Read ADSL. Keep subjects with EFFFL = \"Y\". This is the analysis population. | ADSL: USUBJID, EFFFL, TRT01P, TRT01PN, SITEGR1 | SAP10.1.1 (\"will use the efficacy population\"); SAP6; T (\"Population: Efficacy\") |\n| 2 | Read ADQSADAS. Keep rows where PARAMCD = \"ACTOT\" (ADAS-Cog(11) total). Do not use the item parameters ACITM01 to ACITM14. | ADQSADAS: PARAMCD, PARAM | REQ; the PARAMCD label in the INPUT |\n| 3 | Select the Week 24 analysis record with LOCF. Keep rows for the Week 24 analysis visit (AVISIT/AVISITN). Keep both observed rows and rows with DTYPE = \"LOCF\". Keep ANL01FL = \"Y\" where the flag is populated. Check that this leaves exactly one row per subject. See OPEN QUESTIONS 2 and 3. | ADQSADAS: AVISIT, AVISITN, DTYPE, ANL01FL, AVAL, BASE, CHG | SAP10.1.1 (\"LOCF imputation for any missing values at Week 24\"); SAP8.1; DEF:DTYPE; DEF:ANL01FL; DEF:AVISIT |\n| 4 | Restrict step 3 to subjects selected in step 1 (inner join on USUBJID). Take treatment and site group from ADSL. Do not filter on COMP24FL, because LOCF imputation implies non-completers are included. | ADSL.USUBJID, TRT01P, TRT01PN, SITEGR1 | SAP10.1.1; DEF:SITEGR1 (\"ADSL.SITEGR1\") |\n| 5 | Use BASE as the baseline covariate. It is the QS baseline-flagged value at VISITNUM = 3. Take change from baseline as CHG, which per DEF:CHG is AVAL − BASE. Optionally recompute AVAL − BASE and compare with CHG. See OPEN QUESTION 6. | ADQSADAS: BASE, AVAL, CHG | DEF:BASE; DEF:CHG |\n| 6 | Summary statistics by treatment group. For baseline (BASE), Week 24 (AVAL) and change (CHG), compute n, mean, SD, median, minimum and maximum. | Analysis dataset from step 4 | REQ (\"summary statistics\"); T |\n| 7 | Fit the dose-response ANCOVA. Outcome is CHG. Terms are BASE, site group (categorical) and treatment as a numeric (continuous) variable. No interaction terms. Take the p-value for the treatment coefficient (a non-zero-coefficient test). | CHG, BASE, SITEGR1, TRT01PN (or a dose score, see OPEN QUESTION 4) | SAP10.1.1 (\"baseline score, site, and treatment\"; \"Treatment will be included as a continuous variable\"; \"Interaction terms will not be investigated\"); FN2; REQ (\"test of dose response\") |\n| 8 | Fit the pairwise ANCOVA. Same model, but treatment is categorical. | CHG, BASE, SITEGR1, TRT01P | FN3 (\"treatment as a categorical variable\"); FN1 |\n| 9 | From step 8, obtain the least-squares means by treatment. Form the 3 pairwise differences, each with its SE, a 95% CI and a p-value. Apply no multiplicity adjustment. | Step 8 model | FN3 (\"without adjustment for multiple comparisons\"); T; REQ (\"pairwise treatment comparisons\") |\n| 10 | Apply the SAP gating rule: pairwise comparisons are performed if the dose-response test is significant at the 0.05 level. Document how the team applies this against what Table 14-3.01 displays. See OPEN QUESTION 8. | Outputs of steps 7 and 9 | SAP10.1.1 (\"If the test for dose response is statistically significant, pairwise comparisons ... 0.05\") |\n\nB. PSEUDO-CODE (R or SAS equivalent, no macros)\n\n```\n# 1. Population\nadsl_eff  = ADSL where EFFFL == \"Y\"\n              keep USUBJID, TRT01P, TRT01PN, SITEGR1\n\n# 2-3. Records\nq = ADQSADAS where PARAMCD == \"ACTOT\"\n              and AVISITN == <Week 24 code, OPEN Q2>\n              and ANL01FL == \"Y\"           # drop this condition if OPEN Q3 shows LOCF rows have it blank\n              # DTYPE not filtered: observed rows (blank) and DTYPE==\"LOCF\" rows are both kept\n              keep USUBJID, AVAL, BASE, CHG, DTYPE\ncheck: count rows per USUBJID in q; stop and report if any subject has != 1 row,\n       or if an efficacy subject has 0 rows\n\n# 4. Merge (inner join on USUBJID)\nd = adsl_eff INNER JOIN q BY USUBJID\nd$site = factor(SITEGR1)\nd$trt  = factor(TRT01P, levels = c order by TRT01PN)   # Placebo, Low, High\nd$dose = <numeric score, OPEN Q4>\ncheck: drop/flag rows with missing BASE or CHG; report the count (OPEN Q5)\n\n# 5. (optional) check CHG == AVAL - BASE\n\n# 6. Descriptives, by trt (and for each of BASE, AVAL, CHG)\nn, mean, sd, median, min, max\n# R: aggregate/tapply; SAS: PROC MEANS CLASS trt; VAR BASE AVAL CHG;\n# the n/mean/std/median/min/max statistics; use the same d for all three variables\n\n# 7. Dose response model\nfit_dose = linear model: CHG ~ BASE + site + dose      # R: lm\n# SAS: PROC GLM; CLASS site; MODEL CHG = BASE site dose / SOLUTION;\n# test statistic: t-test for the coefficient on dose (null hypothesis: coefficient = 0)\n# report the p-value; state sidedness and SS type (OPEN Q7)\n\n# 8. Categorical model\nfit_cat = linear model: CHG ~ BASE + site + trt        # R: lm\n# SAS: PROC GLM; CLASS site trt; MODEL CHG = BASE site trt;\n\n# 9. LS means and differences\nlsm = least-squares means of trt, at the mean of BASE, site levels weighted per OPEN Q9\n      # R: emmeans(fit_cat, ~ trt); SAS: LSMEANS trt / PDIFF CL ALPHA=0.05 STDERR ADJUST=NONE;\nfor each pair (Low-Placebo, High-Placebo, High-Low; direction per OPEN Q10):\n    diff, SE(diff), 95% CI (t-based, residual df), unadjusted p-value\n    # R: contrast(lsm, method = pairwise, adjust = \"none\"); confint(...)\n\n# 10. Output assembly\ntable columns: trt; n; mean(SD) and median(min,max) for BASE, AVAL, CHG;\n               dose-response p; per-pair p, diff (SE), 95% CI\n```\n\nC. DATASETS AND VARIABLES READ\n\n- ADSL: USUBJID, EFFFL, TRT01P, TRT01PN, SITEGR1. Other flags (ITTFL, SAFFL, COMP24FL) are read only for cross-checks.\n- ADQSADAS: USUBJID, PARAMCD, PARAM, AVISIT, AVISITN, AVAL, BASE, CHG, ABLFL, ANL01FL, DTYPE. Optionally TRTP, TRTPN, SITEGR1 and EFFFL for consistency checks against ADSL.\n\nD. PRE-SEND CHECKLIST\n\n- Every OPEN QUESTION is resolved by the sponsor or study team, or is stated as an assumption in the response.\n- The efficacy-population count and the per-group n reconcile to Table 14-3.01 and to the SAP definition.\n- There is exactly one analysis row per efficacy subject at Week 24.\n- Reproduced values match the CSR table. The numbers are not to be pasted from this draft.\n- The code was run from the submitted ADaM datasets only, with no other inputs.\n- The code was independently reviewed (second programmer).\n- Variable names and flag values in the instructions match the define.xml.\n- Model terms match FN1 to FN3 and SAP10.1.1.\n- The CHG label discrepancy and any ADaM metadata issues are noted or explained.\n- The software and version are stated.\n- The code is simplified as requested but still runs.\n- The cover text contains no study conclusions.\n- Regulatory affairs / quality review has signed off.\n\nE. COVER TEXT\n\n\"Please find enclosed step-by-step instructions and simplified code showing how the primary analysis of change from baseline in ADAS-Cog (11) at Week 24 (LOCF) was derived from the submitted ADaM datasets ADSL and ADQSADAS. The material covers the population selection, the record selection and imputation, the summary statistics, the test of dose response and the pairwise treatment comparisons. The steps follow the Statistical Analysis Plan and the footnotes of CSR Table 14-3.01. The code is a simplified illustration of the derivation. Please let us know if further detail on any step would be useful.\"\n\nOPEN QUESTIONS\n\n1. The INPUT does not give the source of EFFFL or confirm that it implements SAP6, including the CIBIC+ requirement, because no CIBIC+ dataset was submitted. Confirm that EFFFL = \"Y\" is the population used.\n2. The AVISIT and AVISITN values for Week 24 are not given. The windowing algorithm (SAP Section 8.2) is referenced but not quoted.\n3. It is not stated whether DTYPE = \"LOCF\" rows carry ANL01FL = \"Y\", or how an observed Week 24 row and a LOCF row interact for the same subject. The rule for choosing one row per subject is not stated.\n4. The numeric coding of treatment for the dose-response test is not given. The values of TRTPN or TRT01PN, the dose scores and the spacing are not in the INPUT. It is not stated whether TRTPN is used as the continuous variable.\n5. The handling of subjects with missing BASE or no post-baseline record is not stated.\n6. CHG has the label \"Baseline Value\" in the file, with the comment \"AVAL - BASE\". Confirm that the values are AVAL − BASE and that the label is a metadata error.\n7. The test sidedness, the sums-of-squares type, and the degrees of freedom are not stated.\n8. Whether Table 14-3.01 shows the pairwise comparisons regardless of the dose-response result is not stated, and neither is the dose-response outcome.\n9. The weighting of site levels in the LS means is not stated.\n10. The direction of each difference (which group is subtracted from which) is not stated.\n11. The treatment variable is TRT01P (ADSL) or TRTP (ADQSADAS), both planned. It is not stated that TRTP is identical to TRT01P, nor what the TRTP values are.\n12. The software, the version and the procedures used for the original analysis are not given.\n13. The SAP gives no pooling algorithm beyond SAP7.1. Confirm that SITEGR1 already applies it, so no re-pooling is needed.\n14. It is not stated whether baseline and Week 24 summaries use the same subjects as the model (the full analysis set at Week 24) or each variable's own non-missing subjects.\n\n---\nWHAT HAPPENS WHEN THE PLAN IS EXECUTED IN R (replicate_14-3-01.R, unmodified data, run 2026-10-21):\n\nStep 1 efficacy subjects in ADSL: 234 \nStep 3 rows: 254  subjects: 254  DTYPE:  155; LOCF 99 \nStep 4 joined rows: 234  efficacy subjects with no Week 24 row: 0 \nDose scores used: 0, 54, 81 \nMissing BASE or CHG: 0 \nStep 5 check CHG == AVAL - BASE: TRUE \nOK       Placebo BASE n                           replicated=79             CSR=79\nOK       Placebo BASE meansd                      replicated=24.1 (12.19)   CSR=24.1 (12.19)\nOK       Placebo BASE medrange                    replicated=21.0 (5;61)    CSR=21.0 (5;61)\nOK       Placebo AVAL n                           replicated=79             CSR=79\nOK       Placebo AVAL meansd                      replicated=26.7 (13.79)   CSR=26.7 (13.79)\nOK       Placebo AVAL medrange                    replicated=24.0 (5;62)    CSR=24.0 (5;62)\nOK       Placebo CHG n                            replicated=79             CSR=79\nOK       Placebo CHG meansd                       replicated=2.5 (5.80)     CSR=2.5 (5.80)\nOK       Placebo CHG medrange                     replicated=2.0 (-11;16)   CSR=2.0 (-11;16)\nOK       Xanomeline Low Dose BASE n               replicated=81             CSR=81\nOK       Xanomeline Low Dose BASE meansd          replicated=24.4 (12.92)   CSR=24.4 (12.92)\nOK       Xanomeline Low Dose BASE medrange        replicated=21.0 (5;57)    CSR=21.0 (5;57)\nOK       Xanomeline Low Dose AVAL n               replicated=81             CSR=81\nOK       Xanomeline Low Dose AVAL meansd          replicated=26.4 (13.18)   CSR=26.4 (13.18)\nOK       Xanomeline Low Dose AVAL medrange        replicated=25.0 (6;62)    CSR=25.0 (6;62)\nOK       Xanomeline Low Dose CHG n                replicated=81             CSR=81\nOK       Xanomeline Low Dose CHG meansd           replicated=2.0 (5.55)     CSR=2.0 (5.55)\nOK       Xanomeline Low Dose CHG medrange         replicated=2.0 (-11;17)   CSR=2.0 (-11;17)\nOK       Xanomeline High Dose BASE n              replicated=74             CSR=74\nOK       Xanomeline High Dose BASE meansd         replicated=21.3 (11.74)   CSR=21.3 (11.74)\nOK       Xanomeline High Dose BASE medrange       replicated=18.0 (3;57)    CSR=18.0 (3;57)\nOK       Xanomeline High Dose AVAL n              replicated=74             CSR=74\nOK       Xanomeline High Dose AVAL meansd         replicated=22.8 (12.48)   CSR=22.8 (12.48)\nOK       Xanomeline High Dose AVAL medrange       replicated=20.0 (3;62)    CSR=20.0 (3;62)\nOK       Xanomeline High Dose CHG n               replicated=74             CSR=74\nOK       Xanomeline High Dose CHG meansd          replicated=1.5 (4.26)     CSR=1.5 (4.26)\nOK       Xanomeline High Dose CHG medrange        replicated=1.0 (-7;13)    CSR=1.0 (-7;13)\nOK       p dose response                          replicated=0.245          CSR=0.245\nOK       Low-Pbo p                                replicated=0.569          CSR=0.569\nOK       Low-Pbo diff (SE)                        replicated=-0.5 (0.82)    CSR=-0.5 (0.82)\nOK       Low-Pbo 95% CI                           replicated=(-2.1;1.1)     CSR=(-2.1;1.1)\nOK       High-Pbo p                               replicated=0.233          CSR=0.233\nOK       High-Pbo diff (SE)                       replicated=-1.0 (0.84)    CSR=-1.0 (0.84)\nOK       High-Pbo 95% CI                          replicated=(-2.7;0.7)     CSR=(-2.7;0.7)\nOK       High-Low p                               replicated=0.520          CSR=0.520\nOK       High-Low diff (SE)                       replicated=-0.5 (0.84)    CSR=-0.5 (0.84)\nOK       High-Low 95% CI                          replicated=(-2.2;1.1)     CSR=(-2.2;1.1)\n\n37 of 37 cells match, 0 mismatch.\nRESULT: PASS\n\nSensitivity (not part of the plan): dose scores 0,1,2 instead of 0,54,81 give dose-response p = 0.232 \nSensitivity (not part of the plan): Week 24 ACTOT rows for efficacy subjects WITHOUT the ANL01FL filter: 237  subjects: 234 ",
    "trim_note": "The plan is verbatim and untrimmed. The R run output is shown in full. The plan is pseudo-code, as the prompt asked; replicate_14-3-01.R is the builder's translation of it, and each point where the plan left a choice open is marked CHOICE in the script. The plan was produced by a fresh subagent that saw only the excerpt and prompt; it was told not to use tools, which cannot be enforced from outside. The excerpt is shorter than the SAP text: omitted sentences are marked with an ellipsis in SAP 10.1.1 only."
  },
  "bad": {
    "input": "FDA sent us an information request. They want step by step instructions for how we got the primary ADAS-Cog result from the ADaM datasets, plus simplified code. Can you write the response plan?",
    "output": "RESPONSE PLAN: FDA information request on the primary ADAS-Cog analysis (ADaM to result)\n\nI have not seen your SAP, ADaM specs, or programs. Everything below is a template built on common conventions (ADSL, ADQS or ADADAS, MMRM on change from baseline). Items marked [CONFIRM] must be checked against your actual SAP and datasets before anything goes to FDA.\n\n1. Triage and governance (Day 0-2)\n- Log the IR in the regulatory tracker, with its number, date received, and due date. Confirm the response deadline with Regulatory Affairs.\n- Name owners: Regulatory lead (submission and cover letter), Lead biostatistician (method and text), Independent programmer (QC), Clinical lead (context review), and QA/Medical writing.\n- Clarify scope with FDA through the regulatory lead if anything is ambiguous. Questions to settle: which study or studies, which ADAS-Cog version (11 or 13), which analysis (primary endpoint, timepoint), and whether they want the SAS code, the R code, or just a narrative.\n- Freeze the exact datasets and programs that were submitted. Record versions, checksums, and the define.xml. Do not use any post-submission data cuts.\n\n2. Reproduce the result first (Day 2-5)\n- Rerun the submitted programs on the submitted ADaM. Confirm the primary estimate, CI, and p-value match the CSR and submitted tables exactly.\n- If they do not match, stop and escalate before writing anything. Do not send FDA code that has not reproduced the reported number.\n- Have the independent programmer reproduce the result from the simplified code too (step 4).\n\n3. Step-by-step description (the narrative section)\nWrite this as numbered steps, each citing the dataset, variables, and the SAP section.\n\nStep 1. Source datasets: ADSL (subject-level; population flags and treatment) and the ADAS-Cog analysis dataset (ADQS/ADADAS: one record per subject, parameter, and visit). Merge key: USUBJID. [CONFIRM names]\nStep 2. Analysis population: keep records where the population flag (for example, ITTFL = \"Y\" or FASFL = \"Y\") is set. State the number of subjects. [CONFIRM flag]\nStep 3. Endpoint selection: PARAMCD = ADAS-Cog total score (11 or 13) [CONFIRM], with ANL01FL = \"Y\" so only the analysis-flagged records are used (the one valid record per visit after windowing and any imputation rules).\nStep 4. Baseline and change from baseline: use BASE and CHG as derived in ADaM (CHG = AVAL - BASE). State the baseline definition (last non-missing value before first dose) and note that ADAS-Cog scores run 0-70 or 0-85, where higher means worse.\nStep 5. Missing data handling: describe exactly what the SAP specifies (for example, MMRM under MAR with no imputation, or LOCF or multiple imputation). Describe any ADaM derivation of imputed values (DTYPE) and which records carry it. [CONFIRM]\nStep 6. Model: for an MMRM, the response is CHG at each post-baseline visit. Fixed effects are treatment, visit, treatment-by-visit, baseline, and baseline-by-visit, plus any stratification factors (for example, region or baseline severity). The covariance is unstructured, or the fallback hierarchy named in the SAP. Degrees of freedom use Kenward-Roger. [CONFIRM all of this]\nStep 7. Primary contrast: the LS mean difference (active minus placebo) at the primary timepoint (for example, Week 24), with its 95% CI and two-sided p-value. State the alpha level and any multiplicity procedure.\nStep 8. Output: map each number to the table or figure in the CSR and the submitted TLF program name.\nStep 9. Sensitivity analyses, if FDA asked, or a pointer to those already submitted.\n\n4. Simplified code (provide in SAS if that is what you submitted; R shown as an alternative)\nThese are illustrative skeletons. Replace names with your actual ones and verify they reproduce the submitted results.\n\nSAS\n```\n/* 1-4: build analysis set */\nproc sql;\n  create table anl as\n  select a.usubjid, a.trt01p, a.region, b.avisitn, b.avisit, b.base, b.chg\n  from adsl as a\n  inner join adqs as b on a.usubjid = b.usubjid\n  where a.ittfl = \"Y\"\n    and b.paramcd = \"ADAS13\"      /* [CONFIRM] */\n    and b.anl01fl = \"Y\"\n    and b.avisitn > 0;\nquit;\n\n/* 5-7: MMRM */\nproc mixed data=anl method=reml;\n  class usubjid trt01p(ref=\"Placebo\") avisit region;\n  model chg = trt01p avisit trt01p*avisit base base*avisit region\n        / ddfm=kr solution;\n  repeated avisit / subject=usubjid type=un;\n  lsmeans trt01p*avisit / diff cl alpha=0.05;\nrun;\n```\nR\n```\nlibrary(dplyr); library(mmrm); library(emmeans)\nanl <- adqs %>%\n  inner_join(filter(adsl, ITTFL == \"Y\"), by = \"USUBJID\") %>%\n  filter(PARAMCD == \"ADAS13\", ANL01FL == \"Y\", AVISITN > 0) %>%\n  mutate(AVISIT = factor(AVISIT), TRT01P = relevel(factor(TRT01P), \"Placebo\"))\n\nfit <- mmrm(CHG ~ TRT01P * AVISIT + BASE * AVISIT + REGION +\n            us(AVISIT | USUBJID), data = anl, method = \"Kenward-Roger\")\nemmeans(fit, pairwise ~ TRT01P | AVISIT, at = list(AVISIT = \"Week 24\"))\n```\nNotes to include with the code: this is a simplified version of the production program; it omits formatting, macros, and output steps; and it reproduces the primary estimate to the stated precision.\n\n5. QC and review (Day 5-8)\n- Independent programmer confirms the simplified code reproduces the reported estimate, SE, CI, and p-value, with a documented comparison.\n- A second statistician reviews the narrative against the SAP and define.xml (variable names, derivations, flags).\n- Clinical and regulatory review: confirm no wording introduces new claims, post hoc analyses, or inconsistencies with the CSR.\n- Check for any data-privacy issue: no subject-level data in the response unless FDA requested it and the format is approved.\n\n6. Package and submit (Day 8-10)\n- Cover letter that restates the IR verbatim and answers it point by point.\n- Narrative (step 3), code files as .txt or .sas/.R per eCTD guidance, the log or output showing reproduction, and references to the SAP and define.xml sections.\n- Submit through the ESG or the agreed channel under the correct IND/NDA/BLA sequence number; Regulatory Affairs handles this.\n- Archive everything: the final package, program versions, run logs, and the QC record.\n\n7. Risks to flag early\n- The simplified code does not match the production result (for example, because of the covariance structure fallback, the handling of intercurrent events, or the visit windowing).\n- The IR text can be read more broadly than you expect (for example, a request for all analysis code instead of a single result). Clarify before you start.\n- Any discrepancy found during reproduction needs a decision from the lead statistician and Regulatory before it is mentioned to FDA.\n\nInputs I need to turn this into a final response: the IR text, the study and SAP section for the primary analysis, the ADaM specs (dataset and variable names), the submitted program, and the due date.\n\n---\nWHAT HAPPENS WHEN THE PLAN'S CODE IS CHECKED AGAINST THE REAL FILES (run_bad.R, run 2026-10-21):\n\nDoes the plan's PARAMCD = 'ADAS13' exist in ADQSADAS?  FALSE \nPARAMCD values present:  ACITM01 ACITM02 ACITM03 ACITM04 ACITM05 ACITM06 ACITM07 ACITM08 ACITM09 ACITM10 ACITM11 ACITM12 ACITM13 ACITM14 ACTOT \nDoes the plan's REGION exist in ADSL or ADQSADAS?  FALSE \nDoes ADSL have FASFL?  FALSE \nRows left after the plan's filter (PARAMCD == 'ADAS13'):  0 \nIs the mmrm package installed?  FALSE ",
    "what_went_wrong": [
      "It says it has not seen the SAP or ADaM specs and builds a template from convention: an MMRM with an unstructured covariance. The SAP specifies an ANCOVA on LOCF data with treatment as a continuous term (SAP 10.1.1, CSR PDF p.429). Following the plan would produce a different analysis and a different number.",
      "It names PARAMCD = \"ADAS13\". The pilot dataset has ACTOT for the ADAS-Cog (11) total; ADAS13 does not exist, so the plan's filter returns 0 rows.",
      "It adds a REGION covariate that is in neither ADSL nor ADQSADAS; the SAP's covariate is the pooled site group (SITEGR1).",
      "It uses an ITT or FASFL population flag. ADSL has no FASFL; the analysis uses EFFFL = Y (234 subjects, not the 254 ITT subjects).",
      "LOCF appears only as one 'for example' option, and the code keeps all post-baseline visits (AVISITN > 0) for a repeated-measures model. The SAP specifies a single-visit Week 24 analysis with LOCF records (DTYPE = LOCF) filling missing values.",
      "Most of the plan is calendar and governance (Day 0-2, owners, ESG submission, checksums). None of it can be checked, and none of it is a derivation step. It also states that the code 'reproduces the primary estimate to the stated precision' before any run, which is a claim with no basis.",
      "The R code depends on the mmrm package, which is not installed in the project library; this is minor and fixable."
    ]
  },
  "what_changed": [
    "Input: the lazy request became real variable labels and define.xml comments for ADSL and ADQSADAS, four verbatim SAP passages, and the footnotes of the target table in words, with the invented request clearly bannered.",
    "Output: a generic MMRM template became a ten-step procedure that names ACTOT, Week 24, ANL01FL, EFFFL, SITEGR1, TRT01PN and the two ANCOVA models, each step tied to a quoted sentence.",
    "The prompt asked for gaps to be listed instead of filled. The plan listed 14 open questions, including the numeric dose coding and the Week 24 visit code, instead of guessing.",
    "The prompt asked for pseudo-code precise enough to implement without questions. That made the plan executable: the translation to R needed only a few explicit choices (Week 24 code, dose scores, contrast direction).",
    "The check changed from reading to running: 37 of 37 table cells were reproduced from the plan, and a sensitivity run showed which open question mattered."
  ],
  "check_before_trust": [
    "Run it. A plan is not a replication until the code reproduces the table. Here the cells matched, but a different dose coding or a missing ANL01FL filter would have changed results (see 5 and 6).",
    "Check the answer key. The CSR values in replicate_14-3-01.R were typed from pdftotext output of Table 14-3.01 (PDF p.49). Compare them with the PDF yourself.",
    "Check the population count first. Efficacy subjects are 234 in ADSL; the table headers say 79, 81 and 74. If your n differs, stop before comparing anything else.",
    "The plan's row selection (ANL01FL = Y, no DTYPE filter) is only safe after a one-row-per-subject check. Without the ANL01FL filter the Week 24 ACTOT records for the efficacy subjects number 237 for 234 subjects, which would silently double-count three people in a model.",
    "Dose coding changes the dose-response p-value. With TRT01PN (0, 54, 81) the p-value matches the CSR (0.245); with scores 0, 1, 2 it is 0.232. The input did not say how the CSR coded dose; the match with 0, 54, 81 is evidence, not documentation. Ask the team what the production program used.",
    "Contamination: the CDISC pilot is public and the model may know the SAP and the CSR. The excerpt did not contain the table's numbers, but the model could have reproduced standard choices from memory. One run cannot separate the two.",
    "Do not send the response on the strength of a pass. The pass shows the table can be reproduced from these files with this method; it does not show the submitted SAS program is what ran, and it says nothing about whether the instructions are clear to a reviewer."
  ],
  "verification": {
    "answer_key": "Recomputed. The plan was executed step by step in R (replicate_14-3-01.R) on the unmodified adam_adsl.xpt and adam_adqsadas.xpt and compared cell by cell with CSR Table 14-3.01 (cdiscpilot01_csr.pdf, PDF p.49, repeated on p.468), typed from pdftotext output. The SAP (CSR Appendix 9) and adam_define.xml were reference documents for the claim table.",
    "rows": [
      {
        "claim": "Efficacy population is ADSL EFFFL = Y",
        "verdict": "Correct",
        "cite": "ADSL 234 Y of 254; per group 79/81/74 match CSR Table 14-3.01 (PDF p.49)"
      },
      {
        "claim": "SAP 10.1.1 says the primary analysis uses the efficacy population with LOCF",
        "verdict": "Correct",
        "cite": "SAP 10.1.1 (CSR PDF p.429)"
      },
      {
        "claim": "PARAMCD ACTOT is the ADAS-Cog (11) total",
        "verdict": "Partly",
        "cite": "File label is 'Adas-Cog(11) Subscore'; 'total' is an interpretation (the input said the same)"
      },
      {
        "claim": "ACITM01 to ACITM14 are item parameters, not to be used",
        "verdict": "Correct",
        "cite": "adam_adqsadas.xpt PARAMCD values"
      },
      {
        "claim": "Keep observed rows and DTYPE = LOCF rows, no DTYPE filter",
        "verdict": "Correct",
        "cite": "Week 24, ANL01FL = Y, efficacy subjects: 155 observed and 79 LOCF"
      },
      {
        "claim": "ANL01FL = Y at Week 24 leaves one row per subject",
        "verdict": "Correct",
        "cite": "234 rows for 234 subjects; without the flag 237 rows (3 extra)"
      },
      {
        "claim": "Do not filter on COMP24FL",
        "verdict": "Correct",
        "cite": "Completers are 118 of 234; 79 LOCF rows are in the analysis"
      },
      {
        "claim": "Inner join to ADSL on USUBJID; treatment and site from ADSL",
        "verdict": "Correct",
        "cite": "All 234 efficacy subjects have a Week 24 row"
      },
      {
        "claim": "TRT01PN is a numeric treatment variable",
        "verdict": "Correct",
        "cite": "Placebo 0, Low 54, High 81; ADQSADAS TRTPN equals ADSL TRT01PN"
      },
      {
        "claim": "BASE is the QS baseline value at VISITNUM 3",
        "verdict": "Correct",
        "cite": "adam_define.xml ADQSADAS.BASE"
      },
      {
        "claim": "CHG is AVAL - BASE",
        "verdict": "Correct",
        "cite": "Maximum absolute difference 0; file label is 'Baseline Value'"
      },
      {
        "claim": "Descriptives: n, mean, SD, median, min, max for BASE, AVAL, CHG",
        "verdict": "Correct",
        "cite": "CSR PDF p.49 layout; 27 cells reproduced"
      },
      {
        "claim": "Dose model: CHG ~ BASE + site + continuous treatment",
        "verdict": "Correct",
        "cite": "SAP 10.1.1; footnote 2"
      },
      {
        "claim": "No interaction terms",
        "verdict": "Correct",
        "cite": "SAP 10.1.1"
      },
      {
        "claim": "Dose-response p-value is a test of a non-zero coefficient",
        "verdict": "Correct",
        "cite": "Footnote 2; p = 0.245 reproduced"
      },
      {
        "claim": "Pairwise model uses categorical treatment",
        "verdict": "Correct",
        "cite": "Footnote 3"
      },
      {
        "claim": "No multiplicity adjustment for pairwise comparisons",
        "verdict": "Correct",
        "cite": "Footnote 3"
      },
      {
        "claim": "Three pairwise differences, each with SE, 95% CI and p-value",
        "verdict": "Correct",
        "cite": "CSR PDF p.49; nine cells reproduced"
      },
      {
        "claim": "SAP gating rule: pairwise only if dose response is significant",
        "verdict": "Correct",
        "cite": "SAP 10.1.1; CSR section 11.4.1 says the printed pairwise results 'should not be considered'"
      },
      {
        "claim": "Footnote 1 supports the pairwise model (treatment and site factors, baseline covariate)",
        "verdict": "Correct",
        "cite": "CSR PDF p.49 footnote 1"
      },
      {
        "claim": "SITEGR1 in ADQSADAS equals ADSL.SITEGR1; pooling follows SAP 7.1",
        "verdict": "Correct",
        "cite": "define.xml comment; SAP 7.1; values identical for all 254 subjects"
      },
      {
        "claim": "AVISIT is derived by the SAP 8.2 windowing algorithm",
        "verdict": "Correct",
        "cite": "define.xml comment"
      },
      {
        "claim": "Cover text makes no study claims",
        "verdict": "Correct",
        "cite": "Read of section E"
      },
      {
        "claim": "OPEN Q1: EFFFL source and CIBIC+ requirement not in the input",
        "verdict": "Correct",
        "cite": "Real gap. Builder note: define.xml gives the comment 'ADSL.FASFL' for ADQSADAS.EFFFL and ADSL has no FASFL variable"
      },
      {
        "claim": "OPEN Q2: Week 24 visit code not in the input",
        "verdict": "Correct",
        "cite": "Real gap; in the data AVISITN = 24"
      },
      {
        "claim": "OPEN Q3: relation of LOCF rows to ANL01FL, and row choice, not stated",
        "verdict": "Partly",
        "cite": "The input's ANL01FL comment gives most of the rule; in the data 3 efficacy rows have a blank flag"
      },
      {
        "claim": "OPEN Q4: numeric treatment coding not given",
        "verdict": "Correct",
        "cite": "Real gap; data give 0/54/81; scores 0/1/2 would give p = 0.232"
      },
      {
        "claim": "OPEN Q5: missing BASE or CHG handling not stated",
        "verdict": "Correct",
        "cite": "Real gap; none missing"
      },
      {
        "claim": "OPEN Q6: CHG label is 'Baseline Value'",
        "verdict": "Correct",
        "cite": "Confirmed in the file; values are exactly AVAL - BASE"
      },
      {
        "claim": "OPEN Q7: sidedness, SS type and df not given",
        "verdict": "Correct",
        "cite": "Real gap in the excerpt; the protocol text in the CSR says two-sided"
      },
      {
        "claim": "OPEN Q8: whether the table shows pairwise comparisons regardless of the dose-response result",
        "verdict": "Partly",
        "cite": "The input's table description already says pairwise comparisons are shown; only the dose-response outcome is a true gap"
      },
      {
        "claim": "OPEN Q9, Q10, Q12: LS-mean weighting, difference direction, software not given",
        "verdict": "Correct",
        "cite": "Real gaps; CSR p.49 labels give the direction"
      },
      {
        "claim": "OPEN Q11: TRTP vs TRT01P identity not stated",
        "verdict": "Correct",
        "cite": "Real gap; identical in the data"
      },
      {
        "claim": "OPEN Q13: confirm SITEGR1 already applies pooling",
        "verdict": "Partly",
        "cite": "The label 'Pooled Site Group 1' plus SAP 7.1 mostly answer it"
      },
      {
        "claim": "OPEN Q14: do descriptives use the same subjects as the model",
        "verdict": "Correct",
        "cite": "Real gap; n = 234 for all variables"
      }
    ],
    "errors_found": [
      "No outright errors in the plan. Four partly-correct points: ACTOT called a 'total' where the file label says 'Subscore'; open questions 3, 8 and 13 ask about things the input already mostly answered.",
      "Risk in the pseudo-code (builder reading, not a verifier verdict): the comment 'drop the ANL01FL condition if LOCF rows have it blank' would give 237 rows for 234 subjects, because 3 efficacy rows have a blank flag. The plan's own one-row-per-subject check would catch it.",
      "The plan could not know the dose coding. TRT01PN (0, 54, 81) reproduced the CSR p-value 0.245; scores 0, 1, 2 give 0.232.",
      "Gap not visible to the model: define.xml says ADQSADAS.EFFFL derives from 'ADSL.FASFL', a variable that does not exist in ADSL.",
      "Not verified: the SAS PROC lines in the pseudo-code comments (no SAS available); the verifier did not refit the ANCOVA."
    ],
    "summary": "Independent verification: a separate subagent that did not write the plan checked 35 claims against the define.xml, SAP, CSR text and xpt files, with its own R checks. 31 correct, 4 partly, 0 wrong, 0 not in source, 0 outright false gaps (the three partly-answered open questions are partial false gaps). Executing the plan in R reproduced 37 of 37 cells of CSR Table 14-3.01 (PASS); the verifier's check of the typed reference values agreed with the CSR text. The verifier did not refit the ANCOVA itself, so the model p-values and LS-mean differences rest on the builder's script, which was not independently rerun. The plan left 14 questions open; the dose coding decided the dose-response p-value and the builder used the plan's own suggestion, TRT01PN."
  },
  "run": {
    "generated_by": "Claude (Anthropic), run as subagents on 2026-10-21: one subagent for the lazy run and one fresh subagent for the good run (shown the excerpt and prompt only, instructed to use no tools and read no files; the tool restriction cannot be enforced from outside, and both agents had tool access). The builder executed the plan in R. Verification by a third subagent that did not write the output.",
    "not_tested_in": "Microsoft 365 Copilot"
  },
  "run_summary": [
    {
      "kind": "ok",
      "label": "Plan executed in R",
      "text": "37 of 37 cells of CSR Table 14-3.01 reproduced (PASS), after the builder chose Week 24, dose scores and contrast direction."
    },
    {
      "kind": "warn",
      "label": "Open questions mattered",
      "text": "Dose scores 0, 1, 2 instead of 0, 54, 81 give a dose-response p of 0.232, not 0.245; skipping the ANL01FL filter gives 237 rows for 234 subjects."
    },
    {
      "kind": "fail",
      "label": "Lazy input",
      "text": "Generic MMRM template; PARAMCD ADAS13 and REGION do not exist, so its filter returns 0 rows."
    }
  ],
  "contamination_note": "One model, one run each for the lazy and the good input; this is not a rate. The good-run agent was not given any number from Table 14-3.01 but the pilot is public and may be familiar to the model. The agency request is invented; the real FDA wording for such requests was not used.",
  "trim_note": "One model, one run each, not a rate. The example covers one study (a 2000s mock submission), one table and one model. It does not show how the approach works for a model with random effects, an MMRM, or a table that needs the SAS program's macros."
}