Why Test Independence Cell by Cell?
Knowing the separate distributions of two discrete random variables does not, by itself, determine how they behave together. A joint probability model records both the marginal behavior and the association between the variables. Testing independence asks whether the joint probabilities are exactly those implied by combining the two marginal distributions.
For a discrete model, this is a direct calculation: find the marginal mass of each variable, then compare each relevant joint mass with the product of the corresponding marginal masses. One unequal pair is enough to establish dependence. To establish independence, however, the equality must hold throughout the joint support.
\(p_{X,Y}(x,y)=p_X(x)p_Y(y)\).
The joint model must be valid: its masses are nonnegative and sum to 1. Marginal masses are obtained by summing the joint masses over the other variable.
A Reliable Testing Procedure
For a finite table, use every cell in the table, including cells with joint mass zero. For a countable model, the same criterion applies to every pair of values. In practice, a zero marginal also immediately implies that every joint mass involving that value is zero. The key distinction is that the joint support—the pairs assigned positive joint mass—may be smaller than the Cartesian product of the two marginal supports. If a pair of values each has positive marginal mass but their joint mass is zero, the product of the marginals is positive, so independence fails.
Confirm that the listed masses are nonnegative and sum to 1. If the model is not valid, it cannot be used as a probability distribution.
For each \(x\), add the joint masses across all possible \(y\). For each \(y\), add across all possible \(x\).
For each relevant pair \((x,y)\), calculate \(p_X(x)p_Y(y)\) and compare it with \(p_{X,Y}(x,y)\), preferably using exact fractions.
One mismatch proves dependence. If every pair matches, the variables are independent.
The test is about the probability model, not about a sample of observed data. It is not a statistical test with a significance level or a p-value. The exact joint probabilities either satisfy the independence criterion or they do not.
Worked Example: Testing a Joint Probability Table
A hypothetical monitoring system records \(X\), an indicator that a sensor alarm occurred (0 = no, 1 = yes), and \(Y\), the number of calibration flags recorded (0, 1, or 2). Its joint probability table is:
| \(X\) | \(Y=0\) | \(Y=1\) | \(Y=2\) |
|---|---|---|---|
| 0 | \(1/10\) | \(2/10\) | \(1/10\) |
| 1 | \(2/10\) | \(1/10\) | \(3/10\) |
Determine whether \(X\) and \(Y\) are independent. Also find \(P(X=1,Y=2)\).
Method. First check the model and obtain the marginals, then compare all six joint masses with their marginal products.
Validity check. The six masses sum to \((1+2+1+2+1+3)/10=10/10=1\), and each is nonnegative. Thus the table defines a valid joint probability model.
Marginals. Summing across rows gives \(p_X(0)=(1+2+1)/10=4/10\) and \(p_X(1)=(2+1+3)/10=6/10\). Summing down columns gives \(p_Y(0)=(1+2)/10=3/10\), \(p_Y(1)=(2+1)/10=3/10\), and \(p_Y(2)=(1+3)/10=4/10\).
All cell comparisons. In the \(X=0\) row, the products are \((4/10)(3/10)=12/100\), \((4/10)(3/10)=12/100\), and \((4/10)(4/10)=16/100\). The joint masses are \(10/100\), \(20/100\), and \(10/100\), respectively. In the \(X=1\) row, the products are \((6/10)(3/10)=18/100\), \((6/10)(3/10)=18/100\), and \((6/10)(4/10)=24/100\). The joint masses are \(20/100\), \(10/100\), and \(30/100\), respectively. None of the six comparisons matches, so \(X\) and \(Y\) are dependent.
Requested probability. Reading the cell at \(X=1,Y=2\) gives \(P(X=1,Y=2)=3/10=0.3000\). This is the joint probability, not the product of the marginals; that product is \(24/100=0.2400\). The mismatch is one direct demonstration of dependence.
Check and trap avoided. The row and column totals each sum to 1, as required for marginal distributions. A common mistake is to inspect one cell and then claim independence because it happens to match, or to compare the cell with only one marginal. Neither is the criterion: compare against the product of both marginals, and verify every cell to claim independence.
Why the Product-of-Marginals Criterion Works
The cell-by-cell criterion follows directly from the definition of independence. The events \(\{X=x\}\) and \(\{Y=y\}\) have probabilities \(p_X(x)\) and \(p_Y(y)\), and their intersection is the event \(\{X=x,Y=y\}\). If these events are independent, their intersection probability must be the product of their probabilities.
The reverse implication also holds for discrete variables. If the equality holds for every pair of values, then probabilities of any sets of values \(A\) and \(B\) can be summed over their pairs. The finite-sum argument below also applies to countable supports, with sums over the relevant values.
Thus the pairwise mass equalities imply independence for events formed from sets of values, not just for single values. This argument depends on the variables being discrete so that their event probabilities can be obtained by summing their probability masses.
Testing a Formula-Based Model
When a joint mass function is given by a formula rather than a table, begin by identifying its support: the pairs \((x,y)\) where the formula applies. Verify that the masses normalize to 1, derive both marginals by summation, and only then test the product criterion. A formula that appears to separate into an \(x\)-part and a \(y\)-part is suggestive, but the normalization and marginal calculations still need to be checked.
Worked Example: A Separable Joint Mass Function
In a hypothetical classification model, \(X\) takes values \(0,1,2\), and \(Y\) takes values \(0,1\). On this support, suppose
Determine whether \(X\) and \(Y\) are independent, and calculate \(P(X\geq 1,Y=1)\).
Validity and masses. The sum of the numerators over the support is \((1+2+3)(2+3)=6\cdot5=30\), so the joint masses sum to \(30/30=1\). The six masses, listed by row, are \(2/30,3/30\) for \(x=0\); \(4/30,6/30\) for \(x=1\); and \(6/30,9/30\) for \(x=2\). They are all nonnegative.
Marginal of \(X\). Summing over \(y\), the row totals are \(5/30=1/6\), \(10/30=1/3\), and \(15/30=1/2\). Equivalently, \(p_X(x)=(x+1)/6\) for \(x=0,1,2\).
Marginal of \(Y\). Summing over \(x\), the column totals are \(12/30=2/5\) for \(y=0\) and \(18/30=3/5\) for \(y=1\). Equivalently, \(p_Y(y)=(y+2)/5\) for \(y=0,1\).
Independence check. For every allowed pair, \(p_X(x)p_Y(y)=((x+1)/6)((y+2)/5)=(x+1)(y+2)/30=p_{X,Y}(x,y)\). For example, at \((x,y)=(2,1)\), the joint mass is \(9/30=3/10\), while the marginal product is \((1/2)(3/5)=3/10\). The formula proves the equality for all six pairs, so \(X\) and \(Y\) are independent.
Requested event probability. Add the two joint masses for \(x=1,2\) and \(y=1\): \(P(X\geq1,Y=1)=6/30+9/30=15/30=1/2\). As a check using the established independence, \(P(X\geq1)P(Y=1)=(1/3+1/2)(3/5)=(5/6)(3/5)=1/2\).
Check and trap avoided. The row marginals sum to \(1/6+1/3+1/2=1\), and the column marginals sum to \(2/5+3/5=1\). A common error is to decide that the model is independent just because the formula has factors involving \(x\) and \(y\). The calculation above confirms normalization, derives the actual marginals, and verifies that their product equals the joint mass.
A Dependence Example and a Calculation Trap
In formula-based models, careful bookkeeping matters. In particular, a joint mass is not itself a marginal mass. The product criterion uses marginal masses, each obtained by summing joint masses. The following example makes this distinction explicit.
Worked Example: Distinguishing Joint and Marginal Masses
Let \(X,Y\in\{0,1\}\) have joint mass function \(p_{X,Y}(x,y)=(1+x+y)/8\). Verify the model, determine whether the variables are independent, and calculate \(P(X=Y)\).
Validity. The masses at \((0,0),(0,1),(1,0),(1,1)\) are \(1/8,2/8,2/8,3/8\). Their sum is \((1+2+2+3)/8=8/8=1\), and all are nonnegative.
Marginals. For \(X=0\), sum \(1/8+2/8=3/8\); for \(X=1\), sum \(2/8+3/8=5/8\). By symmetry, \(p_Y(0)=3/8\) and \(p_Y(1)=5/8\).
Independence check. At \((0,0)\), the joint mass is \(1/8=8/64\). The product of the marginal masses is \((3/8)(3/8)=9/64=0.140625\). Since \(8/64\ne9/64\), the variables are dependent; this one mismatch is sufficient. For completeness, the other cells also fail: at \((0,1)\) and \((1,0)\), the joint mass is \(2/8=16/64\), while the marginal product is \((3/8)(5/8)=15/64\); at \((1,1)\), the joint mass is \(3/8=24/64\), while the product is \((5/8)(5/8)=25/64\).
Equality event. The event \(X=Y\) consists of \((0,0)\) and \((1,1)\), so \(P(X=Y)=1/8+3/8=4/8=1/2=0.5000\).
Check and trap avoided. The marginal probabilities each sum to \(3/8+5/8=1\). The product required at \((0,0)\) is \((3/8)(3/8)\), not \((1/8)(1/8)\): \(1/8\) is the joint mass at that cell, not either marginal. In fact, \((1/8)(1/8)=1/64=0.015625\), but it is not the independence comparison for this cell. Using the correct marginal product, \(9/64=0.140625\), gives the correct mismatch with \(1/8\).
Common Errors to Avoid
- Using the joint mass in place of a marginal. A marginal is a sum over the other variable. Do not multiply two cell masses when the criterion calls for \(p_X(x)p_Y(y)\).
- Checking too few cells. One failure proves dependence, but one match does not prove independence. To establish independence, verify every relevant pair.
- Ignoring a zero joint mass. If both marginal masses at a pair are positive, independence requires a positive joint mass equal to their product. A zero joint mass at that pair is evidence of dependence.
- Rounding too early. Use exact fractions where possible. Close decimal values can appear equal after rounding even when the exact probabilities differ.
- Skipping normalization. Marginals and independence comparisons are meaningful only when the proposed joint masses form a valid probability model.
Check Your Understanding
For each model, verify any needed marginal masses and state the requested conclusion. Use exact fractions where possible.
- A joint table has \(p(0,0)=3/20\), \(p(0,1)=3/20\), \(p(1,0)=7/20\), and \(p(1,1)=7/20\). Are \(X\) and \(Y\) independent? (Answer: Yes; the marginals are \(p_X=(3/10,7/10)\) and \(p_Y=(1/2,1/2)\), and all four products match.)
- For \(x,y\in\{0,1\}\), let \(p_{X,Y}(x,y)=(1+x+y)/8\). Are the variables independent, and what is \(P(X=Y)\)? (Answer: Dependent, since \(p(0,0)=1/8\ne(3/8)(3/8)=9/64\); \(P(X=Y)=1/2\).)
- For \(x\in\{1,2\}\) and \(y\in\{0,1,2\}\), suppose \(p_{X,Y}(x,y)=c\,x(1+y)\). Find \(c\) and determine whether the variables are independent. (Answer: \(c=1/18\); independent, with \(p_X(x)=x/3\) and \(p_Y(y)=(1+y)/6\).)
- A table has masses \(p(0,0)=1/6\), \(p(0,1)=1/3\), \(p(1,0)=1/3\), and \(p(1,1)=1/6\). Determine independence and calculate \(P(X=Y)\). (Answer: Dependent, since \(p_X(0)p_Y(0)=(1/2)(1/2)=1/4\ne1/6\); \(P(X=Y)=1/3\).)
- For \(x\in\{0,1,2\}\) and \(y\in\{0,1\}\), let \(p_{X,Y}(x,y)=(1+x+y)/15\). Verify normalization, test independence, and find \(P(X=Y)\). (Answer: The masses sum to \((1+2+2+3+3+4)/15=1\); dependent because \(p(0,0)=1/15\ne p_X(0)p_Y(0)=(1/5)(2/5)=2/25\); \(P(X=Y)=1/15+3/15=4/15\).)