Back to all posts
•
causal-inference, statistics, interactive, data-science, data-driven-decisions

The dangers of aggregated data: a visual example

Suppose we collect exercise and LDL cholesterol measurements from a group of people. Before fitting a model, look at the points. What relationship do you expect to see?

Exercise and LDL cholesterol: synthetic observations An interactive scatter plot. The pooled association is positive, but the association within each age group is negative.

These are synthetic observations: a toy example used for illustration, not clinical evidence. This example is inspired by the exercise–cholesterol example in Causal Inference in Statistics: A Primer, by Judea Pearl, Madelyn Glymour, and Nicholas P. Jewell. Exercise is measured in hours per week and LDL cholesterol in mg/dL. Here we mean LDL cholesterol, not HDL cholesterol.

Revealing the generating model

Let \(A\) be age, \(X\) exercise, and \(Y\) LDL cholesterol. The master equation is:

\[ Y = \alpha A + \beta X + \varepsilon, \qquad \alpha = 4.5,\quad \beta = -8,\quad \varepsilon \sim \mathcal{N}(0,12^2) \]

The exercise-generation equation:

\[ X^* = 0.5 + 0.09A + U, \qquad U \sim \mathcal{N}(0,1^2) \]

Exercise varies between patients, with older patients exercising more on average in this constructed sample.

There are 60 observations in each of 11 age groups: 20–25, 25–30, and so on through 65–70, then 70+. Ages are sampled uniformly within each band, including its lower boundary but excluding its upper boundary. For this simulation, the 70+ group samples ages from 70 to under 80. The independent outcome noise is \(\varepsilon \sim \mathcal{N}(0,12^2)\) in mg/dL. Older participants exercise more on average in this constructed example and have higher baseline LDL cholesterol.

That is what makes this a toy example: we wrote the master equation ourselves. Nature does not hand us its master equations! Our job as scientists is to learn as much as we can from limited observations and careful reasoning. We use induction to develop explanations from what we observe, then deduction to work out what those explanations predict and test those predictions against new observations.

Recovering the coefficients with multiple linear regression

Instead of dividing patients into age bands, we can include age and exercise together in one regression. Fitting ordinary least squares to all 660 observations gives:

\[ \widehat{Y} = -1.087 + 4.486A - 7.401X \]
Parameter Generating value Fitted value
Intercept 0 -1.087
Age 4.5 4.486
Exercise -8 -7.401

Holding age fixed, one additional hour of weekly exercise is associated with about 7.40 mg/dL lower predicted LDL. Holding exercise fixed, one additional year of age is associated with about 4.49 mg/dL higher predicted LDL. The coefficients are close to the values we used to generate the data, not exact, because this is a finite sample with random noise.

The same patients in three dimensions

Drag to rotate, or focus the chart and use the arrow keys. Points are colored by age, from blue for younger patients to red for older patients. The shaded surface is the fitted regression plane, restricted to the sample's exercise–age footprint. The orange line shows predictions at age 50.

Age, exercise, and LDL cholesterol with the fitted regression plane

The fitted model has an in-sample \(R^2\) of 0.963. This describes its fit to these observations, not its performance on new patients or proof of causality.

But this is a favorable test: we know the master equation, and we fitted the same linear form with the correct inputs. We should expect to recover coefficients close to the generating values, given enough observations. That is not evidence that a straight-line model will describe a real system equally well.

What if the relationship were nonlinear? Exercise might have diminishing returns, or its effect might depend on age. Including both variables would then not be enough: a model with one constant coefficient for each could miss curvature or interactions.

This is where more flexible machine-learning methods have a place. When we do not know the functional form, they can help us learn predictive relationships from the data without specifying an equation for every curve or interaction beforehand. They are not assumption-free, and they cannot recover information missing from the inputs. We still need to check their predictions on appropriate held-out data. Better prediction alone would not establish a causal effect.

Outside this toy example, we have to infer both the relevant inputs and the form of their relationships, without the master equation as an answer key.

What disappeared when we pooled the data?

Pooling mixed comparisons within an age group with comparisons between age groups. The people who exercise more also tend to be older in this sample. Age increases baseline LDL cholesterol strongly enough to reverse the pooled trend.

This is Simpson's paradox: an association can reverse when groups are combined. The pooled line answers a different question from the within-group lines, and we can clearly see that in this case it fails.

The real danger: Making decisions under this model

Have you ever heard that correlation does not mean causation? This is an example of it. The upward trend is there in the pooled data. We did not calculate it incorrectly. The mistake would be to conclude that exercise causes LDL cholesterol to rise.

Start with just the pooled regression, before separating patients by age. A careless reading of its upward slope might become advice to "Work out less!" Once we bring age into the picture, we might joke: "Or be younger!" Clearly, that is not something a patient can choose.

Not every relevant variable is something we can change, and some are not even measured. Here we know age matters because we have access to the master equation that generated the data. In real applications, we do not have that equation. We have to infer which variables and mechanisms produced the outcomes, and we may not even know what we are missing. That is the key difficulty. The problem starts when we turn an incomplete comparison into advice.

In our toy model, that advice would do the opposite of what the doctor intended. For a patient of a given age, less exercise means higher expected LDL cholesterol. The pooled line does not tell us what happens when that patient changes their exercise habits.

Of course, this toy example is not a basis for medical advice. The point is that the danger becomes real when we start making decisions under this model. A small p-value does not make the recommendation sound. We can be very confident about the association and still be wrong about what to do.

What this means for pipeline integrity

Why does this matter for pipeline integrity? Because we use data to buy things and decide where to intervene. Two pipelines can differ in age, material, manufacturing process, operating conditions, environment, and inspection history. If we pool their records, which of those differences are we actually measuring?

Procurement: comparing performance under different conditions

Every pipe is different. Before using data to make a procurement decision, we need to account for the specifics of the pipeline where the product will be used. Material properties, dimensions, manufacturing history, loading, operating environment, and relevant failure mechanisms determine whether experience from another pipeline is informative for this one. An aggregate ranking cannot establish that a product is suitable for a particular application.

Imagine one provider's inspection results come mostly from pipelines with more challenging operating conditions and feature geometries, while another's come from easier applications. The first provider could have larger sizing errors overall even if it performs better when compared under similar conditions.

Choosing the second provider from that aggregate ranking could mistake differences in the inspection population for differences in capability. Before making a procurement decision, we need to compare performance for the pipeline and features that matter to us, accounting for operating conditions and how the measurements were verified.

Integrity decisions: acting on an incomplete picture

The danger is making "data-driven" integrity decisions with incomplete data or an analysis that leaves out important information. In the worst case, the action can have the opposite effect from the one intended, increasing risk rather than reducing it. Incomplete does not necessarily mean too few records. A large dataset can still omit the conditions that explain why outcomes differ.

Suppose a model estimates corrosion growth from historical inspection data collected under relatively stable operating temperatures. The operating temperature then changes, but the model does not include temperature or account for that change. For a corrosion mechanism whose growth accelerates under the new conditions, the historical rates may no longer be representative.

The model could still predict slow growth and support extending an inspection interval, even while deterioration is accelerating. Its historical validation might look good, but that does not establish reliability under the new conditions. A decision intended to support safe operation could instead leave a deteriorating segment unexamined for longer.

This need not involve a reversal as dramatic as the exercise example. The shared problem is treating an incomplete relationship as a sufficient basis for action, without checking whether the conditions behind the data still apply.

Does separating the groups always solve it?

No. The graph alone does not tell us which variables to adjust for. Here we know the generating model: age precedes both exercise and LDL cholesterol, so it acts as a common cause. In real observational data, that causal assumption needs justification. Conditioning on a mediator or a collider can answer a different question or introduce bias.

Even an age-adjusted association would not, by itself, establish a medical effect. Unmeasured common causes, selection, and measurement error could remain. We can interpret the coefficient causally in this toy model because we specified how the data was generated, not because the fitted lines look persuasive.

The lesson is to be very careful with aggregated data, especially large datasets used to support life-and-death decisions.

"Data-driven" does not necessarily mean information-driven or informed by causation. Having observations is not the same as having the information needed for a decision, or understanding what will happen when we act.

Reference

Causal Inference in Statistics: A Primer, by Judea Pearl, Madelyn Glymour, and Nicholas P. Jewell