Definition
Independent and identically distributed (IID, also written i.i.d.) samples are observations that meet two conditions in the probability model used to analyze them. Independent: knowing the values of some observations does not change the probabilities for the others. Identically distributed: all observations follow one and the same probability distribution, the list of possible values with the probability of each. IID is an assumption about how the data were produced. Many standard formulas for the uncertainty of an average are derived from it and can be badly wrong when it fails.
The idea
Ten response times §9.32 are measured one after another on one device. A textbook formula for the uncertainty of their average silently assumes that the ten values are ten separate pieces of information about one unchanging behavior. Suppose a queue was congested during the whole test. Then all ten values are slow together: they are ten reports on one congestion episode. Or suppose the device warms up during the test and slows down steadily, a gradual change called drift. Then the tenth value comes from a different behavior than the first.
Picture drawing numbered balls from a bag. Put each ball back and shake the bag before the next draw. Then no draw influences another, which is independence, and every draw faces the same bag, which is identical distribution. Dependence is a draw that is steered by the previous one. A changing distribution is someone swapping balls between draws. The picture stops being accurate in one respect: a bag keeps no memory unless someone gives it one, whereas a device carries state from each trial, meaning each repetition of the measurement, into the next unless someone removes it.
How it works
Treat each observation as a random variable, a quantity whose value is decided by chance. The two conditions are separate, and each can hold without the other.
Independent. For every combination of outcomes, the probability that all observations take those outcomes equals the product of the separate probabilities. Learning some of the values then never changes the probabilities of the rest.
Identically distributed. Looked at alone, every observation has the same possible outcomes, each with the same probability, as every other observation.
Working with the assumption takes three steps.
Before measuring, remove what can be removed. Reset carried state between trials or let it settle. When several conditions are compared, put them in random order, which is called randomization §11.8, so that drift favors none of them on average over the possible orders. One particular order can still favor one condition by chance.
After measuring, look for violations. Plot the values in the order in which they were taken; a slope or a step shows that the distribution changed. Plot each value against the one before it; a visible pattern shows that neighboring values are related, through dependence or through drift.
If dependence remains, group the observations that share state and use an uncertainty method that treats each group as one unit, such as the cluster bootstrap §11.21, which builds new data sets by drawing whole groups at random from the recorded ones.
Worked example
Code a fair coin toss as 1 for heads and 0 for tails.
Identically distributed but dependent. Toss one coin and write the result down twice, as and . Each is 1 with probability , so the two have the same distribution. Independence would require the probability that both are 1 to be . The true probability is , because is 1 whenever is. The two records hold the information of one toss.
Independent but not identically distributed. Let be a fair coin toss and let always be 0. Knowing changes nothing about . The probability that and is , which equals the product , as independence requires. But is 1 with probability , and is 1 with probability 0.
Uncorrelated but dependent. Let be , 0 or 1, each with probability , and let . The mean of is . The mean of is . The product equals , and its mean is . The covariance §15.44, a measure of how two quantities vary together, is the mean of the product minus the product of the means: . Yet forces , so the two are dependent. Quantities with a covariance of zero are called uncorrelated. That rules out a straight-line relationship, not every relationship.
What dependence costs. The variance §11.14 of a quantity is its average squared distance from its mean. For one fair toss it is , because both outcomes lie from the mean and . Variances of independent quantities add, and halving a quantity divides its variance by , so the average of two independent tosses has variance . The average of the copied pair from the first case is the toss itself, with variance . A formula that assumes independence would claim for the copied pair and overstate the precision.
Stated precisely
Let be random variables, and write for probability. They are independent if, for every choice of sets of outcomes , Here means that the value of lies in the set . They are identically distributed if for every and every set . They are IID if both hold.
Independence of every pair is weaker than independence of all together. Let and be two separate fair coin tosses, and let be 1 if they differ and 0 if they agree. Any two of the three are independent. All three together are not, because forces : the probability that all three are 1 is 0, not .
The best-known consequence: if are IID with variance , their average has variance . The proof uses a common variance, which identical distribution supplies, and a covariance of zero for every pair, which independence supplies. When the pairs have positive covariance, the true variance of the average is larger than .
Limits and common mistakes
Repeating the same command does not make observations IID. The command is identical. The state of the device that runs it is not.
IID cannot be proved from the data. Plots and tests can reveal a violation, but a record that shows none has not shown that none exists.
A record that is not IID can still be described: its mean and its largest value are what they are. What fails is any step beyond the record that rests on IID, such as the formula for the variance of the average, or the prediction that future data will follow the distribution seen in the record. A method that allows for the dependence, such as the cluster bootstrap, or for the change in distribution can still support a conclusion beyond the record.
Independence depends on what the conclusion is about. Requests on one device can be independent as evidence about that device and still be dependent as evidence about devices in general, because they all share the peculiarities of that device. Counting them as separate evidence about devices is pseudoreplication §11.6.
Questions answered
What state carried from one trial could create dependence or drift?
Any state that one trial, meaning one repetition of the measurement, leaves behind and the next trial inherits. Typical examples in a computer system are:
caches, meaning stored copies of earlier results, which make a repeated operation faster than the first one;
queues and buffers that still hold work from the previous trial;
the bookkeeping of the memory allocator, the part of a system that hands out memory, because free memory can split into ever smaller pieces as a run goes on;
temperature and battery charge, which change during a run and can alter timing;
radio conditions, which can stay good or bad for longer than one trial;
stored protocol state such as counters, keys and open connections;
the fill level of permanent storage, which can trigger clean-up work at irregular moments.
State that neighboring trials share makes them resemble each other, which is dependence. State that accumulates makes later trials differ from earlier ones, which is drift and breaks identical distribution. For each such state there are three remedies: reset it between trials; randomize the order of the compared conditions, so that state which builds up in the same way under every condition favors none of them on average; or record it and group the trials that share it. Randomizing does not remove the bias from state that the compared conditions leave behind in different amounts, such as a cache that one condition fills and the other does not. That bias does not average out over the orders, so such state has to be reset, or allowed to fade completely, before the next trial. A fixed random seed, the starting value of a random number generator, repeats the generated inputs. It resets none of the states listed above.
Related entries: Variance and standard deviation (§11.14), Standard error (§11.15), Cluster bootstrap (§11.21), Pseudoreplication (§11.6), Randomization (§11.8), Warmup and steady state (§11.27).