Six people, two groups, and a visit log with repeat visits. Build an endpoint, compare risks, then audit three proposed pieces of code.
Inspect the source tables
Day 0 is enrollment. Follow-up is the number of days with complete capture of return visits. The visit log can include records outside the endpoint window.
cohort
id
arm
followup
1
A
30
2
A
30
3
A
12
4
B
30
5
B
30
6
B
30
visits
id
day
1
8
1
12
2
31
4
30
6
0
SQL workbench
Return one row per arm, ordered by arm. Name your columns arm, events, observed and risk. Each person contributes once. Keep the risk as a decimal and exclude unknown outcomes from its denominator.
Explain the group comparison
With 12 days observed, person 3 has an unknown outcome. Group A has one event among two observed people (50%). With 30 days and no visit, that person becomes an observed zero and group A falls to one in three. Group B stays at one in three. The change comes entirely from outcome ascertainment.
Code review desk
events = [x for x in outcomes if x]
risk = sum(events) / len(events)
Which issue or review action matters here?
The assignment
Create a reproducible person-level analysis for a synthetic cohort. Each person has a unique ID, a treatment group, and an outcome measured at one year. Some outcomes are missing. Report enrolled, observed, missing, events, and observed risk by treatment group. Use R, Python, or SQL. State that this is a descriptive comparison and do not label it a treatment effect.
Write the specification
Define one row per person. The population includes people with an assigned group. The outcome is a binary one-year event. Report event risk among participants with an observed outcome, separately by group. Missing outcomes stay missing. Before coding, write the expected counts for a five-row hand-worked dataset and identify what would make the comparison misleading.
Build the workflow
Create a project with a README, analysis script or query, tests, and generated output folder. Validate unique IDs, allowed group labels, binary outcomes and missingness. Produce one row per group with enrolled, observed, missing, events and risk. Save the output with a date or version identifier and keep raw input unchanged.
Add a test suite
Include the original five-person example, a group with no observed outcomes, a group with zero events, a duplicated ID, an invalid outcome and a duplicated visit record. Confirm that an empty denominator yields an undefined risk, not zero. Compare counts before and after every join.
Review an AI contribution
Ask an AI assistant to add one test or refactor one small function. Supply only synthetic data. Write the expected behavior before prompting. Inspect the complete diff, run existing and new tests, and verify that the refactor preserves the output. Document a defect you caught or explain why the proposed change passed review.
Deliver the analysis
A complete submission includes the specification, code or query, tests, README instructions, software versions, and generated group summary. A second analyst should be able to reproduce the summary from a clean copy without guessing a hidden step. In the conclusion, distinguish the descriptive contrast from causal interpretation and identify the missing-outcome limitation.
Discussion
Questions, précisions et applications de cette ressource.