TMP-SCI-204 · Planned course · Unfinished learning resource

Unit 5: Reproducible tabular analysis and comparison

TMP-SCI-204. Original teaching following Units 1–4. This is not a new course, execution service or accredited qualification. All sites, samples and values are fictional. Use supplied files in an owned folder and an existing suitable Python interpreter. No installation, account, network, payment, real sampling or private data is required. EXECUTION CAPACITY UNRESOLVED remains.

The question behind a summary

A table can produce a correct arithmetic answer to the wrong question. Before calculating, ask: What does one row represent, which rows count, what denominator matches the question, and what disappeared during processing? This unit develops reproducible scientific table handling. It does not teach SQL syntax, alter a database or replace a statistics course.

You need integer sums, fractions, means and the source/input/run distinctions from earlier units. An arithmetic mean is the sum of included values divided by their count; it is undefined if that count is zero. A weighted mean gives some components more influence through stated weights. We derive the weights needed here rather than assuming previous statistics training.

Proposed workload is 14 unpiloted hours: dictionary/keys 2; inclusion and worked summaries 3; missingness and diagnostics 2; practice/audit 2; quiz 1; project 3; delayed transfer 1. This is not credit or measured learner timing.

Outcomes: define the unit represented by a row; validate unique metadata links; implement an explicit inclusion policy; reconcile counts and row decisions; distinguish pooled and equal-site summaries; conduct bounded missingness sensitivity without inventing observations; reproduce an accessible report and limit its interpretation.

R1. Find the arithmetic mean of 0,4,8,12. Explain why the zero is included in the denominator.

R2. One site contributes four measurements, another two. Does averaging their two means always give the pooled mean of all six measurements? Explain what might differ.

R3. A sample has a missing concentration, represented by null. Is its concentration known to be zero? What evidence would justify recording a measured zero instead?

R4. Two rows have identical numerical values but different sample IDs. Is that enough reason to delete one as a duplicate?

1. The data dictionary is part of the computation

The packet has two small tables, stored together in JSON. JSON is only the file representation; it does not itself establish scientific meaning. The sites table contains site_id and label. The samples table contains sample_id, site_id, value_ug_l and qc.

One sample row represents one planned physical sample slot, with at most one reported concentration. The concentration unit is micrograms per litre. A missing result still has its planned row. It is not silently removed. This distinction lets us see the difference between the number of planned samples and the number of usable observations.

The sample ID uniquely identifies that planned slot across the whole packet. It is not an observation's numerical value and must not be reused at another site. The site ID links a sample to exactly one metadata row. Labels are display names; they are not keys and need not be unique. Renaming a label should not merge two sites or change any measurement.

value_ug_l is an integer from 0 to 1,000,000, or JSON null, which becomes Python None. A zero is a recorded value. Null is unavailable information. The integer scale is a chosen exercise format, not a claim that all real instruments report integers or that a number is physically exact.

qc is either accepted or flagged. In this packet, flagged means the result has not passed the default quality policy. It does not tell us whether the value is too high, too low, or wrong by a known amount. Including flagged values later is a labelled sensitivity exercise, not evidence that they became scientifically acceptable.

The bounded interchange contract permits at most 100 sites and 1000 samples. IDs contain 1–32 ASCII letters, digits, underscores or hyphens and are case-sensitive. Labels are printable, nonblank text of at most 80 characters. The field names are exact; extra/missing fields are rejected. Every sample must reference a known site. Duplicate JSON object keys, duplicate site IDs and duplicate sample IDs are rejected, not silently replaced. Raw UTF-8 input is limited to 1 MiB.

G1. State the meaning and role of each of the six field names across the two tables. Classify sample ID, site ID, label, concentration and QC as identity, metadata, measured-value representation or inclusion information. Explain why the unit and row meaning are not optional decoration.

The sites table declares A=Birch, B=Reed and C=Cove. Each ID occurs once. A lookup from sample site ID to metadata label can therefore attach exactly one label to each sample, without adding or removing sample rows. This is the required one-to-one metadata match for each sample row; many different samples may still reference the same site.

If site A appears twice in the metadata, a naive expansion could duplicate every A sample. The numerical values might look plausible while their influence doubles. If a sample references unknown site X, silently dropping it would change the analyzed population. Our workflow rejects both problems before any filtering or output creation. This is a conceptual key/link check, not a database lesson.

Validation also happens before QC exclusions. A flagged row with an unknown site is still structurally invalid. Otherwise, a change in inclusion policy could reveal data defects that the earlier computation concealed. Preserve the original and resolve a mismatch using reliable source evidence; do not invent an ID or delete inconvenient rows just to make validation pass.

G2. Explain the consequences of (a) duplicate site A metadata, (b) sample B3 referring to unknown X, and (c) two different physical samples both labelled A1. Which are refused, and why should QC filtering not hide them?

3. Work the original packet before executing

The supplied fixtures/worked.json contains these planned slots:

All numeric values above are concentrations in micrograms per litre. The initial policy has two ordered decisions. First exclude a flagged row unless the sensitivity option explicitly permits flagged rows. Then exclude an otherwise eligible row if its value is missing. All remaining rows are included. This assigns one primary decision to each row: flagged, missing or included.

The order matters for accounting. A row can be both flagged and missing in its raw fields, but our default audit classifies it once as flagged. “Excluded missing” therefore means missing among QC-eligible rows, not every raw null in the file. Do not sum overlapping raw attributes as though they were disjoint categories.

For the worked packet, eight samples were planned. One is excluded by QC, leaving seven QC-eligible slots. One of those is missing, leaving six included observations. The conservation checks are:

planned = excluded_flagged + eligible = 1 + 7 = 8

eligible = excluded_missing + included = 1 + 6 = 7.

A row-level audit preserves the sample ID, site ID, original row number and decision. It is easier to find a bad rule by inspecting a specific missing or flagged row than by staring at a final mean. The original input remains unchanged.

G3. Write the decision for each worked sample ID. Verify both conservation equations. Then suppose A5 is both flagged and missing: what is its default primary reason, and what happens if flagged rows are permitted?

4. Pooling rows and balancing sites answer different questions

Site A's included values are 0,4,8,12: sum 24, count 4, mean 6. Site B's values are 12,16: sum 28, count 2, mean 14. The pooled observed mean is (24+28)/(4+2)=52/6=26/3, approximately 8.6667 micrograms per litre.

Adding concentrations here is an intermediate arithmetic sum for a mean, not a total mass of material. No sample volumes are supplied, so the table cannot determine total mass.

This gives each included sample equal weight. It can also be reconstructed from site means using sample-count weights: (4×6+2×14)/6. Simply averaging the two site means gives (6+14)/2=10, which gives each observed site equal weight. Neither number is automatically wrong. They summarize different units, and the report must say which it uses.

Site C has no observations. Its observed mean is undefined, not zero. The companion reports the mean of observed-site means over 2 of 3 declared sites. That is not an equal-weight mean for all three sites, because C's site mean is unavailable. A sum initialized to zero for an empty group does not turn into a measured zero concentration.

Counts belong beside means. “Birch mean 6, n=4; Reed mean 14, n=2; Cove undefined, n=0” carries information missing from a bare bar chart. The linear text summary makes all groups, denominators and exclusions available without relying on colour, bar height or hover interactions. It does not by itself prove that a published reader is accessible.

G4. Derive the pooled and equal-observed-site means in two ways. Explain the weights, the role of C, and why neither summary proves that one site caused a concentration difference or represents every place in a wider region.

5. Change one policy at a time

As a sensitivity analysis, permit flagged rows while keeping missing values unavailable. A5 contributes 16. The pooled mean becomes 68/7, about 9.7143. Site A now has mean 40/5=8; site B remains 14. The mean of the two observed-site means is 11.

This change measures the effect of including that flagged observation. It does not establish which estimate is scientifically better. Keep the original result, the changed policy, the changed row decisions and a statement of what evidence would justify any permanent policy change. Do not change the raw QC label just to reproduce a preferred summary.

Now consider replacing missing B3 with zero. That is a different action: it invents or hypothesizes a measurement value. It must not be silently treated as ordinary missing-data handling. If used as an explicit counterfactual scenario, label it. A measured zero enters the observed denominator, so treating missing as zero can change the mean substantially even though it adds nothing to the sum.

G5. Calculate the flagged-inclusion sensitivity. Separately calculate the default-QC mean if B3 were genuinely measured as zero. Explain why these are alternative changes, not changes to combine without being asked.

6. Bound a missing-value scenario without claiming to observe it

Keep the default QC policy. Suppose, as an explicit hypothetical bound, B3's unobserved concentration x lies in [0,20] micrograms per litre. The complete mean for the seven QC-eligible planned slots would be (52+x)/7. Therefore it lies in [52/7,72/7], about [7.4286,10.2857].

The denominator is seven, not six observed values and not all eight planned samples. We are asking about completing the QC-eligible sample set under a stated missing-value bound. The excluded flagged observation remains outside that set. This scenario does not fill in the input file or relabel B3 as measured.

For m missing eligible values, each bounded by L and U, and observed sum S across a total of N eligible slots, the complete eligible mean is bounded by (S+mL)/N and (S+mU)/N when N>0. This follows by adding the smallest or largest allowed missing contributions. No random-sampling, independence or probability assumption is required. The bounds are conditional on their premises and are not a confidence interval.

The interval is supplied for missing values only. It does not automatically require every observed value to lie inside it. Its scientific credibility would need outside evidence in a real study. If N=0, the complete mean is undefined. If N>0 but every eligible value is missing, the scenario may still give bounds while the observed mean remains undefined.

G6. Derive the worked missing-value interval and identify its population, denominator and assumption. Explain why it is not a confidence interval, an imputed dataset or an estimate for all three declared sites.

7. Execute a recoverable analysis

Keep the source, tests and fixtures together. Use an existing Python 3 interpreter; the author checked Python 3.12.14. Record your actual version. From this package folder:

python3 -B -m unittest discover -v
python3 -B tabular_analysis.py fixtures/worked.json my-table-run-001 --missing-range 0 20

Use your verified interpreter command consistently. If execution is unavailable, trace and design tests, marking outputs predicted. Conceptual work cannot establish that you executed or reproduced a pipeline.

The new output directory contains exact input.json, structured report.json, readable summary.txt, a source snapshot tabular_analysis.py, and a final run.json with environment, arguments, analysis options and four payload hashes. Parsing/domain checks finish before output creation. An existing destination is refused. A later write failure can leave partial output; preserve it and choose a new folder after diagnosing the problem. This is not an atomic transaction or a security sandbox.

Reproduce using the saved source/input and the same explicit options:

python3 -B my-table-run-001/tabular_analysis.py my-table-run-001/input.json my-table-run-002 --missing-range 0 20

Under the same checked conditions, report and summary bytes should match. Arguments in run metadata may differ. Validate the completion JSON and hashes of the four known files; do not execute arbitrary commands or follow unfamiliar paths from an untrusted manifest. Matching hashes check bytes, not authenticity or measurement truth. Work in trusted owned folders and do not edit source while it runs.

For the flagged sensitivity, use another new output name and add --include-flagged. Preserve whichever missing-range option belongs to the intended scenario. A rerun with changed options is a changed analysis, not evidence that the earlier result was irreproducible. The full input remains recoverable even when outputs omit values from arithmetic.

8. Independent practice and audit

I1. A naive metadata expansion duplicates every included A row. Derive the resulting pooled mean and compare it with 26/3. Why is this not a legitimate equal-site weighting method?

I2. Change only A's label from Birch to “Revised label.” Which numerical summaries and row decisions should stay unchanged? Which output bytes need not stay unchanged?

I3. Reverse sample-row order without changing IDs or values. Predict pooled/site summaries, audit row numbers and raw input hashes. Distinguish semantic equality from byte identity.

I4. A packet has one accepted sample with missing value and no observations. State the observed mean and the conditional complete mean bounds if its value lies in [2,8]. Contrast with a packet containing no eligible slots at all.

I5. Propose four independent tests: observed zero, flagged missing overlap, orphan site ID, and duplicate sample ID. State the expected result and what scientific fact the test does not establish.

I6. Explain why the difference between Birch and Reed means is not by itself a causal effect or a representative estimate for a region. Name at least two kinds of missing design information.

H1. “Every nonnumeric cell should be replaced by zero before averaging.” Diagnose the error using the packet.

H2. “The two means are reproducible, so either can be called the average concentration.” What must accompany that phrase?

H3. “The missing scenario is narrow, so it proves the data are unbiased and gives a 95% confidence interval.” Identify the unsupported conclusions.

9. Changed-data quiz: 30 formative points

The same sites are declared. A1=1 accepted, A2=5 accepted, A3=missing accepted. B1=9 accepted, B2=13 flagged, B3=17 accepted. C has no rows. All concentrations are micrograms per litre; each question is worth 6 points.

Q1. Under default policy, derive planned/eligible/included counts, both exclusion counts, site means, pooled mean and mean of observed-site means. Explain why the two means coincide here without being universally interchangeable.

Q2. Permit flagged rows in a separate analysis. Derive the new pooled and equal-observed-site means and identify the changed row decision.

Q3. Under default QC, bound each missing eligible value by [0,15]. Derive the complete eligible mean interval and explain why observed B3=17 does not violate the stated missing-only scenario.

Q4. Someone fixes an unknown site reference by silently discarding that sample. Explain the validation and population problem, and propose a recoverable evidence-based response.

Q5. Execute or explicitly trace the quiz with a discriminating test and a repeat plan. Preserve true source/input/options/output evidence if executed, or label predictions clearly. Include a limitation.

10. Project: defend a denominator and a comparison, 40 formative points

Use fixtures/project.json. A1=2 accepted, A2=6 accepted, A3=10 accepted, A4=missing accepted. B1=8 accepted, B2=12 accepted, B3=16 flagged, B4=missing accepted. C remains declared without rows.

P1. (8 points) Create a row-decision audit and derive default counts, sum, site means, pooled mean and mean of observed-site means. Identify each summarized population.

P2. (8 points) Run and reproduce the default project with --missing-range 0 18, or explicitly trace it. Verify the known-file hashes, report/summary comparison and independent arithmetic. Keep computational evidence distinct from plans.

P3. (8 points) Derive default complete-eligible mean bounds. Then separately permit flagged rows and derive both observed summaries and the revised missing-value bounds. Explain exactly which populations changed.

P4. (8 points) In a distinct alternative, suppose reliable new measurement evidence establishes A4=0 while default QC stays. Derive changed summaries and design tests preventing this alternative from accidentally inheriting flagged inclusion. Explain why a null-to-zero replacement without that evidence would be unjustified.

P5. (8 points) Write a 150–220-word report naming row meaning, units, policies, denominators, observed summaries, conditional missingness bounds, actual-versus-traced evidence and limitations. Avoid causal, population-representative or confidence claims unsupported by the task.

11. Delayed transfer

D1. A new laboratory file has three assay readings from each physical sample. Why does the current one-row-per-planned-sample contract no longer fit? Propose explicit sample/assay identifiers and the aggregation question that must be decided before computing a mean.

D2. A missing result is later described as “below detection limit 3,” not completely unavailable. Explain why null loses information, propose a representation preserving the bound, and state a defensible conditional interval without pretending to know the exact value.

Sources and limits

Official Python JSON documentation and Fraction documentation, opened 4 November 2026, support file/library behavior. The data, arithmetic, bounds and assessments are original. No SQL/database or inference package is used. Specialist moderation, learner trials/calibration and actual accessibility validation remain unperformed. The reader and optional companion files are available; learner execution access remains unresolved. No accreditation, credit, institutional equivalence or completed-semester claim follows.