Skip to course content
Free Python statistics course

Statistical Data Analytics with Python

Unit 02.00: Outcome, predictor, grouping, unit, window

Five decisions define what the analysis is, and all five are made before any code runs.

Outcome, predictor, grouping, unit, window

The outcome is what you measure. The predictor is what you think relates to it. Any grouping says the analysis runs within strata. The unit of analysis says what one row represents. The time window says which observations are eligible.

The unit is the one that catches people. The same table can be analysed per delivery or per driver, and since every standard error divides by the square root of n, the choice moves every interval and every p-value in the report.

None of these are technical decisions. They are statements about which question you are answering.

This block states the five and then shows what the unit choice does.

import pandas as pd

spec = {
    "Outcome":          "delivery_minutes (numeric)",
    "Predictor":        "route_plan (old or new)",
    "Grouping":         "none -- single stratum",
    "Unit of analysis": "one delivery",
    "Time window":      "2026-03-01 to 2026-03-31 inclusive",
}
for k, v in spec.items():
    print(f"{k:18s} {v}")

deliveries = pd.DataFrame({
    "delivery_id": range(1, 9),
    "driver_id":   [1, 1, 1, 2, 2, 3, 3, 3],
    "route_plan":  ["old", "old", "new", "new", "old", "new", "new", "old"],
    "minutes":     [34, 41, 29, 31, 38, 27, 30, 36],
})

print()
print(f"Rows: {len(deliveries)}   distinct drivers: {deliveries.driver_id.nunique()}")
print(f"If the unit is the delivery, n = {len(deliveries)}")
print(f"If the unit is the driver,   n = {deliveries.driver_id.nunique()}")
print()
print("The same table supports two sample sizes. Every standard error divides")
print("by sqrt(n), so the choice moves every interval in the report.")

The specification names an outcome, a predictor, no grouping, the delivery as the unit and a one-month window. The data then holds 8 rows from 3 distinct drivers. If the unit is the delivery, n = 8. If it is the driver, n = 3. The same rows, two sample sizes, and everything downstream depends on which you meant.

The mistake this prevents

The mistake is never stating the unit and letting it default to whatever the table's row grain happens to be — a decision made by the export format rather than by the analyst.

Takeaway

Write all five decisions down before analysing. Be explicit about the unit, and check that the analysis table's grain actually matches it.