Review ask

As a clinical trial statistician or programmer, challenge anything in this benchmark: describe a problem in Comments, or propose a fix with the Edit button on any source file.

  1. Task: Would a real study need this derivation, specified this way? Does it follow CDISC ADaM: variable names, controlled terms, record structure? Flag any rule that is ambiguous or that a sponsor would handle differently.
  2. Inputs: Do they look like data collected in a real trial, and do they include the situations you would expect to meet in one?
  3. Expected output: Would independent QC programming reproduce every value from these inputs and rules?

The other tabs beside Comments are background for assessment, not under review.

Summary

Lifecycle: reviewedEditUnder review
What this benchmark means
README.md

Goal: add one total laboratory record per subject and visit whose analysis value (AVAL) is the collected component results added in the order the source records were stored, flagged with the record-type flag (DTYPE).

Input: collected laboratory records carrying the study identifier, subject identifier, sequence number, test code and name, visit, and standardized result. The component values are deliberately simple (0.1, 0.2, 0.3) so the floating-point rounding stays visible.

Variables:

  • PARAM: the collected test name on each component record; "Total of Components" on the new total record.
  • AVAL: the collected result on each component record; on the total record, the component results added in stored record order. A component with no collected result contributes nothing, and a subject and visit with no collected results at all leaves the total empty rather than zero.
  • DTYPE: empty on the collected records; CALCULATION on the total record, marking it as calculated rather than collected.

Note: binary floating-point addition makes the total sensitive to that order: one subject's records stored as 0.1, 0.2, 0.3 total 0.6000000000000001, while another subject's identical values stored as 0.3, 0.2, 0.1 total 0.6.

Inputs

Under review
1 source file

input/lb.csv

Edit
12 rows
input/lb.csv
STUDYIDUSUBJIDLBSEQLBTESTCDLBTESTVISITLBSTRESN
YAMAA-011COMP1Component 1WEEK 10.1
YAMAA-012COMP2Component 2WEEK 10.2
YAMAA-013COMP3Component 3WEEK 10.3
YAMAA-011COMP3Component 3WEEK 10.3
YAMAA-012COMP2Component 2WEEK 10.2
YAMAA-013COMP1Component 1WEEK 10.1
YAMAA-011COMP1Component 1WEEK 10.1
YAMAA-011COMP1Component 1WEEK 10.1
YAMAA-012COMP2Component 2WEEK 1—
YAMAA-013COMP3Component 3WEEK 10.3
YAMAA-011COMP1Component 1WEEK 1—
YAMAA-012COMP2Component 2WEEK 1—

Expected output

Under review
17 expected rows

expected/adlb.csv

Edit
17 rows
expected/adlb.csv
STUDYIDUSUBJIDPARAMCDPARAMAVISITAVALDTYPE
YAMAA-01COMP1Component 1WEEK 10.1—
YAMAA-01COMP2Component 2WEEK 10.2—
YAMAA-01COMP3Component 3WEEK 10.3—
YAMAA-01COMP3Component 3WEEK 10.3—
YAMAA-01COMP2Component 2WEEK 10.2—
YAMAA-01COMP1Component 1WEEK 10.1—
YAMAA-01COMP1Component 1WEEK 10.1—
YAMAA-01COMP1Component 1WEEK 10.1—
YAMAA-01COMP2Component 2WEEK 1——
YAMAA-01COMP3Component 3WEEK 10.3—
YAMAA-01COMP1Component 1WEEK 1——
YAMAA-01COMP2Component 2WEEK 1——
YAMAA-01TOTALTotal of ComponentsWEEK 10.6000000000000001CALCULATION
YAMAA-01TOTALTotal of ComponentsWEEK 10.6CALCULATION
YAMAA-01TOTALTotal of ComponentsWEEK 10.1CALCULATION
YAMAA-01TOTALTotal of ComponentsWEEK 10.4CALCULATION
YAMAA-01TOTALTotal of ComponentsWEEK 1—CALCULATION
Shaded columns are derived— = missing value

Comments and assessment materials

Comments

Signed in with GitHub; saved in repository Discussions

Mapping spec

Generated from the benchmark YAML; do not edit by hand

Dataset NameVariable NameVariable LabelTypeCodelist/Controlled TermsCoreComputational MethodOrigin
ADLBSTUDYIDStudy IdentifiercharacterCopy value from LB.STUDYID.Predecessor
ADLBUSUBJIDUnique Subject IdentifiercharacterCopy value from LB.USUBJID.Predecessor
ADLBAVISITAnalysis VisitcharacterCopy value from LB.VISIT.Predecessor
ADLBPARAMCDParameter CodecharacterSet per constructed row; see the Row construction sheet.Derived
ADLBPARAMParametercharacterSet per constructed row; see the Row construction sheet.Derived
ADLBAVALAnalysis ValuenumericSet per constructed row; see the Row construction sheet.Derived
ADLBDTYPEDerivation TypecharacterSet per constructed row; see the Row construction sheet.Derived
TemplateInclude whenPARAMCDPARAMAVALDTYPE
collectedCopy LB.LBTESTCDCopy LB.LBTESTCopy LB.LBSTRESNConstant "None"
totalConstant "TOTAL"Constant "Total of Components"Aggregate SUM(LB.LBSTRESN) over records matching on the shared output keysConstant "CALCULATION"
VersionDateAuthorDescriptionReviewerSign-off
1.32026-09-29yamaa docs buildShow study codelist names, external dictionaries, and ISO 8601 formats in variable rows; list the document's codelist values and metadata
1.22026-09-29yamaa docs buildClassify ADaM copies from a declared input as Predecessor and recodes as Derived, and SDTM recodes of locally derived columns as Derived
1.12026-09-29yamaa docs buildResolve lookups into the donor record they select, and give every derivation shape a plain-language rule instead of its raw YAML
1.0yamaa docs buildInitial generation from spec.yaml

Agent prompt

The request an agent receives with the input files; each tier states no more than the one above

prompts/adam-adlb-ordered-sum/full.md

Edit
18 lines

Following CDISC ADaM standards, use the provided LB dataset to create an ADLB dataset with one record per subject per visit per parameter, including one total record per subject and visit.

The output dataset should contain the following columns in this order: STUDYID, USUBJID, PARAMCD, PARAM, AVISIT, AVAL, DTYPE

Keep every collected component record with its test code and name, visit, and result; DTYPE has no value on these records. A component with no collected result is still kept, and its AVAL has no value.

Add one total record per subject and visit with PARAMCD "TOTAL", PARAM "Total of Components", and DTYPE "CALCULATION". Its AVAL is the sum of the collected component results at that subject and visit; it has no value, rather than zero, when none of them has a collected result.

Read the source datasets from /app/input and save the completed dataset as /app/output/adlb.csv.

prompts/adam-adlb-ordered-sum/conventions.md

Edit
12 lines

Following CDISC ADaM standards, use the provided LB dataset to create an ADLB dataset with one record per subject per visit per parameter, including one total record per subject and visit.

The output dataset should contain the following columns in this order: STUDYID, USUBJID, PARAMCD, PARAM, AVISIT, AVAL, DTYPE

The total record has PARAMCD "TOTAL", PARAM "Total of Components", and DTYPE "CALCULATION". DTYPE has no value on the component records.

Read the source datasets from /app/input and save the completed dataset as /app/output/adlb.csv.

prompts/adam-adlb-ordered-sum/brief.md

Edit
9 lines

Following CDISC ADaM standards, use the provided LB dataset to create an ADLB dataset with one record per subject per visit per parameter, including one total record per subject and visit.

The output dataset should contain the following columns in this order: STUDYID, USUBJID, PARAMCD, PARAM, AVISIT, AVAL, DTYPE

Read the source datasets from /app/input and save the completed dataset as /app/output/adlb.csv.

yamaa code

Runs the yamaa specification; its result must match the expected output

run.R

Edit
4 lines
library(yamaa)adlb <- yamaa_domain("spec.yaml")$outputadlb

run.py

Edit
4 lines
import yamaaadlb = yamaa.yamaa_domain("spec.yaml").outputadlb

Solution without yamaa

Written from the full prompt and the inputs alone; CI checks it reproduces the expected output

solutions/adam-adlb-ordered-sum/result.R

Edit
65 lines
# Reference solution for the yamaa benchmark adam-adlb-ordered-sum (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.library(dplyr, warn.conflicts = FALSE)library(readr)lb <- read_csv(  "/app/input/lb.csv",  col_types = cols(    LBSEQ = col_integer(),    LBSTRESN = col_double(),    .default = col_character()  ))# Keep every collected component record; DTYPE has no value on these.components <- lb |>  transmute(    STUDYID, USUBJID,    PARAMCD = LBTESTCD,    PARAM = LBTEST,    AVISIT = VISIT,    AVAL = LBSTRESN,    DTYPE = NA_character_  )# One total record per subject and visit: the sum of the collected# component results in laboratory sequence order. No value, rather than# zero, when none of them has a collected result.ordered_sum <- function(x) {  vals <- x[!is.na(x)]  if (length(vals) == 0) {    return(NA_real_)  }  total <- vals[[1]]  if (length(vals) > 1) {    for (v in vals[-1]) {      total <- total + v    }  }  total}totals <- lb |>  arrange(USUBJID, VISIT, LBSEQ) |>  group_by(STUDYID, USUBJID, VISIT) |>  summarise(    AVAL = ordered_sum(LBSTRESN),    .groups = "drop"  ) |>  mutate(    PARAMCD = "TOTAL",    PARAM = "Total of Components",    AVISIT = VISIT,    DTYPE = "CALCULATION"  ) |>  select(STUDYID, USUBJID, PARAMCD, PARAM, AVISIT, AVAL, DTYPE)adlb <- bind_rows(components, totals)dir.create("/app/output", showWarnings = FALSE)write_csv(adlb, "/app/output/adlb.csv", na = "")

solutions/adam-adlb-ordered-sum/result.py

Edit
60 lines
# Reference solution for the yamaa benchmark adam-adlb-ordered-sum (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.from pathlib import Pathimport polars as pllb = pl.read_csv("/app/input/lb.csv", infer_schema=False).with_columns(    pl.col("LBSEQ").cast(pl.Int64),    pl.col("LBSTRESN").cast(pl.Float64, strict=False).alias("AVAL"),)# Keep every collected component record; DTYPE has no value on these.components = lb.select(    "STUDYID",    "USUBJID",    pl.col("LBTESTCD").alias("PARAMCD"),    pl.col("LBTEST").alias("PARAM"),    pl.col("VISIT").alias("AVISIT"),    "AVAL",    pl.lit(None, dtype=pl.String).alias("DTYPE"),)# One total record per subject and visit: the sum of the collected# component results in laboratory sequence order. No value, rather than# zero, when none of them has a collected result.def ordered_sum(values: list) -> float | None:    nums = [v for v in values if v is not None]    if not nums:        return None    total = nums[0]    for value in nums[1:]:        total = total + value    return totaltotals = (    lb.sort(["USUBJID", "VISIT", "LBSEQ"])    .group_by("STUDYID", "USUBJID", "VISIT", maintain_order=True)    .agg(pl.col("AVAL").alias("VALS"))    .with_columns(        PARAMCD=pl.lit("TOTAL"),        PARAM=pl.lit("Total of Components"),        AVISIT=pl.col("VISIT"),        AVAL=pl.col("VALS").map_elements(            ordered_sum, return_dtype=pl.Float64        ),        DTYPE=pl.lit("CALCULATION"),    )    .select("STUDYID", "USUBJID", "PARAMCD", "PARAM", "AVISIT", "AVAL", "DTYPE"))adlb = pl.concat([components, totals], how="diagonal")Path("/app/output").mkdir(exist_ok=True)adlb.write_csv("/app/output/adlb.csv")

solutions/adam-adlb-ordered-sum/result.sas

Edit
32 lines
/* opensas reference solution for the yamaa benchmark adam-adlb-ordered-sum.   Reads the benchmark inputs and derives the requested output.   Execute with the existing opensas runtime: opensas /app/output/result.sas. */data lb;  length STUDYID USUBJID LBTESTCD LBTEST VISIT $1024;  infile "/app/input/lb.csv" dsd dlm="," firstobs=2 truncover lrecl=32767;  input STUDYID : $char1024. USUBJID : $char1024. LBSEQ LBTESTCD : $char1024. LBTEST : $char1024. VISIT : $char1024. LBSTRESN;run;data collected;  length PARAMCD $16 PARAM $1024 AVISIT $1024 DTYPE $11;  set lb; PARAMCD=LBTESTCD; PARAM=LBTEST; AVISIT=VISIT; AVAL=LBSTRESN;run;proc sort data=collected; by STUDYID USUBJID AVISIT LBSEQ; run;data totals;  length PARAMCD $16 PARAM $1024 DTYPE $11;  set collected; by STUDYID USUBJID AVISIT;  if first.AVISIT then do; total=0; count=0; end;  if not missing(AVAL) then do; total+AVAL; count+1; end;  if last.AVISIT then do;    PARAMCD='TOTAL'; PARAM='Total of Components'; DTYPE='CALCULATION';    AVAL=.; if count>0 then AVAL=total;    output;  end;run;data result; set collected totals; run;proc sql;  create table final as select STUDYID, USUBJID, PARAMCD, PARAM, AVISIT, AVAL, DTYPE from result;quit;proc export data=final outfile="/app/output/adlb.csv" dbms=csv replace; run;