IID (Independent and Identically Distributed)
Independent and identically distributed, abbreviated IID or i.i.d., describes a set of observations that satisfy two conditions at once. Google’s machine learning glossary defines the term as “Data drawn from a distribution that doesn’t change, and where each value drawn doesn’t depend on values that have been drawn previously.” The first clause is identical distribution: every observation comes from the same process. The second is independence: knowing one observation tells you nothing about another. The scikit-learn documentation phrases the same idea from the generating side: all samples come from one generative process, and that process has no memory of what it produced before.
Ten flips of a fair coin are the textbook case: each flip has the same probability of heads and no flip influences the next. Most real data is not like that, and both sources say so. Google calls IID “a useful mathematical construct but almost never exactly found in the real world”, and scikit-learn says the same of machine learning practice, that the assumption rarely holds. The point of knowing the term is not to find data that satisfies it but to know what breaks when data does not.
Why the assumption is there
The standard formulas that turn a sample into a statement about a population lean on IID. The law of large numbers, which says a sample mean converges on the population mean, and the central limit theorem, which gives that mean an approximately normal distribution, are both stated for IID draws. The standard error of a mean, \(s/\sqrt{n}\), the confidence interval built on it, the p-value from a hypothesis test, and the sample size a power calculation demands all use \(n\) as if each of the \(n\) observations carried a full unit of new information. Independence is what makes that true. When observations are positively correlated, as they are when several come from the same user or from neighboring days, each carries less than a unit of new information, the effective sample size is smaller than \(n\), and every one of those formulas is too confident. Dependence does not always cut that way: negatively correlated draws can make a mean more precise than independent draws would, and the Stan reference manual notes that for anticorrelated draws the effective sample size “can be larger than the number of iterations”. The positively correlated case is the one that arises in product and observational data, and it is the one the rest of this entry is about.
Note what dependence does and does not do to a mean. If every observation has the right expected value, so does their average, dependent or not; that follows from the linearity of expectation, and it is why dependence by itself does not bias a mean. What it corrupts is the variance, and with it every interval and test that claims a precision the data does not have. Bias in a mean comes from a different failure: observations whose expected value is not the target, most often because the sample was drawn from a population other than the one the claim is about. That is a question about the sample’s representativeness, which IID within the sample does not settle, and estimators that are not linear in the data can be biased by dependence in ways a mean is not.
The unit of sampling, and how the assumption usually fails
A frequent failure in analytics is a mismatch between the row and the unit. Ten thousand page views from two thousand users are not ten thousand independent observations for a question about users; views by the same user share that user’s habits, device, and intent, so ten thousand rows need not carry ten thousand independent observationsโ worth of information. For an equally weighted mean with five observations per independent user and common nonnegative within-user correlation ฯ, the variance-based effective size is 10,000/(1+4ฯ), between 2,000 and 10,000. Unequal cluster sizes, different weights or estimands, and other dependence can change that range; the two counts alone do not determine it. A confidence interval or a test computed with \(n = 10{,}000\) is then narrower than the evidence supports. The remedy is to decide what the unit of the question is, and either aggregate to that unit, one row per user, or keep the rows and use an estimator that accounts for the clustering, such as a cluster-robust standard error or a bootstrap that resamples users rather than views.
| Structure | Which half fails | Example | What to do |
|---|---|---|---|
| Repeated measures on the same unit | Independence | Several sessions per user; several samples per patient | Analyze at the unit level, or use cluster-aware standard errors |
| Time order | Independence | Daily sales; sensor readings; today’s price depends on yesterday’s | Time-aware validation and inference; block or moving-block resampling |
| Population changes over the sample | Identical distribution | Early adopters differ from later customers; a new market opens mid-year | Model the change, stratify, or restrict the claim to the period it holds for |
| Training and production differ | Identical distribution | A model fitted on last year’s applicants scores this year’s | Monitor for data drift; treat the production population as a different one until shown otherwise |
The same two failures govern how a model should be validated. scikit-learn’s guidance is direct: if the samples were generated by a time-dependent process, use a time-series-aware cross-validation scheme, and if the generating process has a group structure, such as different subjects, experiments, or measurement devices, use group-wise cross-validation. Random shuffling across time or across a user’s rows lets the model see the future or the same person on both sides of the split, and the resulting accuracy is not the accuracy it will have in use. Google’s web-traffic example shows how the assumption can hold at one scale and fail at another: visitors “may be i.i.d. over a brief window of time”, but “if you expand that window of time, seasonal differences in the web page’s visitors may appear”.
A short check before quoting any number
- What is the unit the claim is about, and does each row correspond to one of them? If not, the row count overstates the sample.
- Do rows share a source that makes them alike: a user, a device, a day, a store? If so, the standard error has to account for it.
- Was the process the same across the whole sample, or did something change partway? A change means the sample describes more than one population.
- If any of these flags a problem, check that the standard error, the interval, or the validation split was computed in a way that accounts for it.
Independence is a stronger condition than the absence of correlation: two variables can be uncorrelated and still dependent, so a correlation of zero between rows is not evidence that the assumption holds. The question is whether the way the data was produced makes the rows informative about one another, and that is answered mainly by looking at how the data were produced, not only at the numbers.
References
- Google, Machine Learning Glossary: independently and identically distributed (CC BY 4.0)
- scikit-learn, Cross-validation: evaluating estimator performance
- Stan Development Team, Stan Reference Manual: Posterior Analysis (effective sample size)
Discover more from Insightful Data Lab
Subscribe to get the latest posts sent to your email.
