Trying again with independence/sufficiency visualization and
checks
What does independence look like for two categorical variables?
(mosaic plots)
What does independence look like for two continuous variables?
Same questions for conditional independence
What if we have more than two variables? (high-dimensional
visualization + random projections)
Independent random variables
Recall from Lecture 2: random variables are
independent if probabilities of simultaneous events can
be obtained by multiplying their separate probabilities.
For two random variables, this means
\[
P(X\in A,\ Y\in B)=P(X\in A)P(Y\in B)
\]
for every pair of appropriate sets \(A\) and \(B\).
It is not a bad approximation to think of \(A\) and \(B\) as being intervals for continuous
random variables and individual outcomes for categorical random
variables.
Independence/dependence for categorical variables
If \(X\) and \(Y\) take values in finite/countable sets,
we can choose \(A=\{x\}\) and \(B=\{y\}\).
Independence means
\[
P(X=x,Y=y)=P(X=x)P(Y=y)
\]
for every pair of categories.
For example, if \(P(X=1)=P(Y=1)=1/2\), independence requires
\(P(X=1,Y=1)=1/4\).
Visualizing categorical random variables: Mosaic plot
Each column represents a category of \(X\).
Within each column, the boxes represent categories of \(Y\).
The area of the \((x,y)\) box is the fraction of observations
with \(X=x\) and \(Y=y\).
Width, height, and area
For the box corresponding to \(X=x\)
and \(Y=y\):
Part of the box
Probability represented
Column width
\(P(X=x)\)
Height within the column
\(P(Y=y\mid
X=x)\)
Area
\(P(X=x,Y=y)\)
The geometry follows the probability identity
\[
P(X=x,Y=y)=P(X=x)P(Y=y\mid X=x).
\]
A mosaic under independence
Independence implies
\[
P(Y=y\mid X=x)=P(Y=y)
\]
whenever \(P(X=x)>0\).
The proportions of the \(Y\)-categories are the same in every
column, so the horizontal boundaries line up.
The boxes can still have different areas.
A mosaic showing dependence
Everyone aboard the Titanic, by sex (\(X\)) and survival (\(Y\)).
The distribution of \(Y\) changes
between the \(X\)-categories.
Knowing \(X\) tells us something
about \(Y\).
A mosaic plot of simulated independent data
In a finite sample, the observed proportions will differ a little
from one column to another.
We can simulate independent samples to see how much variation to
expect.
Independence/dependence for continuous variables
Flipper length (\(X\)) and body mass
(\(Y\)) for 342 penguins near Palmer
Station, Antarctica.
Pair
How it is made
As measured
Each penguinโs own flipper length and body
mass
Shuffled
Body masses randomly reassigned among the
penguins
Shuffling keeps both lists of values exactly, so \(X\) and \(Y\) have the same distributions in both
pairs.
Shuffling makes the pair independent. Their joint distributions
differ.
Scatterplots of the two pairs
For the independent pair, knowing approximately where \(X\) lies does not change the distribution
we expect for \(Y\).
For the dependent pair, the distribution of \(Y\) moves upward as \(X\) increases.
How can we connect these pictures to the definition of
independence?
Option 1: Discretize both variables and make a mosaic plot
Divide each axis into intervals \(A_1,\ldots,A_4\) and \(B_1,\ldots,B_4\).
for every pair of sets \(A,B\) and
almost every conditioning value \(z\).
We write \(X\perp Y\mid Z\).
After fixing \(Z\), knowing \(X\) does not change the distribution of
\(Y\).
Visualizing conditional distributions
Recall how we simulated conditional distributions:
Generate joint outcomes \((X,Y,Z)\).
Keep only those satisfying the condition.
Study distributions within that collection.
Therefore:
To inspect \((X,Y)\mid Z=z\),
subset to observations with \(Z=z\) and
visualize \(X\) and \(Y\) on that subset.
For continuous variables, we usually subset to observations with
\(Z \approx z\).
We can use the plots from before on the subset.
Conditioning on a categorical variable, penguin example
Return to the discretized penguin measurements:
\(X\): flipper length, cut into
thirds within the species.
\(Y\): body mass, cut into thirds
within the species.
\(Z\): species.
Suppose we want to know about the distribution \((X, Y) \mid Z = \text{Gentoo}\)
Conditional independence predicts aligned horizontal boundaries
within that species.
Conditioning: keep the Gentoo rows
Conditioning on \(Z =
\text{Gentoo}\) means throwing away every other row.
The Gentoo rows, discretized
Does the distribution of body-mass categories change across
flipper-length categories?
If it does, fixing species has not removed the relationship.
Comparing conditional distributions
Each histogram represents
\[
Y\mid X\in A_i,\ Z=\text{Gentoo}.
\]
Under conditional independence, these distributions should agree
across the \(X\)-intervals.
The common distribution may be different for a different species.
How do we condition on a continuous variable?
When the conditioning variable was categorical (species), we can
select rows with exactly \(Z=z\).
With a continuously distributed conditioning variable \(Z\), a finite simulation bank will not
contain rows with exactly a chosen value.
Instead, we might keep a range:
\[
z_0-h<Z<z_0+h.
\]
That range combines different values of \(Z\).
Example: Packing and posting a parcel
Consider a simplified warehouse simulator:
\(Z\): the parcelโs weight.
\(X\): the time needed to pack
it.
\(Y\): the postage charge.
Heavier parcels tend to take longer to pack and cost more to
post.
At a fixed weight, the simulator generates the extra packing time and
extra postage charges independently.
Thus, in this model, \(X\perp Y\mid
Z\).
Parcels in a weight range
Suppose we just have data from this model and donโt know how it was
generated.
Suppose further that we want to know whether \(X\) and \(Y\) are conditionally independent given
\(Z\).
To do so, we investigate the distribution of \((X, Y) \mid Z\).
We do so by plotting observations from the simulation bank that
satisfy \(Z \in (z_0 - h, z_0 +
h)\).
Weโll start with \(z_0 = 2\) and
\(h = 1, .3, .05\).
Postage within packing-time strips, \(h =
1\)
Postage shifts upward from strip to strip.
Postage within packing-time strips, \(h =
1\)
Color by weight: the strips differ because they hold parcels of
different weights.
Postage within packing-time strips, \(h =
0.3\)
A smaller shift remains, mostly between the first strip and the
rest.
Postage within packing-time strips, \(h =
0.3\)
The first strip holds mostly the lighter parcels in the range, which
is where the remaining shift comes from.
Postage within packing-time strips, \(h =
0.05\)
The distributions agree, up to noise in the sparse right-hand
strips.
Postage within packing-time strips, \(h =
0.05\)
Light and heavy parcels within the range are mixed across all the
strips.
Interpreting a conditional-independence plot
When we filter to a range, a visible relationship can come from
dependence remaining at a fixed conditioning value, or from mixing
conditioning values.
Before interpreting the plot, ask:
What exactly did we condition on?
How much does the conditioning variable still vary within the
retained collection?
What happens when we narrow the range, and how many observations
remain?
Next big problem
We have seen how to check for independence between two random
variables and how to check for conditional independence between two
random variables given a third.
What if we want to check for independence/conditional independence
between a random vector (e.g.ย a whole dataset) and a random
variable?
Motivation: For ABC, wanted to know whether \(S(X)\) is a sufficient statistic, (that is,
whether \(X\) and \(\theta\) were conditionally independent
given a statistic \(S(X)\)).
Independence with a vector
Suppose we want to know whether \(\theta\) is independent of a vector
\[
\mathbf X=(X_1,\ldots,X_p).
\]
We could plot \(\theta\) against
each coordinate.
But \(\theta\) can be independent of
every individual coordinate and still depend on the combination.
\[
\theta\perp X_j\text{ for every }j
\quad\text{does not imply}\quad
\theta\perp\mathbf X.
\]
Example: Ten days of rain
Recall our weather model from before.
Let \(X_t=1\) if day \(t\) is rainy and \(X_t=0\) if it is dry.
Day 1 is equally likely to be rainy or dry.
Each subsequent day repeats the previous dayโs weather with
probability \(\theta\).
Otherwise, the weather switches.
Each simulation produces a vector
\[
\mathbf X=(X_1,\ldots,X_{10}).
\]
Large \(\theta\) gives long wet and
dry spells. Small \(\theta\) gives
frequent switches.
Simulated weather sequences
Each row is one simulation. Each column is one day.
\(X_i\) and \(\theta\) are independent
Suppose we plot \(\theta\) against
\(X_1\), then \(X_2\), and so on.
On every day, \(\theta\) has the
same distribution among the dry and the rainy simulations.
But the entire vector \(\mathbf X\)
is not independent of \(\theta\)
Create a โtotal rainy daysโ statistic: \(R(\mathbf X)=X_1+\cdots+X_{10}.\)
But the entire vector \(\mathbf X\)
is not independent of \(\theta\)
The distribution of the total changes with \(\theta\).
What the combination tells us
If \(\theta\) were independent of
\(\mathbf X\), it would also be
independent of every function of \(\mathbf
X\).
But \(R(\mathbf X)\) has a
distribution that changes with \(\theta\).
Therefore,
\[
\theta\not\perp\mathbf X,
\qquad\text{even though}\qquad
\theta\perp X_t\text{ for every }t.
\]
Checking individual coordinates can miss information in how they vary
together.
The two clusters are clear in some projections and overlap in
others.
A tour for an independence question
To examine whether \(Y\perp\mathbf
X\), keep \(Y\) on one axis and
change the projection on the other:
\[
\text{plot }Y\text{ against }T_a=a^\top\mathbf X.
\]
Under independence, the distribution of \(T_a\) should stay the same across values of
\(Y\), for every direction \(a\).
We look for changes in location, spread, or shape.
Random projections and numerical checks
We can inspect these views visually, or measure dependence
numerically.
Draw a direction \(a\) and compute
\(T_a=a^\top\mathbf X\).
Compare the distributions of \(T_a\) across values of \(Y\).
Repeat for other directions.
For example, discretize \(T_a\) and
\(Y\), then compare joint cell
proportions with products of marginal proportions.
Why inspect projections?
For numeric vectors,
\[
Y\perp\mathbf X
\quad\Longleftrightarrow\quad
Y\perp a^\top\mathbf X\text{ for every direction }a.
\]
All one-dimensional projections determine a multivariate
distribution.
A finite collection of plots or numerical checks can still miss
dependence, especially with limited data.
Returning to sufficiency
For a sufficiency check, first restrict simulations to the observed
summary, or a neighborhood of it.
Then inspect whether any projection of the remaining data is related
to the parameter, either graphically using a tour or numerically using
random projections:
Both inherit the earlier limitations of approximate conditioning and
finite samples.
What we saw
How to visualize independence/dependence of random variables
using mosaic plots or scatter plots.
How to visualize conditional independence/dependence of random
variables.
Dependence of a random vector \(\mathbf
X = (X_1,\ldots, X_p)\) and another random quantity cannot be
checked using only the individual coordinates \(X_i\).
We can use can use random projections or tours for independence
of random vectors, but itโs always possible to miss something.