Datasets with overlapping variables#

TL;DR#
When studies, cohorts, or sites measure overlapping variable sets, their stacked table has block-wise missingness, and some pairs of variables are never jointly measured. A conditional independence test of such a pair, or a test that conditions on a variable measured only in another dataset, has no rows to use.
The common answers each claim something the data did not show. Answering such a test with p = 1 deletes true edges and creates false colliders; answering p = 0 draws an edge between every pair never jointly measured; imputation takes their covariance from a model, not from any row.
Andrey 0.19.0 skips such a test: it neither removes an edge nor keeps one. A pair that no test can decide is left out of the graph and listed, an edge that a skipped test might have removed is listed too, and one log message reports both. With
possibly_separable="ambiguous", such an edge never creates a collider.On simulated cohorts with overlapping variable sets and no complete rows, PC’s graph made fewer errors than the empty graph in every setting and kept about as many true edges between jointly measured variables as on the complete data, while answering p = 1 removed most of them. Pairs that no test can decide were never drawn (release card).
Data often come from several datasets rather than one. A consortium pools cohorts from several hospitals, a registry links tables collected by different agencies, and a lab combines panels run years apart. Each dataset measures some variables that the others also measure, and some of its own. The causal discovery literature calls this setting multiple datasets with overlapping variables (Tillman et al., 2008; Tillman and Spirtes, 2011) or overlapping variable sets (Triantafillou and Tsamardinos, 2015).
Take two studies of four variables. Both measure W and Z; the first also measures X, and the
second Y. Here are the first rows of each:
X |
W |
Z |
|---|---|---|
0.13 |
0.42 |
0.95 |
-0.13 |
-0.50 |
-0.31 |
0.64 |
-0.86 |
-0.24 |
W |
Z |
Y |
|---|---|---|
-0.39 |
0.53 |
1.65 |
-0.28 |
1.11 |
1.49 |
-1.24 |
-0.63 |
-0.33 |
When the studies are stacked into one table, each leaves a block of missing values (NaN) in the
column it did not measure:
Study |
X |
W |
Z |
Y |
|---|---|---|---|---|
1 |
0.13 |
0.42 |
0.95 |
NaN |
1 |
-0.13 |
-0.50 |
-0.31 |
NaN |
1 |
0.64 |
-0.86 |
-0.24 |
NaN |
2 |
NaN |
-0.39 |
0.53 |
1.65 |
2 |
NaN |
-0.28 |
1.11 |
1.49 |
2 |
NaN |
-1.24 |
-0.63 |
-0.33 |
This is block-wise missingness, not values missing at random across cells. Stacking datasets yields
a structured missingness pattern in which some variables are never jointly measured (Tillman and
Spirtes, 2011). Here, no row observes X and Y, so no test can check whether they are dependent.
For each test, PC and FCI use the rows where all its variables are observed, a procedure called
test-wise deletion. In this table, some tests have no rows, and how a method handles them
determines its graph.
Tests with no rows#
Consider the smallest case: two cohorts from the fork X <- Z -> Y, one cohort measuring X and
Z, the other Y and Z. The true graph has two edges, and X and Y are independent given
Z. Because X and Y are never jointly measured, no test can check that independence. A
collider X -> Z <- Y can give both cohorts the same distributions, so these rows cannot establish
whether X and Y are adjacent. Every test of X and Y has no rows, as does every test of X
and Z given Y, or of Y and Z given X.
The same ambiguity holds in general. When some variables are never jointly measured, some of their independences and dependences are unknown, so multiple graphs can fit every dataset (Tillman and Spirtes, 2011). Methods built for this setting, ION (Tillman et al., 2008), IOD (Tillman and Spirtes, 2011), and COmbINE (Triantafillou and Tsamardinos, 2015), combine what each dataset shows and return all graphs consistent with them, or a summary of those graphs. COmbINE can even infer an edge between two variables never jointly measured from constraints that the datasets impose together. PC and FCI read a single table and do not combine datasets in this way.
What the usual answers get wrong#
p = 1 treats a test with no rows as evidence of independence. It removes X - Y, which happens
to be right here, and then removes the true edges X - Z given Y and Y - Z given X, so PC
with p = 1 returned the empty graph. With max_depth=0, so no edge is tested given a third
variable, it returned the collider X -> Z <- Y: X and Y were separated without Z, turning
an untested pair into a collider.
p = 0 treats a test with no rows as evidence of dependence. It keeps X - Y, an edge no row
supports, so PC returned the triangle. On larger datasets with overlapping variable sets, every pair
never jointly measured becomes an edge, and those edges create many false colliders.
Imputation, by EM or multiple imputation, fits a model over all columns to fill in the missing
values. Because no row observes X and Y together, their covariance comes from the fitted model,
not the data. After multiple imputation, any causal relation learned between variables never
jointly measured is right only if the assumed model gets that relation right; Structural EM, which
refits the model while filling in values, performed poorly on such data (Tillman et al., 2008).
Andrey’s missing="em" rejects such data and names the pair.
Dropping every incomplete row leaves none. Dropping X or Y until every pair shares rows
discards a variable and its edges. On the benchmark cohorts, PC then kept fewer of the true edges
between jointly measured variables than with Andrey’s answer.
What Andrey does#
Skips tests without enough rows. A conditional independence test with fewer rows than needed (
|S| + 4for Fisher’s z, where|S|is the conditioning-set size), or with no degrees of freedom left, is skipped. It neither removes an edge nor counts as evidence of dependence.Leaves out pairs that no test can decide. When no test has enough rows to decide a pair, such as variables never jointly measured, the pair is omitted from the graph and listed in
metadata["undecided_pairs"]. Orientation rules treat it as neither adjacent nor nonadjacent, so a triple whose endpoints form such a pair never becomes a collider.Lists edges that a skipped test might have removed. An edge is kept when no test with enough rows separated its endpoints, even if a skipped test, whose conditioning set was never observed with the pair, might have.
metadata["possibly_separable"]lists these edges to show what the data could not test, not to mark them as false.Keeps listed edges out of colliders on request. PC, FCI, CD-NOD, FCI-JCI, the Markov-blanket searches, and PCMCI+ accept
possibly_separable="ambiguous", which treats any triple containing one of these edges as neither a collider nor a non-collider. The default,"orient", orients it like any other triple.Logs one summary message. With the default
missing=None, fitting on incomplete data logs one message per process. It names test-wise deletion, states when it is valid, and counts the pairs never jointly measured, the omitted pairs, and the listed edges, naming them when there are at most five.Speeds up tests when missingness patterns are few. Multiple datasets with overlapping variable sets have few missingness patterns. For Fisher’s z and Student’s t, a test sums each pattern’s rows once when that is cheaper than scanning every row, and skips any conditioning set containing a variable never jointly measured with the pair before building it. On simulated cohorts with overlapping variable sets,
pcran faster with identical graphs, and withmax_depth=Noneit finishes on the larger setups of the benchmark below.
PC, FCI, CD-NOD, FCI-JCI, the Markov-blanket searches, PCMCI, PCMCI+, and LPCMCI all skip such tests and populate both lists; see the missing values guide for details on each method.
The two studies in the tables above come from the example below. Both measure W and Z; the
first also measures X, and the second Y. The true graph has X -> Z <- W and Z -> Y:
"""Two studies stacked into one table: both measure W and Z, only the first measures X, and only the
second measures Y, so no row observes X and Y together."""
import logging
import sys
import textwrap
import numpy as np
import pandas as pd
import andrey
class Wrapped(logging.Formatter):
"""Print each log record as a wrapped paragraph."""
def format(self, record):
text = f"{record.levelname}: {record.getMessage()}"
return textwrap.fill(text, 100, break_on_hyphens=False)
handler = logging.StreamHandler(sys.stdout)
handler.setFormatter(Wrapped())
logging.getLogger("andrey").addHandler(handler)
# The true graph: X -> Z <- W, and Z -> Y.
rng = np.random.default_rng(0)
n = 2000
x = rng.standard_normal(n)
w = rng.standard_normal(n)
z = 0.8 * x + 0.8 * w + 0.6 * rng.standard_normal(n)
y = 0.8 * z + 0.6 * rng.standard_normal(n)
data = pd.DataFrame({"X": x, "W": w, "Z": z, "Y": y})
data.loc[1000:, "X"] = np.nan # the second study did not measure X
data.loc[:999, "Y"] = np.nan # the first study did not measure Y
print("Complete rows:", len(data.dropna()))
print()
out = andrey.pc(data)
print(out)
print()
print(andrey.pc(data, possibly_separable="ambiguous").structure)
print()
try:
andrey.ges(data, missing="em")
except ValueError as error:
print("EM:", textwrap.fill(str(error), 96, subsequent_indent=" "))
Complete rows: 0
WARNING: andrey.pc: the data hold missing values and missing=None, so the fit ran the default
handling, test-wise deletion: each test read only the rows where its variables are observed.
Test-wise deletion is valid when values are missing completely at random, which means that whether a
value is missing depends on no value in the data; the rows a test reads are then a random sample of
all rows, and otherwise they are a selected sample that more rows do not correct. Pass
missing="testwise" to choose it by name, and read the rows the tests kept in
metadata["rows_tested"]. 1 pair of columns (X and Y) is never observed together, listed in
metadata["never_observed_together"]. A test whose variables are observed together on fewer rows than
it needs or that has no degrees of freedom left, a pair never observed together included, is not
tested: it never separates a pair and never confirms a link. A pair that no test with rows could
decide, such as a pair never observed together, is undecided: it is left out of the graph, no
orientation reads it as adjacent or apart, and metadata["undecided_pairs"] lists it. 1 pair (X and
Y) is undecided. An edge drawn although a conditioning set that could not be tested might have
separated its pair is listed in metadata["possibly_separable"]: the flag says what the data could
not check, not that the edge is false. 3 drawn edges (W and Z, X and Z, Y and Z) are flagged. This
notice is logged once per process.
pc cpdag | 4 nodes | 3 edges (3 directed)
X -> Z
W -> Z
Z -> Y
rows_tested: min 1000, median 1000
not_tested: 9
undecided_pairs: [['X', 'Y']]
possibly_separable: [['W', 'Z'], ['X', 'Z'], ['Y', 'Z']]
indep_test: fisherz
tie_break: rank
missing: testwise
never_observed_together: [['X', 'Y']]
cpdag | 4 nodes | 3 edges (3 undirected)
X -- Z
W -- Z
Z -- Y
EM: drop column 'X' or column 'Y', or add rows that observe both: missing="em" needs every pair of
columns observed together in at least one row, and these two share none, so the data hold no
covariance for them
Although no row is complete, PC recovers the true CPDAG: the collider at Z comes from X and
W, jointly measured in the first study, and Z -> Y follows because W and Y, jointly
measured in the second study, are independent given Z. X and Y are omitted from the graph and
listed in undecided_pairs.
All three edges appear in possibly_separable because each could have been removed by conditioning
on a variable measured only in the other study, which no row can test. Here all three edges are
true; on larger datasets with overlapping variable sets, the list also contains false edges. With
possibly_separable="ambiguous", both sides of the collider are on the list, so the graph keeps
its edges without arrowheads. EM rejects the data and explains what would let it run.
Benchmark on cohorts with overlapping variable sets#
We simulated cohorts with overlapping variable sets from linear-Gaussian graphs, drawing a new graph for each seed and giving the columns very different units, in three setups of increasing size. Some variables are measured in every cohort, some in several, and a few in only one, so some pairs are never jointly measured. The figure shows the missingness pattern of the smallest setup.
We ran PC and FCI with Fisher’s z, holding the search fixed while varying how tests without enough rows are answered, and compared each graph with the true graph, the empty graph, and the graph learned from the complete data. With no complete rows:
Fewer errors than the empty graph. PC’s and FCI’s graphs made fewer errors than the empty graph in every setting, counting FCI’s errors on its skeleton. In PC, answering p = 1 made about as many errors as the empty graph, and p = 0 more.
True edges kept. Between jointly measured variables, PC kept about as many true edges as on the complete data. Answering p = 1 removed most of them.
No pair decided without data. Pairs that no test can decide were never drawn, and every one was listed in
undecided_pairs.
The release card gives each setting’s numbers and intervals, along with results for dropping columns, false colliders, and time series.
Limitations and trade-offs#
The release card has the measurements behind these trade-offs.
True edges between variables never jointly measured are omitted. Because no row observes both endpoints, they are listed rather than drawn.
False edges remain, and
possibly_separabledoes not isolate them. A larger share of drawn edges are false than on complete data. Most connect jointly measured variables whose separating set is never observed alongside them, so their dependence appears as a direct edge. Every such false edge is inpossibly_separable, but so are nearly all drawn edges. These false edges drive most false colliders, and PC drew more false colliders than on complete data.possibly_separable="ambiguous"trades arrowheads for fewer false colliders. It removed nearly all false colliders, and nearly all true arrowheads with them. PC’s graph then made more errors than the empty graph, while FCI’s skeleton errors rose but stayed below the empty graph’s. Keep the default when you need orientations, and use"ambiguous"when false colliders cost more than missing arrowheads.A few rows measuring every variable decide cross-cohort tests on small samples. Such rows let every test run, but tests across cohorts then rest on those few rows and can remove true edges between jointly measured variables.
Test-wise deletion assumes data missing completely at random. Cohort membership is rarely random, and when missingness depends on other variables, testing only observed rows can yield wrong conclusions (Tu et al., 2019). Limiting conditioning-set size via
max_depthnever decides an unobserved pair; only rows observing both columns can.Tests pool rows across cohorts. Each test combines all cohorts that measure its variables into one sample. As Tillman and Spirtes (2011) note, pooling datasets into a single test often works worse in practice than combining per-dataset p-values, as IOD does.
Try it#
pip install -U andrey-core
See the missing values guide to choose a missing-data strategy for your dataset and missingness mechanism, and run each option in the missing values example.
Help us build it#
Andrey is in alpha, and its API may change between releases. If you try it on your own data, report what breaks or tell us which methods you need. Pull requests are welcome; see the contributing guide to set up a development environment.
This release grew out of a user report on cohorts with overlapping variable sets. Thank you for writing in.
References#
Tillman, R. E., Danks, D., and Glymour, C. (2008). Integrating locally learned causal structures with overlapping variables. NeurIPS 21. proceedings.neurips.cc.
Tillman, R. E., and Spirtes, P. (2011). Learning equivalence classes of acyclic models with latent and selection variables from multiple datasets with overlapping variables. AISTATS, PMLR 15, 3-15. proceedings.mlr.press.
Triantafillou, S., and Tsamardinos, I. (2015). Constraint-based causal discovery from multiple interventions over overlapping variable sets. JMLR 16(66), 2147-2205. jmlr.org.
Tu, R., Zhang, C., Ackermann, P., Mohan, K., Kjellström, H., and Zhang, K. (2019). Causal discovery in the presence of missing data. AISTATS, PMLR 89, 1762-1770. proceedings.mlr.press.
AI statement. Parts of this post were drafted with Claude Code, Codex, and Carbon. The author checked every statement, number, and reference and is responsible for the content.