TExcelTAD
Home › Statistics › Gathering Data

Gathering Data

Good analysis cannot rescue bad data. Before collecting anything, decide what question you want to answer, who or what you need to measure, and how you will measure it. Most statistical disasters start right here, long before any formula is used.

Plan before you collect

  1. State the question precisely. "Do people like our app?" is vague. "What share of users who installed the app in March still open it weekly in May?" can be measured.
  2. Define the population. Everyone the question is about: all March installers, not just the ones who wrote a review.
  3. Choose variables and units. Minutes or hours? Self-reported or logged by the app?
  4. Choose a collection method: survey, measurement, existing records or an experiment.
  5. Decide the sample size and how to pick the sample (see Sample Types).

Common collection methods

Method Strengths Watch out for
Survey / questionnaire Cheap, reaches many people Leading questions, people who don't respond, dishonest answers
Direct measurement Objective, precise Instrument errors, cost
Existing records (logs, registers) Large, already available Recorded for another purpose; may miss what you need
Experiment Can show cause and effect Expensive; must be designed carefully

Bias: when data systematically misleads

Bias is a systematic error that pushes results in one direction. Collecting more biased data does not help. It only makes you more confident in the wrong answer. Typical sources:

  • Selection bias: the people you reach differ from the population (an online poll only reaches people online).
  • Non-response bias: people who answer differ from those who don't (very happy or very angry customers reply more often).
  • Measurement bias: the instrument or the wording distorts the answer ("Don't you agree that…?").

The simulation below shows non-response bias. A town has 10,000 residents whose true satisfaction scores (1–10) we know because we invented them. Unhappy residents are less likely to answer a survey:

python · try it yourself
import numpy as np

rng = np.random.default_rng(11)
satisfaction = rng.integers(1, 11, size=10_000)        # true scores, 1..10
print("true average:", round(satisfaction.mean(), 2))

# chance of answering grows with satisfaction: 10% for a score of 1 ... 55% for 10
p_answer = 0.05 + 0.05 * satisfaction
answered = rng.random(10_000) < p_answer
print("people who answered:", answered.sum())
print("survey average:", round(satisfaction[answered].mean(), 2))
true average: 5.52
people who answered: 3340
survey average: 6.71

Thousands of people answered, yet the survey average is clearly too high. Sample size cannot fix a biased collection process.

Random selection removes selection bias

If instead we choose people at random and (in this simulation) everyone answers, the sample average lands close to the truth even with far fewer responses:

python · try it yourself
import numpy as np

rng = np.random.default_rng(11)
satisfaction = rng.integers(1, 11, size=10_000)

for n in [50, 200, 1000]:
    chosen = rng.choice(10_000, size=n, replace=False)   # simple random sample
    print(f"random sample of {n:4d}: average = {satisfaction[chosen].mean():.2f}")
print("true average:", round(satisfaction.mean(), 2))
random sample of   50: average = 5.14
random sample of  200: average = 5.57
random sample of 1000: average = 5.41
true average: 5.52

Random samples still wobble around the true value, but the wobble shrinks as n grows and, crucially, they are not systematically off in one direction.

Recording data well

  • Use a fixed format from the start (dates as 2025-04-30, decimals with a dot, one unit per column).
  • Record missing values explicitly instead of guessing or leaving zeros: a zero is a real value.
  • Keep the raw data untouched and do cleaning in code, so every step can be repeated.
  • Note how and when each value was collected. It will matter when you interpret the results.
python · try it yourself
import io
import pandas as pd

raw = io.StringIO("""id,date,temp_c,station
1,2025-04-01,12.4,North
2,2025-04-01,,South
3,2025-04-02,13.1,North
4,2025-04-02,11.8,South
""")
readings = pd.read_csv(raw, parse_dates=["date"])
print(readings)
print()
print("missing temperatures:", readings["temp_c"].isna().sum())
   id       date  temp_c station
0   1 2025-04-01    12.4   North
1   2 2025-04-01     NaN   South
2   3 2025-04-02    13.1   North
3   4 2025-04-02    11.8   South

missing temperatures: 1

The empty cell became NaN ("not a number"), pandas' marker for a missing value. Most statistics functions in pandas skip NaN automatically, but you should always know how many values are missing and why.

Test yourself

A gym surveys its members by leaving forms at the reception desk. Which bias is most likely?

  1. Measurement bias from bad scales
  2. Selection/non-response bias: frequent visitors are far more likely to fill it in
  3. No bias, because every member could answer
  4. Rounding bias

A biased survey method is used to collect 50,000 responses instead of 500. What happens to the bias?

  1. It disappears
  2. It is cut in half
  3. It stays: the estimate becomes more precise but still wrong
  4. It becomes random noise

Why should a missing measurement not be recorded as 0?

  1. Zeros are not allowed in CSV files
  2. 0 is a real value and would distort averages and counts
  3. pandas deletes zeros
  4. It makes the file bigger