Lab · Programming · 5 sections

Is the code good enough to use?

Decide whether analysis code is ready to share using hand calculations, edge cases and a reproducible review.

No account needed to read online.

What it covers

  • Match the result to the question
  • Run a small acceptance suite
  • Test changes that should preserve the result
  • Make and document the decision

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 six rows ordered by id, with columns id and event. Count a visit on days 1 through 30 inclusive. A person with no qualifying visit needs 30 days of follow-up to be classified as event-free. Otherwise the outcome is unknown.

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

SELECT arm, AVG(event) AS risk
FROM outcomes JOIN visits USING (id)
GROUP BY arm;

Which issue or review action matters here?

Read online

Is the code good enough to use?

Match the result to the question

First ask whether the code answers the stated question. Confirm the unit of analysis, eligibility, follow-up, outcome definition, numerator, denominator, and missing-data handling. A numerically plausible answer can still target the wrong population or quantity.

Run a small acceptance suite

Check expected counts before percentages. Independent hand calculations make a useful acceptance suite for this example.

Input                 Events   Observed   Proportion
[1, 0, missing, 0, 1]      2          4         0.50
[0, missing]               0          1         0.00
[missing, missing]         0          0    undefined
[2]                        reject as invalid

Test changes that should preserve the result

Test invariants and structure. Reordering independent rows should not alter a simple summary. Adding a person with a missing outcome should increase enrolled and missing counts while leaving observed risk unchanged. Duplicate IDs should fail or be resolved by a documented rule. After joins, check row counts and key uniqueness.

Make and document the decision

Use this decision rubric before sharing an analysis. Ready means the question and row unit are clear, inputs are validated, expected cases pass, the workflow reruns from a clean session, outputs match the specification, and a reviewer can trace code to results. Needs revision means a fixable issue remains. Hold the result when the denominator, source data, cohort construction, or output cannot be explained. Record the issue, fix it, rerun the affected checks, and update the review note.

Review a real pull request

Read the README and change summary first. Run the stated command from a clean checkout. Compare generated tables with expected results. Inspect the diff for hard-coded paths, silent row drops, broad exception handling, unpinned dependencies, and accidental data files. Leave comments tied to specific behavior, then rerun after revisions.

Discussion

Questions, clarifications and applications of this resource.

Loading discussion…