As a clinical trial statistician or programmer, answer three short questions in Your review: the task, the inputs and outputs, and the AI-assisted review. Agreeing with all three approves this benchmark; disagreeing with any needs a comment. Propose a fix with the Edit button on any source file, or add it to your comments.
We suggest spending no more than 5 minutes on a review. The other tabs beside Your review are background for assessment, not under review.
Summary
README.mdPublic entries: Python and R. Passing coverage requires an installed inventory.
Goal: repeat on every dose record and every pharmacokinetic (PK)
concentration record of a population PK dataset the subject's baseline
covariates: age, sex and race with numeric codes (SEXN, RACEN),
weight and height with the body mass index and the body surface area
(WTBL, HTBL, BMIBL, BSABL), the baseline creatinine, alanine
aminotransferase and bilirubin (CREATBL, ALTBL, TBILBL), and the
creatinine clearance and estimated glomerular filtration rate (CRCLBL,
EGFRBL).
Input: exposure (EX) records, one per administration, with the
date/time (EXSTDTC), and PK concentration (PC) records with the
collection date/time (PCDTC); an administration gives a dose record and
a sample gives a concentration record. The subject-level dataset (ADSL)
has AGE in years, SEX and RACE. Vital signs (VS) hold the tests
WEIGHT (kg) and HEIGHT (cm), and laboratory (LB) records hold the
tests CREAT (umol/L), ALT (U/L) and BILI (umol/L) among others,
with the numeric result in VSSTRESN or LBSTRESN. A subject's baseline
record of a test is the one flagged Y in VSBLFL or LBBLFL.
Variables:
ASEQ: the record's number within the subject, in the order ofADTM.ADTM: the date/time of the administration or of the sample.EVID: 1 for a dose record and 0 for a concentration record.AGE,SEX,RACE: as in ADSL.SEXN: 1 forMand 2 forF.RACEN: 1 forAMERICAN INDIAN OR ALASKA NATIVE, 2 forASIAN, 3 forBLACK OR AFRICAN AMERICAN, 4 forNATIVE HAWAIIAN OR OTHER PACIFIC ISLANDER, 5 forWHITEand 6 for any other value.WTBL,HTBL: the baseline weight and height; empty when the subject has no baseline record of the test.BMIBL:WTBLdivided by the square ofHTBLin metres (HTBL/ 100).BSABL: the Mosteller body surface area, the square root ofHTBLxWTBL/ 3600.CREATBL,ALTBL,TBILBL: the baseline results ofCREAT,ALTandBILI; empty when the subject has no baseline record of the test.CRCLBL: the Cockcroft-Gault creatinine clearance in mL/min: (140 -AGE) xWTBLx 1.23 /CREATBLfor a male subject, with 1.04 in place of 1.23 for a female subject.EGFRBL: the CKD-EPI 2021 estimated glomerular filtration rate in mL/min/1.73 m2. With r =CREATBL/ 88.42 / 0.9 for a male subject andCREATBL/ 88.42 / 0.7 for a female subject, it is 142 x r^a x 0.9938^AGE, times 1.012 for a female subject, where the exponent a is -1.2 when r is above 1 and otherwise -0.302 for a male and -0.241 for a female subject.
Note: no computed value is rounded, and a computed value is empty when a value it is computed from is empty. Results that are not flagged as baseline, and tests other than those named, are not used.
Inputs
Under review5 source filesinput/adsl.csv
Edit5 rows| STUDYID | USUBJID | AGE | AGEU | SEX | RACE |
|---|---|---|---|---|---|
| YAMAA-01 | 61 | YEARS | M | WHITE | |
| YAMAA-01 | 48 | YEARS | F | ASIAN | |
| YAMAA-01 | 35 | YEARS | M | BLACK OR AFRICAN AMERICAN | |
| YAMAA-01 | 72 | YEARS | F | WHITE | |
| YAMAA-01 | 56 | YEARS | F | MULTIPLE |
input/ex.csv
Edit5 rows| STUDYID | USUBJID | EXSEQ | EXTRT | EXDOSE | EXDOSU | EXSTDTC |
|---|---|---|---|---|---|---|
| YAMAA-01 | 1 | DRUG X | 100 | mg | 2025-03-10T08:00 | |
| YAMAA-01 | 1 | DRUG X | 100 | mg | 2025-03-10T08:30 | |
| YAMAA-01 | 1 | DRUG X | 100 | mg | 2025-03-11T08:00 | |
| YAMAA-01 | 1 | DRUG X | 100 | mg | 2025-03-11T09:00 | |
| YAMAA-01 | 1 | DRUG X | 100 | mg | 2025-03-12T08:15 |
input/lb.csv
Edit15 rows| STUDYID | USUBJID | LBSEQ | LBTESTCD | LBSTRESN | LBSTRESU | LBBLFL | VISIT | LBDTC |
|---|---|---|---|---|---|---|---|---|
| YAMAA-01 | 1 | ALT | 28 | U/L | Y | SCREENING | 2025-03-03 | |
| YAMAA-01 | 2 | BILI | 11 | umol/L | Y | SCREENING | 2025-03-03 | |
| YAMAA-01 | 3 | CREAT | 80 | umol/L | Y | SCREENING | 2025-03-03 | |
| YAMAA-01 | 4 | GLUC | 5.4 | mmol/L | Y | SCREENING | 2025-03-03 | |
| YAMAA-01 | 1 | ALT | 19 | U/L | Y | SCREENING | 2025-03-04 | |
| YAMAA-01 | 2 | BILI | 8 | umol/L | Y | SCREENING | 2025-03-04 | |
| YAMAA-01 | 3 | CREAT | 55 | umol/L | Y | SCREENING | 2025-03-04 | |
| YAMAA-01 | 1 | ALT | 44 | U/L | Y | SCREENING | 2025-03-04 | |
| YAMAA-01 | 2 | CREAT | 70 | umol/L | Y | SCREENING | 2025-03-04 | |
| YAMAA-01 | 1 | ALT | 23 | U/L | Y | SCREENING | 2025-03-05 | |
| YAMAA-01 | 2 | BILI | 14 | umol/L | Y | SCREENING | 2025-03-05 | |
| YAMAA-01 | 3 | CREAT | 68 | umol/L | — | WEEK 2 | 2025-03-25 | |
| YAMAA-01 | 1 | ALT | 31 | U/L | Y | SCREENING | 2025-03-06 | |
| YAMAA-01 | 2 | BILI | 9 | umol/L | Y | SCREENING | 2025-03-06 | |
| YAMAA-01 | 3 | CREAT | 97 | umol/L | Y | SCREENING | 2025-03-06 |
input/pc.csv
Edit5 rows| STUDYID | USUBJID | PCSEQ | PCTESTCD | PCTPT | PCDTC |
|---|---|---|---|---|---|
| YAMAA-01 | 1 | DRGX | 2 h | 2025-03-10T10:00 | |
| YAMAA-01 | 1 | DRGX | 2 h | 2025-03-10T10:30 | |
| YAMAA-01 | 1 | DRGX | 2 h | 2025-03-11T10:00 | |
| YAMAA-01 | 1 | DRGX | 2 h | 2025-03-11T11:00 | |
| YAMAA-01 | 1 | DRGX | 2 h | 2025-03-12T10:15 |
input/vs.csv
Edit11 rows| STUDYID | USUBJID | VSSEQ | VSTESTCD | VSSTRESN | VSSTRESU | VSBLFL | VISIT | VSDTC |
|---|---|---|---|---|---|---|---|---|
| YAMAA-01 | 1 | HEIGHT | 178 | cm | Y | SCREENING | 2025-03-03 | |
| YAMAA-01 | 2 | WEIGHT | 85 | kg | — | SCREENING | 2025-03-03 | |
| YAMAA-01 | 3 | WEIGHT | 84.5 | kg | Y | DAY 1 | 2025-03-10 | |
| YAMAA-01 | 4 | WEIGHT | 83.9 | kg | — | WEEK 2 | 2025-03-24 | |
| YAMAA-01 | 1 | HEIGHT | 162 | cm | Y | SCREENING | 2025-03-04 | |
| YAMAA-01 | 2 | WEIGHT | 58 | kg | Y | DAY 1 | 2025-03-10 | |
| YAMAA-01 | 1 | WEIGHT | 91.3 | kg | Y | DAY 1 | 2025-03-11 | |
| YAMAA-01 | 1 | HEIGHT | 155.5 | cm | Y | SCREENING | 2025-03-05 | |
| YAMAA-01 | 2 | WEIGHT | 49.8 | kg | Y | DAY 1 | 2025-03-11 | |
| YAMAA-01 | 1 | HEIGHT | 168 | cm | Y | SCREENING | 2025-03-06 | |
| YAMAA-01 | 2 | WEIGHT | 70.2 | kg | Y | DAY 1 | 2025-03-12 |
Expected output
Under review10 expected rowsexpected/adppk.csv
Edit10 rows| STUDYID | USUBJID | ASEQ | ADTM | EVID | AGE | SEX | SEXN | RACE | RACEN | WTBL | HTBL | BMIBL | BSABL | CREATBL | ALTBL | TBILBL | CRCLBL | EGFRBL |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| YAMAA-01 | 1 | 2025-03-10T08:00:00 | 1 | 61 | M | 1 | WHITE | 5 | 84.5 | 178 | 26.669612422673904 | 2.044029245278931 | 80 | 28 | 11 | 102.6358125 | 96.5540557410661 | |
| YAMAA-01 | 2 | 2025-03-10T10:00:00 | 0 | 61 | M | 1 | WHITE | 5 | 84.5 | 178 | 26.669612422673904 | 2.044029245278931 | 80 | 28 | 11 | 102.6358125 | 96.5540557410661 | |
| YAMAA-01 | 1 | 2025-03-10T08:30:00 | 1 | 48 | F | 2 | ASIAN | 2 | 58 | 162 | 22.10028959000152 | 1.6155494421403511 | 55 | 19 | 8 | 100.8989090909091 | 109.69337151096254 | |
| YAMAA-01 | 2 | 2025-03-10T10:30:00 | 0 | 48 | F | 2 | ASIAN | 2 | 58 | 162 | 22.10028959000152 | 1.6155494421403511 | 55 | 19 | 8 | 100.8989090909091 | 109.69337151096254 | |
| YAMAA-01 | 1 | 2025-03-11T08:00:00 | 1 | 35 | M | 1 | BLACK OR AFRICAN AMERICAN | 3 | 91.3 | — | — | — | 70 | 44 | — | 168.4485 | 118.73341597121299 | |
| YAMAA-01 | 2 | 2025-03-11T10:00:00 | 0 | 35 | M | 1 | BLACK OR AFRICAN AMERICAN | 3 | 91.3 | — | — | — | 70 | 44 | — | 168.4485 | 118.73341597121299 | |
| YAMAA-01 | 1 | 2025-03-11T09:00:00 | 1 | 72 | F | 2 | WHITE | 5 | 49.8 | 155.5 | 20.59532056120181 | 1.4666571969391256 | — | 23 | 14 | — | — | |
| YAMAA-01 | 2 | 2025-03-11T11:00:00 | 0 | 72 | F | 2 | WHITE | 5 | 49.8 | 155.5 | 20.59532056120181 | 1.4666571969391256 | — | 23 | 14 | — | — | |
| YAMAA-01 | 1 | 2025-03-12T08:15:00 | 1 | 56 | F | 2 | MULTIPLE | 6 | 70.2 | 168 | 24.87244897959184 | 1.8099723754798027 | 97 | 31 | 9 | 63.22342268041238 | 59.164964926871065 | |
| YAMAA-01 | 2 | 2025-03-12T10:15:00 | 0 | 56 | F | 2 | MULTIPLE | 6 | 70.2 | 168 | 24.87244897959184 | 1.8099723754798027 | 97 | 31 | 9 | 63.22342268041238 | 59.164964926871065 |
Human review and assessment
| Dataset Name | Variable Name | Variable Label | Type | Codelist/Controlled Terms | Core | Computational Method | Origin |
|---|---|---|---|---|---|---|---|
| ADPPK | STUDYID | Study Identifier | character | Set per constructed row; see the Row construction sheet. | Derived | ||
| ADPPK | USUBJID | Unique Subject Identifier | character | Set per constructed row; see the Row construction sheet. | Derived | ||
| ADPPK | ADTM | Analysis Date/Time | numeric | ISO 8601 | Set per constructed row; see the Row construction sheet. | Derived | |
| ADPPK | EVID | Event ID | numeric | 0, 1 | Set per constructed row; see the Row construction sheet. | Derived | |
| ADPPK | AGE | Age | numeric | Copy value from ADSL.AGE. | Predecessor | ||
| ADPPK | SEX | Sex | character | Copy value from ADSL.SEX. | Predecessor | ||
| ADPPK | SEXN | Sex (N) | numeric | Recode SEX: "M" → "1", "F" → "2"; missing values stay missing; unlisted values are errors. | Derived | ||
| ADPPK | RACE | Race | character | Copy value from ADSL.RACE. | Predecessor | ||
| ADPPK | RACEN | Race (N) | numeric | If RACE = 'AMERICAN INDIAN OR ALASKA NATIVE' then "1"; If RACE = 'ASIAN' then "2"; If RACE = 'BLACK OR AFRICAN AMERICAN' then "3"; If RACE = 'NATIVE HAWAIIAN OR OTHER PACIFIC ISLANDER' then "4"; If RACE = 'WHITE' then "5"; otherwise "6". | Derived | ||
| ADPPK | WTBL | Baseline Weight (kg) | numeric | Take WEIGHT from the VS record whose STUDYID equals STUDYID and USUBJID equals USUBJID, where VS.VSBLFL = 'Y' AND VS.VSTESTCD IN ('WEIGHT', 'HEIGHT'), and no match yields blank. | Derived | ||
| ADPPK | HTBL | Baseline Height (cm) | numeric | Take HEIGHT from the VS record whose STUDYID equals STUDYID and USUBJID equals USUBJID, where VS.VSBLFL = 'Y' AND VS.VSTESTCD IN ('WEIGHT', 'HEIGHT'), and no match yields blank. | Derived | ||
| ADPPK | BMIBL | Baseline Body Mass Index (kg/m2) | numeric | Compute WTBL / POWER(HTBL / 100, 2). | Derived | ||
| ADPPK | BSABL | Baseline Body Surface Area (m2) | numeric | Compute SQRT(HTBL * WTBL / 3600). | Derived | ||
| ADPPK | CREATBL | Baseline Creatinine (umol/L) | numeric | Take CREAT from the LB record whose STUDYID equals STUDYID and USUBJID equals USUBJID, where LB.LBBLFL = 'Y' AND LB.LBTESTCD IN ('CREAT', 'ALT', 'BILI'), and no match yields blank. | Derived | ||
| ADPPK | ALTBL | Baseline Alanine Aminotransferase (U/L) | numeric | Take ALT from the LB record whose STUDYID equals STUDYID and USUBJID equals USUBJID, where LB.LBBLFL = 'Y' AND LB.LBTESTCD IN ('CREAT', 'ALT', 'BILI'), and no match yields blank. | Derived | ||
| ADPPK | TBILBL | Baseline Bilirubin (umol/L) | numeric | Take BILI from the LB record whose STUDYID equals STUDYID and USUBJID equals USUBJID, where LB.LBBLFL = 'Y' AND LB.LBTESTCD IN ('CREAT', 'ALT', 'BILI'), and no match yields blank. | Derived | ||
| ADPPK | CRCLBL | Baseline Creatinine Clearance (mL/min) | numeric | If SEX = 'M' then compute (140 - AGE) * WTBL * 1.23 / CREATBL; If SEX = 'F' then compute (140 - AGE) * WTBL * 1.04 / CREATBL; otherwise blank. | Derived | ||
| ADPPK | EGFRBL | Baseline Estimated GFR (mL/min/1.73 m2) | numeric | If SEX = 'M' AND CREATR > 1 then compute 142 * POWER(CREATR, -1.2) * POWER(0.9938, AGE); If SEX = 'M' then compute 142 * POWER(CREATR, -0.302) * POWER(0.9938, AGE); If SEX = 'F' AND CREATR > 1 then compute 142 * POWER(CREATR, -1.2) * POWER(0.9938, AGE) * 1.012; If SEX = 'F' then compute 142 * POWER(CREATR, -0.241) * POWER(0.9938, AGE) * 1.012; otherwise blank. | Derived | ||
| ADPPK | ASEQ | Analysis Sequence Number | numeric | Row number within each group of STUDYID, USUBJID, ordered by ADTM then EVID. | Derived |
| Template | Include when | STUDYID | USUBJID | ADTM | EVID |
|---|---|---|---|---|---|
| dose | Copy EX.STUDYID | Copy EX.USUBJID | Copy EX.EXSTDTC | Constant "1" | |
| concentration | Copy PC.STUDYID | Copy PC.USUBJID | Copy PC.PCDTC | Constant "0" |
| Variable | Permitted values |
|---|---|
| EVID | 0, 1 |
| Version | Date | Author | Description | Reviewer | Sign-off |
|---|---|---|---|---|---|
| 1.8 | 2026-11-19 | yamaa docs build | State open and closed range endpoints, including bounds of zero | ||
| 1.7 | 2026-10-20 | yamaa docs build | Read a specification in the 1.0 surface as its 0.5 counterpart; state that missing values stay missing where a mapping declares no missing handler, and leave out a declared missing answer that restates a handler's default | ||
| 1.6 | 2026-10-17 | yamaa docs build | Describe collected date parts written as ISO 8601 date text and times of day counted in seconds since midnight | ||
| 1.5 | 2026-10-17 | yamaa docs build | Name collected precision in words instead of letter codes; state imputation fallbacks, minimum source precision, bounds ignored outside the collected period, and invalid text with no handler as an error; describe date and datetime shifts, imputation flag codes, and partial text giving no date part | ||
| 1.4 | 2026-10-15 | yamaa docs build | State datetime precision codes through the hour and minute, and complete only the time parts a collected datetime lacks | ||
| 1.3 | 2026-09-29 | yamaa docs build | Show study codelist names, external dictionaries, and ISO 8601 formats in variable rows; list the document's codelist values and metadata | ||
| 1.2 | 2026-09-29 | yamaa docs build | Classify ADaM copies from a declared input as Predecessor and recodes as Derived, and SDTM recodes of locally derived columns as Derived | ||
| 1.1 | 2026-09-29 | yamaa docs build | Resolve lookups into the donor record they select, and give every derivation shape a plain-language rule instead of its raw YAML | ||
| 1.0 | yamaa docs build | Initial generation from spec.yaml |
prompts/adam-adppk-baseline-covariates/full.md
Edit40 linesFollowing CDISC ADaM standards, use the provided ADSL, EX, LB, PC, and VS datasets to create an ADPPK dataset with one record per subject per administration or pharmacokinetic sample.
The output dataset should contain the following columns in this order: STUDYID, USUBJID, ASEQ, ADTM, EVID, AGE, SEX, SEXN, RACE, RACEN, WTBL, HTBL, BMIBL, BSABL, CREATBL, ALTBL, TBILBL, CRCLBL, EGFRBL
Each EX record gives a dose record and each PC record a concentration record. Every record holds its subject's baseline covariates.
- ADTM is the date/time of the administration (EXSTDTC) or of the sample (PCDTC), in the form YYYY-MM-DDThh:mm:ss with the seconds shown.
- ASEQ numbers the subject's records from 1 in the order of ADTM.
- EVID is 1 for a dose record and 0 for a concentration record.
- AGE, SEX and RACE are as in ADSL. SEXN is 1 for "M" and 2 for "F". RACEN is 2 for "ASIAN", 3 for "BLACK OR AFRICAN AMERICAN", 5 for "WHITE" and 6 for any other value.
- WTBL and HTBL are the baseline results (VSSTRESN) of the VS tests "WEIGHT" and "HEIGHT", and CREATBL, ALTBL and TBILBL the baseline results (LBSTRESN) of the LB tests "CREAT", "ALT" and "BILI". The baseline record of a test is the one flagged "Y" in VSBLFL or LBBLFL, and each of these has no value when the subject has none. Results that are not flagged as baseline, and tests other than those named, are not used.
- BMIBL is WTBL divided by the square of HTBL in metres (HTBL / 100), and BSABL is the Mosteller body surface area, the square root of HTBL x WTBL / 3600.
- CRCLBL is the Cockcroft-Gault creatinine clearance in mL/min: (140 - AGE) x WTBL x 1.23 / CREATBL for a male subject, with 1.04 in place of 1.23 for a female subject.
- EGFRBL is the CKD-EPI 2021 estimated glomerular filtration rate in mL/min/1.73 m2. With r = CREATBL / 88.42 / 0.9 for a male subject and CREATBL / 88.42 / 0.7 for a female subject, it is 142 x r^a x 0.9938^AGE, times 1.012 for a female subject, where the exponent a is -1.2 when r is above 1 and otherwise -0.302 for a male and -0.241 for a female subject.
- BMIBL, BSABL, CRCLBL and EGFRBL are not rounded, and each has no value when a value it is computed from has no value.
Read the source datasets from /app/input and save the completed dataset as /app/output/adppk.csv.
prompts/adam-adppk-baseline-covariates/conventions.md
Edit17 linesFollowing CDISC ADaM standards, use the provided ADSL, EX, LB, PC, and VS datasets to create an ADPPK dataset with one record per subject per administration or pharmacokinetic sample.
The output dataset should contain the following columns in this order: STUDYID, USUBJID, ASEQ, ADTM, EVID, AGE, SEX, SEXN, RACE, RACEN, WTBL, HTBL, BMIBL, BSABL, CREATBL, ALTBL, TBILBL, CRCLBL, EGFRBL
ADTM is in the form YYYY-MM-DDThh:mm:ss with the seconds shown. EVID is 1 for a dose record and 0 for a concentration record. SEXN is 1 for "M" and 2 for "F". RACEN is 2 for "ASIAN", 3 for "BLACK OR AFRICAN AMERICAN", 5 for "WHITE", or 6. BSABL is the Mosteller body surface area, CRCLBL the Cockcroft-Gault creatinine clearance, and EGFRBL the CKD-EPI 2021 estimated glomerular filtration rate. BMIBL, BSABL, CRCLBL and EGFRBL are not rounded.
Read the source datasets from /app/input and save the completed dataset as /app/output/adppk.csv.
prompts/adam-adppk-baseline-covariates/brief.md
Edit10 linesFollowing CDISC ADaM standards, use the provided ADSL, EX, LB, PC, and VS datasets to create an ADPPK dataset with one record per subject per administration or pharmacokinetic sample.
The output dataset should contain the following columns in this order: STUDYID, USUBJID, ASEQ, ADTM, EVID, AGE, SEX, SEXN, RACE, RACEN, WTBL, HTBL, BMIBL, BSABL, CREATBL, ALTBL, TBILBL, CRCLBL, EGFRBL
Read the source datasets from /app/input and save the completed dataset as /app/output/adppk.csv.
R
Edit3 lineslibrary(yamaa)yamaa_spec("spec.yaml")$run()$outputPython
Edit3 linesimport yamaayamaa.spec("spec.yaml").run().outputsolutions/adam-adppk-baseline-covariates/result.R
Edit115 lines# Reference solution for the yamaa benchmark adam-adppk-baseline-covariates (R track).## Written from the benchmark's full prompt and its inputs alone, as an agent# would write it. Harbor's oracle agent runs it to check that the prompt can# be solved and that the grader scores a correct answer 1.suppressPackageStartupMessages({ library(dplyr) library(tidyr) library(readr) library(stringr)})read_src <- function(name) { read_csv( file.path("/app/input", name), col_types = cols(.default = col_character()), na = c("", "NA"), trim_ws = TRUE, progress = FALSE )}adsl <- read_src("adsl.csv")ex <- read_src("ex.csv")lb <- read_src("lb.csv")pc <- read_src("pc.csv")vs <- read_src("vs.csv")with_seconds <- function(x) { date_part <- "[0-9]{4}-[0-9]{2}-[0-9]{2}" case_when( is.na(x) ~ NA_character_, str_detect(x, paste0("^", date_part, "T[0-9]{2}:[0-9]{2}$")) ~ paste0(x, ":00"), str_detect(x, paste0("^", date_part, "T[0-9]{2}:[0-9]{2}:[0-9]{2}")) ~ str_sub(x, 1, 19), TRUE ~ x )}baseline <- function(data, testcd, flag, value, tests) { data %>% transmute( USUBJID, TESTCD = .data[[testcd]], FLAG = .data[[flag]], VALUE = as.numeric(.data[[value]]) ) %>% filter(FLAG %in% "Y", TESTCD %in% names(tests)) %>% group_by(USUBJID, TESTCD) %>% slice(1) %>% ungroup() %>% mutate(TESTCD = factor(unname(tests[TESTCD]), levels = unname(tests))) %>% select(USUBJID, TESTCD, VALUE) %>% pivot_wider( names_from = TESTCD, values_from = VALUE, names_expand = TRUE )}vs_bl <- baseline( vs, "VSTESTCD", "VSBLFL", "VSSTRESN", c(WEIGHT = "WTBL", HEIGHT = "HTBL"))lb_bl <- baseline( lb, "LBTESTCD", "LBBLFL", "LBSTRESN", c(CREAT = "CREATBL", ALT = "ALTBL", BILI = "TBILBL"))events <- bind_rows( ex %>% transmute(USUBJID, ADTM = with_seconds(EXSTDTC), EVID = 1L), pc %>% transmute(USUBJID, ADTM = with_seconds(PCDTC), EVID = 0L))adppk <- events %>% inner_join( adsl %>% transmute(STUDYID, USUBJID, AGE = as.numeric(AGE), SEX, RACE), by = "USUBJID" ) %>% left_join(vs_bl, by = "USUBJID") %>% left_join(lb_bl, by = "USUBJID") %>% arrange(USUBJID, ADTM, desc(EVID)) %>% group_by(USUBJID) %>% mutate(ASEQ = row_number()) %>% ungroup() %>% mutate( SEXN = case_when(SEX == "M" ~ 1L, SEX == "F" ~ 2L, TRUE ~ NA_integer_), RACEN = case_when( RACE %in% "ASIAN" ~ 2L, RACE %in% "BLACK OR AFRICAN AMERICAN" ~ 3L, RACE %in% "WHITE" ~ 5L, TRUE ~ 6L ), BMIBL = WTBL / (HTBL / 100)^2, BSABL = sqrt(HTBL * WTBL / 3600), CRCLBL = (140 - AGE) * WTBL * case_when(SEX == "M" ~ 1.23, SEX == "F" ~ 1.04, TRUE ~ NA_real_) / CREATBL, EGFR_R = CREATBL / 88.42 / case_when(SEX == "M" ~ 0.9, SEX == "F" ~ 0.7, TRUE ~ NA_real_), EGFR_A = case_when( EGFR_R > 1 ~ -1.2, SEX == "M" ~ -0.302, SEX == "F" ~ -0.241, TRUE ~ NA_real_ ), EGFRBL = 142 * EGFR_R^EGFR_A * 0.9938^AGE * case_when(SEX == "F" ~ 1.012, SEX == "M" ~ 1, TRUE ~ NA_real_) ) %>% select( STUDYID, USUBJID, ASEQ, ADTM, EVID, AGE, SEX, SEXN, RACE, RACEN, WTBL, HTBL, BMIBL, BSABL, CREATBL, ALTBL, TBILBL, CRCLBL, EGFRBL )write_csv(adppk, file.path("/app/output", "adppk.csv"), na = "")solutions/adam-adppk-baseline-covariates/result.py
Edit107 lines# Reference solution for the yamaa benchmark adam-adppk-baseline-covariates (Python track).## Written from the benchmark's full prompt and its inputs alone, as an agent# would write it. Harbor's oracle agent runs it to check that the prompt can# be solved and that the grader scores a correct answer 1.import numpy as npimport pandas as pdIN = "/app/input"OUT = "/app/output"KEYS = ["STUDYID", "USUBJID"]COLUMNS = [ "STUDYID", "USUBJID", "ASEQ", "ADTM", "EVID", "AGE", "SEX", "SEXN", "RACE", "RACEN", "WTBL", "HTBL", "BMIBL", "BSABL", "CREATBL", "ALTBL", "TBILBL", "CRCLBL", "EGFRBL",]def read(name): return pd.read_csv(f"{IN}/{name}.csv", dtype=str, keep_default_na=False)def full_datetime(value): value = value.strip() if "T" not in value: date, time = value, "" else: date, time = value.split("T", 1) parts = [p for p in time.split(":") if p != ""] parts = (parts + ["00", "00", "00"])[:3] return f"{date}T{':'.join(parts)}"def baseline(df, testcd, flag, result, tests): df = df[(df[flag].str.strip() == "Y") & df[testcd].str.strip().isin(tests)].copy() df["_value"] = pd.to_numeric(df[result].str.strip().replace("", np.nan)) df["_name"] = df[testcd].str.strip().map(tests) wide = df.groupby(KEYS + ["_name"], sort=False)["_value"].first().unstack("_name") wide = wide.reindex(columns=list(tests.values())) wide.columns.name = None return wide.reset_index()adsl = read("adsl")ex = read("ex")pc = read("pc")vs = read("vs")lb = read("lb")doses = ex[KEYS].copy()doses["ADTM"] = ex["EXSTDTC"].map(full_datetime)doses["EVID"] = 1samples = pc[KEYS].copy()samples["ADTM"] = pc["PCDTC"].map(full_datetime)samples["EVID"] = 0events = pd.concat([doses, samples], ignore_index=True)events = events.sort_values( KEYS + ["ADTM", "EVID"], ascending=[True, True, True, False], kind="stable").reset_index(drop=True)events["ASEQ"] = events.groupby(KEYS, sort=False).cumcount() + 1cov = adsl[KEYS + ["AGE", "SEX", "RACE"]].copy()cov["AGE"] = pd.to_numeric(cov["AGE"].str.strip().replace("", np.nan))cov["SEXN"] = cov["SEX"].map({"M": 1, "F": 2}).astype("Int64")cov["RACEN"] = ( cov["RACE"] .map({"ASIAN": 2, "BLACK OR AFRICAN AMERICAN": 3, "WHITE": 5}) .fillna(6) .astype("Int64"))cov = cov.merge( baseline(vs, "VSTESTCD", "VSBLFL", "VSSTRESN", {"WEIGHT": "WTBL", "HEIGHT": "HTBL"}), on=KEYS, how="left",)cov = cov.merge( baseline(lb, "LBTESTCD", "LBBLFL", "LBSTRESN", {"CREAT": "CREATBL", "ALT": "ALTBL", "BILI": "TBILBL"}), on=KEYS, how="left",)male = cov["SEX"] == "M"female = cov["SEX"] == "F"known = male | femalecov["BMIBL"] = cov["WTBL"] / (cov["HTBL"] / 100) ** 2cov["BSABL"] = np.sqrt(cov["HTBL"] * cov["WTBL"] / 3600)cg = pd.Series(np.where(male, 1.23, 1.04), index=cov.index).where(known)cov["CRCLBL"] = (140 - cov["AGE"]) * cov["WTBL"] * cg / cov["CREATBL"]kappa = pd.Series(np.where(male, 0.9, 0.7), index=cov.index).where(known)ratio = cov["CREATBL"] / 88.42 / kappalow = pd.Series(np.where(male, -0.302, -0.241), index=cov.index)exponent = pd.Series(np.where(ratio > 1, -1.2, low), index=cov.index)sex_factor = pd.Series(np.where(female, 1.012, 1.0), index=cov.index)cov["EGFRBL"] = 142 * ratio ** exponent * 0.9938 ** cov["AGE"] * sex_factorif cov["AGE"].notna().all() and (cov["AGE"] % 1 == 0).all(): cov["AGE"] = cov["AGE"].astype("Int64")adppk = events.merge(cov, on=KEYS, how="left")[COLUMNS]adppk.to_csv(f"{OUT}/adppk.csv", index=False)solutions/adam-adppk-baseline-covariates/result.sas
Edit153 lines/* opensas reference solution for the yamaa benchmark adam-adppk-baseline-covariates. Reads the benchmark inputs and derives the requested output. Execute with the existing opensas runtime: opensas /app/output/result.sas. */data adsl; infile "/app/input/adsl.csv" dsd dlm=',' firstobs=2 truncover; length STUDYID $20 USUBJID $40 AGE 8 AGEU $10 SEX $1 RACE $60; input STUDYID $ USUBJID $ AGE AGEU $ SEX $ RACE $; RACE = compress(RACE, "0D"x);run;data ex; infile "/app/input/ex.csv" dsd dlm=',' firstobs=2 truncover; length STUDYID $20 USUBJID $40 EXSEQ 8 EXTRT $40 EXDOSE 8 EXDOSU $10 EXSTDTC $25; input STUDYID $ USUBJID $ EXSEQ EXTRT $ EXDOSE EXDOSU $ EXSTDTC $; EXSTDTC = compress(EXSTDTC, "0D"x);run;data pc; infile "/app/input/pc.csv" dsd dlm=',' firstobs=2 truncover; length STUDYID $20 USUBJID $40 PCSEQ 8 PCTESTCD $8 PCTPT $20 PCDTC $25; input STUDYID $ USUBJID $ PCSEQ PCTESTCD $ PCTPT $ PCDTC $; PCDTC = compress(PCDTC, "0D"x);run;data lb; infile "/app/input/lb.csv" dsd dlm=',' firstobs=2 truncover; length STUDYID $20 USUBJID $40 LBSEQ 8 LBTESTCD $8 LBSTRESN 8 LBSTRESU $10 LBBLFL $1 VISIT $20 LBDTC $25; input STUDYID $ USUBJID $ LBSEQ LBTESTCD $ LBSTRESN LBSTRESU $ LBBLFL $ VISIT $ LBDTC $;run;data vs; infile "/app/input/vs.csv" dsd dlm=',' firstobs=2 truncover; length STUDYID $20 USUBJID $40 VSSEQ 8 VSTESTCD $8 VSSTRESN 8 VSSTRESU $10 VSBLFL $1 VISIT $20 VSDTC $25; input STUDYID $ USUBJID $ VSSEQ VSTESTCD $ VSSTRESN VSSTRESU $ VSBLFL $ VISIT $ VSDTC $;run;proc sort data=vs out=vsb; by STUDYID USUBJID VSSEQ; where VSBLFL = "Y" and VSTESTCD in ("WEIGHT", "HEIGHT");run;data vsbl(keep=STUDYID USUBJID WTBL HTBL); set vsb; by STUDYID USUBJID; retain WTBL HTBL; if first.USUBJID then do; WTBL = .; HTBL = .; end; if VSTESTCD = "WEIGHT" then WTBL = VSSTRESN; else if VSTESTCD = "HEIGHT" then HTBL = VSSTRESN; if last.USUBJID then output;run;proc sort data=lb out=lbb; by STUDYID USUBJID LBSEQ; where LBBLFL = "Y" and LBTESTCD in ("CREAT", "ALT", "BILI");run;data lbbl(keep=STUDYID USUBJID CREATBL ALTBL TBILBL); set lbb; by STUDYID USUBJID; retain CREATBL ALTBL TBILBL; if first.USUBJID then do; CREATBL = .; ALTBL = .; TBILBL = .; end; if LBTESTCD = "CREAT" then CREATBL = LBSTRESN; else if LBTESTCD = "ALT" then ALTBL = LBSTRESN; else if LBTESTCD = "BILI" then TBILBL = LBSTRESN; if last.USUBJID then output;run;proc sort data=adsl; by STUDYID USUBJID; run;data cov; merge adsl(in=a keep=STUDYID USUBJID AGE SEX RACE) vsbl lbbl; by STUDYID USUBJID; if a; length SEXN RACEN BMIBL BSABL CRCLBL EGFRBL 8; if SEX = "M" then SEXN = 1; else if SEX = "F" then SEXN = 2; if RACE = "ASIAN" then RACEN = 2; else if RACE = "BLACK OR AFRICAN AMERICAN" then RACEN = 3; else if RACE = "WHITE" then RACEN = 5; else RACEN = 6; if not missing(WTBL) and not missing(HTBL) then do; BMIBL = WTBL / ((HTBL / 100) ** 2); BSABL = sqrt(HTBL * WTBL / 3600); end; if not missing(AGE) and not missing(WTBL) and not missing(CREATBL) then do; if SEX = "M" then CRCLBL = (140 - AGE) * WTBL * 1.23 / CREATBL; else if SEX = "F" then CRCLBL = (140 - AGE) * WTBL * 1.04 / CREATBL; end; if not missing(AGE) and not missing(CREATBL) then do; if SEX = "M" then do; r = CREATBL / 88.42 / 0.9; if r > 1 then ex_a = -1.2; else ex_a = -0.302; EGFRBL = 142 * (r ** ex_a) * (0.9938 ** AGE); end; else if SEX = "F" then do; r = CREATBL / 88.42 / 0.7; if r > 1 then ex_a = -1.2; else ex_a = -0.241; EGFRBL = 142 * (r ** ex_a) * (0.9938 ** AGE) * 1.012; end; end; drop r ex_a;run;data events(keep=STUDYID USUBJID ADTM EVID SRCSEQ); length STUDYID $20 USUBJID $40 ADTM $19 EVID 8 SRCSEQ 8 dtc $25; set ex(in=inex keep=STUDYID USUBJID EXSEQ EXSTDTC) pc(keep=STUDYID USUBJID PCSEQ PCDTC); if inex then do; EVID = 1; dtc = EXSTDTC; SRCSEQ = EXSEQ; end; else do; EVID = 0; dtc = PCDTC; SRCSEQ = PCSEQ; end; dtc = strip(dtc); if length(dtc) = 16 then ADTM = cats(dtc, ":00"); else ADTM = dtc;run;proc sort data=events; by STUDYID USUBJID ADTM descending EVID SRCSEQ;run;data adppk; retain STUDYID USUBJID ASEQ ADTM EVID AGE SEX SEXN RACE RACEN WTBL HTBL BMIBL BSABL CREATBL ALTBL TBILBL CRCLBL EGFRBL; merge events(in=e) cov; by STUDYID USUBJID; if e; if first.USUBJID then ASEQ = 0; ASEQ + 1; keep STUDYID USUBJID ASEQ ADTM EVID AGE SEX SEXN RACE RACEN WTBL HTBL BMIBL BSABL CREATBL ALTBL TBILBL CRCLBL EGFRBL;run;data _null_; set adppk; file "/app/output/adppk.csv"; length line $600 v $40; array nums{14} ASEQ EVID AGE SEXN RACEN WTBL HTBL BMIBL BSABL CREATBL ALTBL TBILBL CRCLBL EGFRBL; array txt{14} $40 t1-t14; do i = 1 to 14; if missing(nums{i}) then txt{i} = ""; else do; v = strip(put(nums{i}, best32.)); if index(v, "E") > 0 then v = strip(put(nums{i}, best16.)); txt{i} = v; end; end; if _n_ = 1 then put "STUDYID,USUBJID,ASEQ,ADTM,EVID,AGE,SEX,SEXN,RACE,RACEN,WTBL,HTBL,BMIBL,BSABL,CREATBL,ALTBL,TBILBL,CRCLBL,EGFRBL"; line = trimn(STUDYID) || "," || trimn(USUBJID) || "," || trimn(t1) || "," || trimn(ADTM) || "," || trimn(t2) || "," || trimn(t3) || "," || trimn(SEX) || "," || trimn(t4) || "," || trimn(RACE) || "," || trimn(t5); do i = 6 to 14; line = trimn(line) || "," || trimn(txt{i}); end; put line;run;
yamaa