AAmit’s LibraryLEARN · PRACTISE · REFLECT

Research and evidence × Programming

Business lens: Research and evidence · Technology lens: Programming

Reading scope: Original fictional teaching. Selected documentation and same-author checks are not independent editorial validation.

Code turns a method into repeatable decisions

A fictional researcher analyses employee survey responses about confidence using a new purchasing system. A short script removes incomplete rows and reports an average. The code is convenient, but its rules determine which evidence survives. Research and programming meet at operational definitions: how a response is parsed, when a value is missing and what makes a record eligible. Write those rules in ordinary language before implementation. A variable named confidence does not establish that the survey item measures the intended construct. The program should enact the declared method and expose exceptions, rather than quietly inventing analytical decisions during execution.

Make transformations inspectable

The researcher owns the method, an analyst implements it and a reviewer checks the relationship between the two. Distinguish blank, invalid and genuine zero values. A zero can be a meaningful answer if the scale permits it. Keep the original input unchanged and create a transformed version with an exclusion log. Python’s random documentation describes seeded pseudorandom generation and sampling functions; recording the generator settings can help reproduce a sampling step, but does not make a convenience population representative. This exercise uses explicit invented values rather than claiming a sampled dataset. A reproducible bug remains a bug until its analytical rule is corrected.

Worked missing-value error

Eight invented responses use a scale from zero to five: 0, 1, 2, 3, 4 and 5 are valid values, and two entries are blank. The six valid values sum to fifteen, giving mean 15/6 = 2.5. A filter that treats all values evaluating as false as missing removes the genuine zero as well as blanks. It then reports 15/5 = 3.0, overstating the valid-response mean by 0.5 scale units, or 20% relative to 2.5. Valid-response coverage is 6/8 = 75%, not the erroneous five-of-eight coverage of 62.5%. The error is in the eligibility rule, not the survey arithmetic.

Test meaning at the boundaries

Correct the parser to distinguish an explicit zero from an absent response. Include invalid text, an out-of-range value and a blank in a separate test table. Do not silently convert every parsing failure to zero, because that creates responses no participant supplied. State how exclusions affect the target population and consider whether nonresponse is related to confidence. Even the corrected mean describes only the six stipulated valid responses. A small fictional example verifies an implementation rule, not the reliability of a survey instrument or its organisational interpretation. Code review should examine assumptions and outputs, not merely whether the file runs without exceptions.

Practice a transparent analysis function

Extend the existing Python descriptive-statistics lesson with the eight-entry scale example and an eligibility specification. Show the incorrect five-value selection and the corrected six-value selection, reproducing 3.0, 2.5, 62.5% and 75%. Your portfolio should include an immutable raw list, an exclusion log and an explanation of the twenty-percent relative overstatement. This is a proposed extension of existing bounded practice, not a new executable survey-analysis fixture. Any local implementation should retain its actual output and version. If a sampling routine is added later, record its settings and population frame separately from the missing-value correction.

Questions and four levels

Who specifies validity, and Whom should a programmer consult about the scale? Whose zero response is lost? What does blank mean, Where is raw input retained, and When are exclusions applied? Why is reproducibility insufficient? Which test distinguishes zero from missing? How can nonresponse affect interpretation? Foundation learners identify a legitimate zero. Undergraduate learners implement and calculate explicit eligibility rules. Postgraduate learners critique parsing, nonresponse and construct validity. DBA/research learners develop a reproducible analysis protocol with independently checked transformations and a bounded methodological contribution. For revision, explain why fixing the code restores the declared six responses without supplying the two unknown answers or proving that the survey measures confidence well.

Study questions and answers

What is the valid-response mean?

(0+1+2+3+4+5)/6 = 2.5 on the stated zero-to-five scale.

Marking guide: Credit 15/6=2.5 with legitimate zero retained on zero-to-five scale.

What does the erroneous filter report?

It removes zero, giving 15/5 = 3.0; the overstatement is 0.5 units or 20% relative to 2.5.

Marking guide: Credit erroneous 3.0 mean,0.5-unit/20% overstatement caused by dropping zero.

What remains unknown after correcting the filter?

The two blank answers and the consequences of nonresponse remain unknown; correction does not establish construct validity.

Marking guide: Two blanks/nonresponse consequences remain unknown; corrected filter does not establish construct validity.

Practice task

Specify and test a survey parser that separates zero, blank, invalid and excluded values.

Practice bridge

  1. Specify and test a survey parser that separates zero, blank, invalid and excluded values.
  2. Reproduce the worked arithmetic, change one assumption and label invented evidence separately from actual practice observations.

Open connected lab

Boundary: Original fictional exercise connected to an existing bounded or guided lesson. No new executable fixture, external platform execution or catalogue lab claimed.

Sources and further reading

  • Python random module documentation
    Scope: Selected seeded generation and sampling descriptions checked; not a representative sampling design or security implementation.
    Access: Free public official documentation
  • Python built-in types — Truth value testing
    Scope: Numeric zero, None and empty strings are false in truth tests; nonempty string zero is not numeric zero. This source supports explicit missing-value checks, not survey validity.
    Access: Free public official documentation

Related chapters

Interactive practice

Open workshop · Open runnable practice · Open lab lab-17

Open interactive matrix reading