Stage 2 summary. Modelling and statistics

9 min 7 concepts 4 figures

Modelling and statistics is where structure and evidence meet. The first half asks how data should be shaped so that a stored fact has one version and a query means one thing: the relational schema that protects writes, the dimensional schema that serves reads, and the harder problem of deciding that two records describe the same person when nothing in either says so. The second half asks what a number is allowed to support, through distributions, the mathematics model training runs on, statistical inference, and the discipline that keeps a machine learning result honest once real users reach it.

One habit connects both halves: somebody has to write down what a row means and defend it. A fact table with an undeclared grain, a linkage threshold nobody owns, a summary statistic chosen without looking at the shape of the data, and a model evaluated on rows that leaked into its own training set are one failure in four costumes, an unstated assumption that stays invisible until the arithmetic diverges.

What you carry out of this stage

  • Read an entity-relationship sketch, explain what a key guarantees, and say why a natural key eventually betrays the model that trusted it
  • Normalise a small schema to third normal form and name the three anomalies it guards against
  • Design a star schema with one fact and three dimensions, starting from a written grain
  • Place one big table and the data vault against the star on the change-cost and query-cost axes
  • Explain probabilistic record linkage at the Fellegi and Sunter level of intuition, and say who owns the threshold
  • Use vectors, matrices, gradients, Bayes and entropy to read what a model is doing rather than only what it outputs
  • Choose a summary statistic from the shape of the distribution, and rule out alternative explanations before calling a correlation evidence
  • Read a confidence interval, state what a p-value is and is not, and design an A/B test that survives review
  • Separate training, validation and test discipline from leakage, and name what changes when a model reaches production

Stage 2 route: from structure to uncertainty

Stage 2 runs in two halves: modules one to three give the facts a shape you can query and modules four to seven say how sure you are of what that shape returns, and they run in that order because shape without uncertainty produces confident nonsense.

Stage 2 runs in two halves. The first gives the facts a shape you can query; the second says how sure you are about what the shape returns. Skip either half and the other one misleads you.

Stage 2 route: from structure to uncertainty Two headed rows of module cards. The upper row, headed Give the facts a shape and tagged Modules 1 to 3, holds 01 Data modelling basics, 02 Relational and dimensional modelling, and 03 Master data and entity resolution. A red arrow drops from below that row, labelled structure you can query, then evidence you can defend. The lower row, headed Say how sure you are and tagged Modules 4 to 7, holds 04 Mathematical foundations, 05 Probability and distributions, 06 Inference and experiments, and 07 Advanced analytics and machine learning. Each card ends in a grey line naming what it gives you. A filled red band closes the figure with what Stage 2 hands to Stage 3. Give the facts a shapeModules 1 to 3 01Data modelling basicsentities, keys, relationships 02Relational anddimensional modellingnormal forms and star schemas 03Master data and entityresolutionone customer, one identifier Say how sure you areModules 4 to 7 04Mathematicalfoundationsnotation you can read 05Probability anddistributionshow spread behaves 06Inference andexperimentsclaims with error bars 07Advanced analyticsand machine learningprediction, held honest structure you can query, then evidence you can defend What Stage 2 hands to Stage 3A shape the engineering stage can build against, and a stated limit on what the numbers prove.

Conceptual, logical and physical models answer three different questions

Modelling runs at three levels and confusing them makes design conversations circular. The conceptual model names the real-world things and how they relate: a customer places orders, an order contains products. The logical model expresses that as attributes, keys, relationships and constraints, without committing to a database product. The physical model decides table names, column types, indexes and partitioning. The hard work is nearly always conceptual. Customer is easy to say and difficult to model, because whether a customer is a person, a household, an account or a supply point decides how many customers the organisation has and how consent applies.

A primary key guarantees that no two rows share a key value, not that each real-world thing appears once: one customer can still be stored twice under two keys, which surrogate keys make easy. A foreign key lets the database refuse a reference to something that does not exist. A natural key uses a real-world value such as an email address or a product code, and it betrays the model as soon as that value changes, is reused, turns out not to be unique, or has to be redacted. A surrogate key is an internal identifier no business process can revise, which is why it survives. Operations and analytics model the same subject differently on purpose, one shaped to keep concurrent writes correct and the other to answer questions over large scans.

Third normal form protects writes, the star schema serves reads, and the grain decides both

Normalisation organises a schema so each fact is stored in exactly one place. First normal form requires every cell to hold a single value; second normal form requires every non-key column to depend on the whole key rather than part of it; third normal form requires that no non-key column is determined by another non-key column, which moves a city determined by its postcode into its own table. What that buys is protection from the three anomalies those dependencies cause: an update landing on some copies of a fact and not others, an insertion that cannot be made because the fact has nowhere to live, and a deletion that takes the last record of something with it. The cost is joins, fair for small keyed reads and poor for scans over hundreds of millions of rows.

Analysis wants a different shape. A star schema puts one fact table of measurements at the centre with descriptive dimensions around it, and no dimension joins another. Once the business process is chosen, the first decision is the grain: a written statement of what one fact row represents, such as one row per order line. It is declared before any column is chosen, because it settles which measures may be added up and which dimensions can join. An order-level discount summed at order-line grain is counted once per line, which is the arithmetic behind two dashboards that agree for eleven months and then differ by four per cent. Dimensions that change over time force a second decision, between overwriting an attribute and versioning it, and the wrong answer is leaving it unmade. One big table folds the star flat into the easy-to-query, expensive-to-change corner: defensible as a serving artefact rebuilt from a modelled core, damaging as the only place meaning is defined. A data vault earns its complexity when many sources describe the same entities and every attribute must trace to its load.

One fact table, four dimensions, and one grain stated first

One fact table states the grain, one row per order line, and four dimensions hang off its join keys, so the grain settles both which measures may be added up and which dimension is allowed on the table at all.

A star schema is one fact table at a stated grain with one dimension on each join key. State the grain first: it settles which measures may be added up and which dimensions can join the fact at all.

One fact table, four dimensions, and one grain stated first A corner star. At the centre a red-tinted fact card, sales_order_line, states its grain as one row per order line, then lists its measures: quantity sold, net sales value, line discount amount. Four white dimension cards sit at the corners: dim_date top left, dim_customer bottom left, dim_product top right, dim_store bottom right, each listing the attributes it carries. Four brand-red rays leave the fact card's side walls and radiate to each dimension, labelled on their midpoints with the join key: date_key, customer_key, product_key, store_key. No ray joins one dimension to another. A red band closes: a dimension that cannot join at the stated grain does not belong on this fact table. State the grain first; everything else follows from it Fact tablesales_order_lineGrain: one row perorder lineMeasures:quantity soldnet sales valueline discount amount Dimensiondim_dateday, month, yearholiday flag Dimensiondim_customersegment, regionsigned-up date Dimensiondim_productcategory, brandunit of measure Dimensiondim_storesite, region, typetrading hours date_key customer_key product_key store_key A dimension that cannot join at the stated grain does not belong on this fact table.

Without a shared identifier, deciding two records are one person is a statistical judgement

Master data is the small set of entities many systems must refer to consistently: customers, patients, suppliers, products, sites, assets. Transactional data records events and nearly always points at one of them. Reference data is the controlled list of permitted values, with a publisher and a version, and two systems holding different vintages of it produce joins that are wrong in ways that look plausible. The test is what breaks when a value changes: a transaction correction fixes one event, a reference code change reclassifies a population, and a master data change alters who the organisation thinks it is dealing with. Entity resolution is deciding which records describe the same real thing, and it is hard because the systems at the seams were never asked to share a key. Names vary lawfully, addresses vary structurally and dates of birth are mistyped.

The chain has five steps: standardise every field, block so only pairs agreeing on something cheap are compared, compare each field on a scale rather than as equal or not, score the agreement pattern into one number, and decide against a threshold. Fellegi and Sunter set out the intuition in 1969. The ratio between how often a field agrees for a true pair and how often it agrees by chance is the evidence that field carries, and its weight is the logarithm of that ratio, which is why the weights add: a rare surname carries strong evidence and a common forename almost none. Blocking is the step whose errors are invisible, because a pair never generated cannot appear in any precision measurement. The threshold is a business decision rather than a statistical output, since a false match gives one person another's history while a missed match leaves a vulnerable customer flag on the record nobody reads. Splink, the Ministry of Justice's open library, is the worked public-sector implementation.

From duplicate records to one golden record through one gate

Standardise, block, compare and score end at a gate with two routes, and the grey band is the second one, so a pipeline drawn with only the automatic route has to set a threshold that either merges two people or leaves one person split in two.

Entity resolution is standardise, block, compare and score, then a gate with two routes: link the confident matches and send the grey band to a person who rejoins the same link step. A pipeline with only the automatic route merges the wrong people quietly.

From duplicate records to one golden record through one gate A chain across the top and a fork below it. Five cards run left to right, Source records, Standardise, Block, Compare and Score, joined by arrows labelled records as captured, one value per field, candidate pairs and agreement pattern. The score drops out of the last card and turns back into a red-tinted diamond asking whether the match weight is above the threshold. Above threshold runs down the left into a Link card; in the grey band runs down the right into a Human review card, from which an arrow labelled sent back to link rejoins the same Link step. Link then feeds the emphasised Golden record card at the far left. A closing red band reads the grey band is a design choice. One chain, one gate, and two routes out of it Source recordsone person, threesystems Standardisecase, spacing,addresses Blockcompare plausiblepairs only Comparefield by fieldagreement Scoreweights sum to onenumber records as captured one value per field candidate pairs agreement pattern Match weightabove threshold? Golden recordone identity, sources keptOutput Linkone id for the pairMatched Human reviewa person decidesGrey band above threshold in the grey band sent back to link The grey band is a design choiceSet the threshold too low and you merge two people. Set it too high and one person stays split in two.

Vectors, matrices, gradients, Bayes and entropy are the machinery under the tools

A vector is an ordered list of numbers standing for a thing, which is what an embedding is. A matrix is a table of them, which is what a dataset is, and multiplying a data matrix by a weight matrix is the core computation inside a regression, a neural network layer and a principal component analysis alike. The dot product multiplies the two vectors' lengths by the cosine of the angle between them, so it grows with length as well as with alignment; cosine similarity divides out the lengths and measures direction alone. That is why users with similar preference vectors get similar recommendations, and why a dot-product score can favour popular items, whose vectors tend to be longer. Training is then optimisation: a loss function scores how wrong the predictions are, and each step moves the parameters against the gradient by a distance set by the learning rate.

Two ideas do the reasoning work on top of that. Bayes' theorem updates a belief in light of evidence, which is why a test with a high detection rate still produces mostly false alarms when the condition is rare: the prior matters as much as the test. Entropy measures how much uncertainty a distribution holds, and mutual information, how far knowing a feature reduces uncertainty about the target, says how much the feature tells you, including dependence a correlation coefficient misses. Neither is needed to run a library, and that is the point: they are what let a practitioner see why an accuracy figure on a rare event is close to meaningless.

The shape of a distribution decides which summary is honest

A distribution describes how values spread, and the shape decides which statistics can be trusted. On an approximately normal distribution the mean, median and mode sit close together and the 68, 95 and 99.7 rule holds across one, two and three standard deviations. Income, house prices, insurance claims and outage durations are usually not normal, and the same rule applied to them understates the tail badly. When incident duration has a mean of 62 minutes and a median of 18, both numbers are true and answer different questions: the median describes a typical incident, the mean warns that rare severe events dominate total exposure.

Correlation is the half that gets misused. The Pearson coefficient runs from minus one through zero to plus one and measures the strength and direction of a linear relationship, nothing more. Ice cream sales and drowning rates rise together because temperature drives both, and a model treating one as the cause recommends the wrong intervention. The working test is not whether two variables move together but what else could make them: confounding, reverse causation, selection bias, seasonality or a change in measurement. Until those are ruled out a correlation is a reason to investigate rather than permission to act, and establishing cause needs a controlled experiment, a credible natural experiment, or an observational design whose assumptions are written down.

Distribution shape decides which summary statistic is honest

Symmetric data can be summarised by the mean, skewed data needs the median, heavy tails need percentiles as well, bimodal data needs splitting, and a mean quoted on skewed data sits above where half the cases actually are.

The honest summary statistic depends on the distribution shape. Symmetric: mean. Skewed: median. Heavy-tailed: median plus percentiles. Bimodal: split the report. Picking the wrong summary distorts the claim; the NIST Engineering Statistics Handbook §1.3.5 lays this out.

Distribution shape decides which summary is honest Four columns side by side, one per distribution shape, with no arrows between them because no order is claimed. Each column draws its shape as a filled curve standing on its own axis line, then a rule, then the summary that stays honest for it, with the source at the foot. Symmetric, one centred bell, mean is honest. Skewed, emphasised in red soft with a red border and a red curve, a peak to the left with a long right tail, median plus IQR. Heavy-tailed, a peak no wider than the bell but with tails still clear of the axis at both edges, median plus the 90th and 99th percentiles. Bimodal, two separate humps, split the report. A filled red band closes: mean on skew is the common defect. Four shapes, and the summary that stays honest in each SymmetricMean is honestNIST SkewedMedian + IQRNIST Heavy-tailedMedian + 90th + 99thpercentileNIST §1.3.5 BimodalSplit the reportONS Mean on skew is the common defectReporting average household income on a skewed distribution puts the headline number well above where half the householdsactually sit. Use median plus percentiles.

A p-value answers a narrow question, and the design has to be fixed before the data arrives

An A/B test is a randomised comparison, and randomisation is what makes the groups comparable before the change is applied. Five requirements make the result worth acting on: random assignment, a single changed variable, a sample size fixed by a power calculation against a stated minimum detectable effect, a hypothesis and success metric agreed in advance, and a duration covering weekday, weekend and payday variation. In the course's illustrative repeated-look model, inspecting cumulative data daily and stopping at the first p-value below 0.05 produces about an 11 per cent false positive rate after three looks and about 25 per cent after twenty; other designs produce different rates.

A p-value answers one narrow question: if there were no real difference, how often would a result at least as extreme as this one turn up under the model's assumptions. It is not the probability that the treatment works, and 0.049 is not meaningfully different from 0.051. The American Statistical Association's 2016 statement was written against that binary reading. Two p-hacking patterns are worth naming: testing many variants and reporting only the one that cleared the threshold, since five independent tests at five per cent give roughly a 23 per cent chance of at least one false positive, and changing the outcome measure after seeing the data. A confidence interval shows the range of effects the data is consistent with. The evidence chain that survives challenge runs from the population sampled, through the measure and the design, to the effect size and its uncertainty, and then to a claim stated no more strongly than that chain supports.

Inference scope bounded on population, time, treatment, outcome

A finding holds only inside the four bounds the study set, population, time, treatment and outcome, and a claim that leaves any one of them unstated has quietly been stretched past the study that produced it.

Every inference is bounded on four axes: population (who the sample represents), time (when the data was gathered), treatment (what was actually tested), outcome (what was measured). Stretching any axis beyond the study is extrapolation. The ASA 2016 statement makes this explicit; bounded claims survive replication, unbounded claims do not.

Inference scope bounded on population, time, treatment, outcome A fenced enclosure and the way out of it. A light grey container bordered in red and marked with a red left bar is labelled Inside the study. In a row inside it sit four white cards of equal size: Population, who the sample represents; Time, when data was gathered; Treatment, what was actually tested; Outcome, what was measured. Each carries a source tag, ASA 2016 on three and CS229 on Treatment. No arrow joins them, because none comes before another. Four red arrows of equal weight drop from the cards, cross the bottom wall and point into a filled red band naming extrapolation as the unmarked exit. A knockout label between the middle pair reads extrapolation. A finding is fenced by four bounds, and it holds only inside all four Inside the study 1PopulationWho the samplerepresentsASA 2016 2TimeWhen data wasgatheredASA 2016 3TreatmentWhat was actuallytestedCS229 4OutcomeWhat was measuredASA 2016 extrapolation Extrapolation is the unmarked exitA finding from 18-25 year olds in 2019 does not generalise to over-65s in 2025 under a different treatment dose. State all fourbounds in every claim.

Generalisation is the whole test, and shipping a model changes what can go wrong

Analytics forms a ladder of questions. Descriptive work says what happened, diagnostic work says why, predictive work estimates what is likely next, and prescriptive work recommends an action and so carries the consequence of being followed. Machine learning problems sort by the learning signal: supervised learning pairs inputs with correct outputs, covering classification and regression; unsupervised learning finds structure without labels, through clustering, dimensionality reduction and anomaly detection; reinforcement learning optimises actions against a reward; and self-supervised learning derives its labels from the data itself.

Evaluation is where projects are won or lost. A model that fits training data including its noise scores highly there and fails on anything new, which is overfitting; one too simple to capture the structure scores poorly on both, which is underfitting. The defence is a genuine separation of training, validation and test data, cross-validation when data is scarce, and vigilance about leakage, where information unavailable at prediction time reaches the model and produces a score that cannot be reproduced. A confusion matrix makes the choice of error explicit: precision matters when a false positive is costly, recall when a missed case is. Once a model ships, the data it sees can drift from the data it learned from, which is why monitoring, a rollback path and a named owner belong in the design. Stage 4 takes up the AI-specific risks, and EU AI Act Article 10 sets what high-risk systems must show about their data, applying from 2 December 2027 for Annex III systems and from 2 August 2028 for Annex I systems.

The traps this stage warns against

  • Building a fact table without writing down what one row represents, because the team all know what a sale is.

    Instead: Declare the grain on the face of the model before choosing a single column. It is what decides which measures may be summed and which dimensions can join, and an undeclared grain surfaces as an unexplained gap between two reports months later.

  • Keying a dimension on a natural business value such as an email address or a product code because it is already unique.

    Instead: Use a surrogate key that no business process can revise, and keep the natural value as an attribute. Real-world identifiers change, get reused, turn out not to be unique and sometimes have to be redacted.

  • Letting the team that built the linkage pipeline choose the match threshold.

    Instead: The threshold trades a false match against a missed match, and the costs are not symmetric. It belongs to the person who can describe what a wrong link does to a real person, and the setting and its reason should be recorded alongside the model version.

  • Tuning the matching model until the manual review queue disappears.

    Instead: Shrink it, but keep it. Twins at one address, a parent and child sharing a forename, or a new tenant at a former customer's flat are genuinely undecidable from the available fields, and removing the queue hides the uncertainty inside an automatic decision nobody can appeal.

  • Reporting a mean because it is the default summary in the tool.

    Instead: Look at the shape first. On a skewed distribution the median describes the typical case and the mean describes total exposure, so report both and say which question each answers.

  • Reading a p-value of 0.04 as a 96 per cent chance that the treatment works.

    Instead: It is the probability of data at least this extreme if there were no effect, under the model's assumptions. Report the effect size and its confidence interval, and decide on whether the effect is large enough and reliable enough to act on.

  • Trusting a validation score produced after cleaning, imputing or feature-engineering across the whole dataset.

    Instead: Split first, then fit every transformation on the training portion alone. Information that crosses the split, including anything unavailable at prediction time, produces a score that will not survive contact with real traffic.

Core distinctions

  • A conceptual model names the things, a logical model names attributes, keys and constraints, and a physical model names the implementation
  • A natural key carries business meaning and can change; a surrogate key carries none and therefore survives
  • Third normal form guards against update, insertion and deletion anomalies and costs joins; a star schema accepts duplication to cut the joins
  • The grain is a written statement of what one fact row represents, and it decides both which measures are additive and which dimensions can join
  • Deterministic matching says a field agrees or it does not; probabilistic linkage says how much that agreement should move your belief
  • The match score is a statistical output and the threshold is a business decision, so they belong to different people
  • Correlation measures how two variables move together; causation requires ruling out confounding, reverse causation, selection and measurement change
  • A p-value is the probability of data at least this extreme if there were no effect, not the probability that the effect is real
  • Overfitting is high training accuracy with poor validation accuracy; leakage is a validation score that was never earned because the answer was in the features

Stage 2 leaves you with two disciplines that reinforce each other: shaping data so a stored fact has one version and a query has one meaning, and treating a number as evidence only as far as its design and its uncertainty allow. The scenario practice now applies both to situations where a defensible answer and a comfortable one differ, which is where a declared grain, an owned threshold and an honest interval start doing visible work.

Sources and further reading