A reproducible report can still answer the wrong question. In this capstone you will preserve an original defective analysis, reproduce its output, diagnose separate problems, check a corrected pipeline and communicate a bounded scientific conclusion. The batches and model are fictional. No real inspection data, operational quality guarantee or inferential analysis is supplied.
This unit draws together contracts and units, decomposition, exact arithmetic, independent checks, inclusion policies, numerical/model interpretation and controlled random records from Units 1–7. It does not repeat every earlier topic or certify every course outcome. Sixteen proposed hours are unpiloted. The final position in an eight-unit plan does not establish a delivered, accredited or completed semester.
Execution capacity remains unresolved. Use only an existing suitable Python 3 interpreter and its standard library. No installation, account, paid package, API or personal data is required. The printed packets and outputs support conceptual tracing. Label trace-only work and leave execution points unclaimed if you cannot run the files. Actual author runs are not your execution evidence.
Capstone outcomes
- Preserve and reproduce a supplied analysis without mistaking reproduction for correctness.
- Turn a scientific question into a data dictionary, policy, denominator and independently checkable claim.
- Isolate distinct defects, design discriminating tests and compare a corrected implementation.
- Interpret missing-data scenarios, model expectations and one synthetic realization without unsupported inference.
- Preserve inputs, source, options, outputs and failures so another person can inspect and rerun the analysis.
- Transfer the method to changed data while recognizing when a changed meaning needs a different model.
1. Establish the question and the unit of a row
The intended question is: among the opportunities in included fictional inspection batches, what fraction were successes? A row is one batch, not one individual opportunity. opportunities is a positive count of binary opportunities, and successes is the count that succeeded. A known zero means the batch was inspected and no opportunity succeeded. null means the success count is unavailable. The code does not infer why it is unavailable.
Each batch has a unique batch_id and a QC state, accepted or flagged. Under the default policy, flagged batches are excluded. Among the remaining eligible batches, known success counts are included and missing counts are withheld. The optional include-flagged analysis is a separately labeled sensitivity case, not a retroactive assertion that those batches passed QC. Input validity is checked before applying either policy: an impossible flagged row is still invalid data and must not be hidden by filtering.
The supplied model has a rational probability p and a seed. It describes ideal independent trials with the same success probability, as introduced in Unit 7. It generates an illustrative synthetic comparator, not new observations. p is supplied rather than estimated from the fictional input counts. “Observed” below means recorded in this exercise's fictional packet, not measured from a real process.
worked.json contains five batches:
- B1: 2 opportunities, 0 successes, accepted.
- B2: 8 opportunities, 6 successes, accepted.
- B3: 4 opportunities, 3 successes, flagged.
- B4: 6 opportunities, missing successes, accepted.
- B5: 4 opportunities, 2 successes, accepted.
The model uses p=1/2 and seed 11. The correct default decisions are included, included, flagged, missing, included. Every planned row receives exactly one decision. This row-accounting identity is useful: planned batches = included batches + flagged exclusions + missing exclusions. The precedence matters for a flagged-and-missing row: it is flagged under the default policy, but becomes a missing eligible row when flagged inclusion is explicitly enabled.
R1. Distinguish reproducing an output, verifying an implementation against a contract, and validating a scientific model. Name evidence needed for each and identify which the printed original report alone can establish.
R2. Two included batches have counts 2/8 and 1/2. Compute the pooled opportunity rate and the unweighted mean of batch rates. Explain their different weighting.
R3. Explain the difference between successes=0 and successes=null for a batch with six opportunities. Why must neither be silently converted into the other?
R4. A flagged row reports seven successes from four opportunities. Should the default analysis silently ignore it or reject the packet? Explain the order of validation and policy filtering.
2. Preserve the flawed result before correcting it
legacy_analysis.py is deliberately defective exercise material. It reads the supplied packet, filters with the truth value of successes, averages batch rates, resets the seed before every selected batch, and prints a report. Its claim that reproduction proves real-process validation is intentionally false. It must never be used as accepted production analysis.
The original worked output is retained in fixtures/legacy-worked-report.json, with source/input/output hashes and the recorded Python version in legacy-evidence.json. That public record normalizes the interpreter path to python3; it preserves the arguments and results but is not the exact original absolute invocation. It includes B2,B3,B5, labels 2/3 as a “pooled” rate, and gives synthetic counts B2=4, B3=1, B5=1. You can reproduce that output exactly and still reject it as a correct answer. Preserve the legacy script and report; write corrections separately rather than erasing the evidence of what changed.
A useful issue record separates symptom, cause, affected claim, discriminating test and correction. For example: “B1 is absent; the truth-value filter treats numeric zero as false; the eligible population and denominator change; a zero-success accepted row must remain included; use an explicit null check after QC.” Do not bundle every disagreement into “bad data” or change several mechanisms at once and assume you know which caused the new result.
The original has at least four computational defects relative to the intended contract: losing zero counts, ignoring QC flags, labeling an equal-batch mean as a pooled opportunity rate, and restarting the synthetic stream for each selected batch. Its scientific-validity statement is a separate unsupported claim. A numerical coincidence could hide any one of these in a particular dataset, so tests need deliberate edge cases, not just a plausible-looking final percentage.
G1. Write a five-item issue record covering the four computational defects and the scientific claim. For each, state one concrete check that could reveal it.
G2. Reproduce or trace the legacy worked output. Explain precisely why its admitted IDs, 2/3 label and repeated short synthetic prefixes are consistent with its defective code. Do not present this as an accepted answer.
G3. Starting from the unchanged worked packet, apply validation and the default decision rule. List included, missing and flagged IDs and check the row-accounting identity.
3. Reconstruct the corrected arithmetic independently
For included batches, pooled rate = total successes / total opportunities. The worked default includes B1,B2,B5, so successes=0+6+2=8 and opportunities=2+8+4=14. The pooled rate is 4/7. This weights each opportunity equally.
The unweighted mean of the three batch rates is (0/2+6/8+2/4)/3=5/12. This gives each included batch equal weight regardless of size. Neither formula is intrinsically meaningless, but they answer different questions and need accurate labels. With equal batch sizes they agree; they may also agree by coincidence with unequal sizes. Equality on one fixture does not prove the implementation uses the correct denominator.
Use exact integer sums and Fraction results rather than rounding individual percentages before pooling. Exact arithmetic describes the supplied numbers; it does not make the fictional input counts a precise account of an actual process. Keep row counts, opportunity counts and success counts separate: “three included batches” is not the denominator for a pooled opportunity rate.
Missing B4 has six known opportunities and an unknown success count between zero and six. Among all default-eligible opportunities, there are 20 opportunities. Under only that stated bound, the complete-eligible rate lies between 8/20=2/5 and (8+6)/20=7/10. These endpoints are conditional deterministic scenarios, not imputed observations, confidence intervals or claims about why the count is missing. The observed-only rate 4/7 and complete-eligible range answer related but different questions. Flagged B3 is outside the default eligible population and does not enter that bound.
If no batch is included, the observed pooled rate and mean batch rate are undefined, represented by null, not zero. If eligible opportunities exist but every success count is missing, their complete-eligible bound is [0,1]. If no eligible opportunity exists, both bounds are null. A known zero numerator with a positive denominator is different from having no denominator.
G4. Calculate the worked default pooled rate and mean batch rate independently. Then, using only legacy-admitted B2,B3,B5, calculate their actual pooled rate and compare it with the legacy's 2/3 output.
G5. Derive the default missing-count bound and state its population, assumptions and limitations. Explain why the missing batch is not simply filled with zero.
4. Inspect the synthetic comparator without turning it into evidence it is not
For a supplied p=a/d, each synthetic trial draws an integer x from 0 to d-1 and succeeds if x<a. The corrected implementation seeds one local random.Random instance once and draws for every planned row in the original order, including flagged and missing rows. It stores the raw draws and synthetic count for each batch. This fixed draw plan means changing the inclusion policy does not change the raw simulated records assigned to those rows.
For the worked packet under the recorded Python 3.12.14 implementation, the five synthetic batch counts are B1=0, B2=4, B3=3, B4=5, B5=3. The default observed analysis includes B1,B2,B5, so its comparator has 7 synthetic successes in the same 14 opportunities, rate 1/2. Its model expected count is 14×1/2=7. This particular realization equals the expectation; that is not guaranteed. The fictional observed count is 8, a distinct number with a distinct role.
Generating values for B4 does not recover its missing observed count. B4's synthetic five must not be inserted into successes. A simulated value from a chosen model is not a newly measured value. Likewise a comparator close to the observed rate does not validate independence, common probability, QC decisions or the real process. The program supplies no goodness-of-fit test or uncertainty interval.
Reordering rows leaves the observed arithmetic unchanged but can change which stream segment is assigned to each batch. A changed numerator with the same denominator/seed/order changes the success rule while retaining the raw draws. A changed denominator or inserted random call can change the stream. Preserve input order, exact source, options and environment; same seed alone is not a complete reproduction specification. See Unit 7 for checkpoint/state continuation; this capstone preserves raw draws and full seeded reruns rather than offering a new checkpoint interface.
G6. Explain the difference between worked observed count 8, synthetic count 7 and model expected count 7. Identify which batches enter each reported comparison and why synthetic B4=5 must not replace its missing input count.
5. Correct by contract, then test deliberately
The separate audit_pipeline.py is the corrected reference companion, not a modification to the legacy artifact. Read its validation, decision and summary functions after making your own issue record. A test is useful when it would reject a plausible wrong implementation. Include accepted zero, flagged valid, accepted missing, unequal batch sizes, no included data, invalid excluded rows and repeated raw-stream reproduction. Testing only a dataset where all rates happen to be equal cannot expose a wrong weighting rule.
All model fields are JSON integers: numerator 0–denominator, denominator 1–1000, seed 0–4294967295. The packet has exactly batches and model. There are at most 40 rows; zero rows is allowed as a diagnostic. Each row has exactly batch_id, opportunities, successes and qc. IDs start with an ASCII letter, then contain at most 15 letters, digits, underscores or hyphens; they must be unique. Opportunities is an integer 1–100. Successes is null or an integer from zero to opportunities inclusive. Booleans and numeric strings are not valid integers. QC is accepted or flagged. The byte limit is 64 KiB, and duplicate JSON keys and nonfinite constants are rejected before analysis.
I1. Design three small independent tests that separately catch zero omission, wrong weighting and ignored QC. Give exact expected results and explain why the tests distinguish those defects.
I2. Run or trace the worked include-flagged sensitivity using the unchanged input. Calculate observed totals, both rates, missing bounds, synthetic comparator and expected count. Explain what changes and what stays fixed.
I3. Consider a separate, explicitly hypothetical packet in which B4 is reliably known to have zero successes. Keep the default QC policy. Calculate pooled rate, mean batch rate and missing bounds. Explain why this differs from an unjustified zero imputation.
I4. Reverse the input row order in a separate copy. Predict which observed results should remain invariant and which per-batch synthetic records may change. Explain why changing QC policy alone must preserve raw draws in the corrected design.
I5. Execute the corrected worked run, a saved-source/input replay with the same option, and all 16 named tests if possible. Preserve hashes, commands and exit results. If tracing, describe the checks without claiming execution.
I6. Construct one missing-only packet and one all-flagged packet under the default policy. Explain null observed rates, [0,1] versus null bounds, and why neither is an observed success rate of zero.
6. Produce recoverable evidence
From this unit's folder, use an existing suitable Python 3 command:
python3 -B legacy_analysis.py fixtures/worked.json
This prints the intentionally flawed result. Compare it with the retained original report without changing either. Then run the corrected reference into a new folder:
python3 -B audit_pipeline.py fixtures/worked.json corrected-run
A separate sensitivity run adds --include-flagged and uses another new folder. The source snapshot, original input bytes, report.json and linear summary.txt are hashed in run.json. The manifest also records include_flagged, invocation and interpreter. To reproduce a sensitivity run, use its saved audit_pipeline.py and input.json and supply the same flag; the saved input alone does not encode this command option.
Completion requires a parseable manifest with status complete, all four expected payload files, and matching recomputed SHA-256 values. Compare report/summary contents under the same recorded interpreter and options, not path-dependent manifests. Hashes detect changes, not authorship, scientific validity or malicious rewriting of both files and manifest.
The runner refuses existing destinations. A failed write can leave partial output or a partial run.json. Keep that evidence, diagnose and choose a fresh destination. Do not rename an incomplete folder to “passed,” fabricate expected output or overwrite the legacy artifact. This is recovery-friendly retention, not atomic/durable storage assurance, malicious-path defense or protection against a concurrent source edit.
H1. The legacy report says reproduction proves a validated real-process probability. Replace this with a defensible statement that distinguishes reproduced defects, corrected computational evidence and unperformed empirical validation.
H2. An analyst changes QC policy until one reported rate matches the supplied p, then presents only that result. Explain the selection problem and give a transparent comparison plan.
H3. An interrupted directory contains run.json but its report hash does not match. A colleague wants to keep the completion status because the printed number looks right. Explain the correct response and what evidence is needed before declaring a later run complete.
7. Formative quiz: a coincidence that can hide a bug
quiz.json rows are A:3 opportunities/0 successes/accepted; B:6/3/accepted; C:2/2/flagged; D:4/missing/accepted; E:3/3/accepted. The model is p=1/2, seed7. Corrected synthetic counts in the original order are 1,5,2,2,2. The quiz totals 30 formative points, six per question.
Q1. Calculate default inclusion decisions, observed totals, pooled rate and mean batch rate. Explain why their equality does not prove the two formulas are interchangeable. [6]
Q2. Calculate the include-flagged sensitivity rates and both default and sensitivity missing bounds, with clearly named populations. [6]
Q3. Calculate the default included synthetic count/rate and model expected count. Contrast them with the fictional observed data and state the limits of this comparison. [6]
Q4. Trace the legacy admission and average on this quiz packet. Calculate its admitted rows' actual pooled rate and identify the hidden zero/QC/weighting issues. [6]
Q5. Describe and, if possible, execute a corrected quiz run and saved-source replay, including option provenance, hashes, meaningful comparisons and interruption handling. One point requires actual execution; trace-only maximum is five. [6]
8. Formative capstone project
project.json rows are P1:4/0/accepted; P2:12/6/accepted; P3:3/3/flagged; P4:5/missing/accepted; P5:6/3/accepted; P6:10/8/accepted. Its model is p=2/3, seed23. Corrected synthetic counts are 3,10,2,4,3,6 in original order. Each task is worth eight points, totaling 40 formative points. Preserve the original packet and label every alternative.
P1. Write the data/policy contract and independently calculate all default decisions, observed totals, both rates and missing bounds. Identify which earlier reasoning checks you reused. [8]
P2. Produce actual base and include-flagged runs, a saved-source replay of the flagged run with its option preserved, manifest/hash checks, output comparisons and the 16-test result. Five points require execution evidence; a trace-only plan can earn at most three. [8]
P3. Compare two separate alternatives: include flagged P3 using the original data; or keep default QC and suppose P4 is reliably observed as zero. Calculate both rates and missing bounds for each. Explain why these are different changes, not interchangeable fixes. [8]
P4. Audit the default synthetic comparator from the supplied counts: calculate its count/rate and expected count, compare with observed counts, and write a cautious interpretation. Explain why P4's synthetic count cannot close the observed missing-data gap. [8]
P5. Assemble a correction dossier: preserve the legacy evidence, connect each computational defect to a regression test, give an accessible findings/limits statement, record execution status and recovery steps, and name what remains before applying the model to actual data. [8]
9. Delayed transfer: reject a changed meaning when necessary
D1. A new file counts repeated inspections of the same physical items as separate opportunities. Explain what the pooled rate now describes, why it is not automatically a distinct-item pass fraction, and which identifiers/assumptions a revised analysis needs.
D2. Another file has three inspected items and four defects because one item can have several defects. Is four a valid binary-success count for three opportunities under this contract? Explain the appropriate rejection and the meaning of a possible defects-per-item rate. Do not silently clamp or relabel it as a probability.
Use the explained key after a genuine attempt. The objective is a defensible, inspectable chain from question to evidence and claim, not a pleasing final percentage.