Lab · Programming · 6 sections

Capstone: build and review a small analysis

Carry one synthetic cohort analysis from specification through code, tests, AI review and a reproducible handoff.

No account needed to read online.

What it covers

  • The assignment
  • Write the specification
  • Build the workflow
  • Add a test suite
  • Review an AI contribution
  • Deliver the analysis

STATISTICAL PROGRAMMING LAB

Who had a return visit within 30 days?

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

idarmfollowup
1A30
2A30
3A12
4B30
5B30
6B30

visits

idday
18
112
231
430
60

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?

Read online

Capstone: build and review a small analysis

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, clarifications and applications of this resource.

Loading discussion…