Skip to content

Separate scenario contrasts from causal effects

A modeled “what if” comparison describes outcomes under specified model assumptions. Estimating a causal effect from observed outcomes additionally requires a design and identification assumptions. Use the scenario tutorial for the first task. This tutorial examines a small native cross-fitted contrast and makes its calculation and limits explicit.

You will reproduce six held-out nuisance predictions and AIPW scores, understand why the estimate differs from a simple difference in sample means, and inspect training-arm overlap. You will also verify that insufficient arm counts, insufficient distinct clusters and clusters split across folds are rejected.

Use the native development environment and basic familiarity with treatment indicators and averages. The six observations are deliberately synthetic. They are not clinical or policy data and do not identify an empirical treatment effect.

The operation is summarize_causal with method cross_fitted_stratum_ate. All observations share one stratum. Fold one contains observations 1–3; fold two contains observations 4–6. Nuisance values for each held-out fold are estimated from the other fold. Cross-fitting and orthogonal scores have a broader statistical theory described by Chernozhukov and colleagues (2018). This fixture checks a particular stratum-based calculation; it does not implement or validate every estimator discussed in that work.

Run the maintained file from the repository root:

Terminal window
.venv-native/bin/python -I examples/native_overlap.py
examples/native_overlap.py
"""Check cross-fitted overlap and contrasts against six hand-worked observations.
These synthetic outcomes do not identify an empirical treatment effect. Meeting
an overlap count threshold does not establish exchangeability, adequate precision
or a suitable analysis design. Threshold one is deliberately small in this demo.
"""
import json
import math
from innovate import NativeError, execute
def main() -> None:
"""Validate held-out predictions, an independent score oracle and overlap guards."""
payload = {
"method": "cross_fitted_stratum_ate",
"outcomes": [1, 2, 3, 4, 5, 6],
"treatment": [0, 0, 1, 0, 1, 1],
"strata": ["a"] * 6,
"folds": [1, 1, 1, 2, 2, 2],
"minimum_training_arm_count": 1,
}
result = execute("summarize_causal", **payload)["result"]
# Fold one trains on outcomes 4,5,6; fold two trains on outcomes 1,2,3.
# Their respective treatment fractions are 2/3 and 1/3.
expected_propensities = [2 / 3] * 3 + [1 / 3] * 3
expected_control_means = [4.0] * 3 + [1.5] * 3
expected_treated_means = [5.5] * 3 + [3.0] * 3
for actual, expected in (
(result["propensities"], expected_propensities),
(result["control_predictions"], expected_control_means),
(result["treated_predictions"], expected_treated_means),
):
assert all(math.isclose(a, b, rel_tol=1e-12, abs_tol=1e-12) for a, b in zip(actual, expected, strict=True))
overlap = result["overlap"]
assert overlap["min_training_arm_count"] == 1
assert overlap["min_training_arm_clusters"] is None
assert math.isclose(overlap["min_propensity"], 1 / 3)
assert math.isclose(overlap["max_propensity"], 2 / 3)
# For score mu1-mu0 + T*(Y-mu1)/e - (1-T)*(Y-mu0)/(1-e), the six
# hand-calculated scores are below. This oracle never calls a model fitter.
scores = [10.5, 7.5, -2.25, -2.25, 7.5, 10.5]
expected_ate = sum(scores) / len(scores)
expected_se = math.sqrt(sum((score - expected_ate) ** 2 for score in scores) / (len(scores) * (len(scores) - 1)))
assert math.isclose(result["contrast"]["estimate"], expected_ate, rel_tol=1e-12)
assert math.isclose(result["contrast"]["influence_standard_error"], expected_se, rel_tol=1e-12)
assert result["contrast"]["observations"] == len(scores)
# Repeated observations within one arm still count as one distinct cluster.
clusters = ["fold1-control", "fold1-control", "fold1-treated", "fold2-control", "fold2-treated", "fold2-treated"]
clustered = execute("summarize_causal", **payload, clusters=clusters, minimum_training_arm_clusters=1)["result"]
assert clustered["overlap"]["min_training_arm_clusters"] == 1
assert math.isclose(clustered["contrast"]["estimate"], expected_ate, rel_tol=1e-12)
assert clustered["contrast"]["cluster_count"] == len(set(clusters))
invalid_designs = [
({**payload, "minimum_training_arm_count": 2}, "minimum_training_arm_count"),
({**payload, "clusters": clusters, "minimum_training_arm_clusters": 2}, "minimum_training_arm_clusters"),
(
{**payload, "clusters": ["split", "c1", "t1", "split", "t2", "t2"]},
"single cross-fitting fold",
),
]
rejected_designs = 0
for invalid, expected_message in invalid_designs:
try:
execute("summarize_causal", **invalid)
except NativeError as error:
assert error.code == "invalid_request" and expected_message in str(error)
rejected_designs += 1
else:
raise AssertionError("An invalid overlap or fold design was silently accepted.")
assert rejected_designs == len(invalid_designs)
print(
json.dumps(
{
"ate": round(result["contrast"]["estimate"], 6),
"minimum_training_arm_count": overlap["min_training_arm_count"],
"minimum_training_arm_clusters": clustered["overlap"]["min_training_arm_clusters"],
"propensity_range": [round(overlap["min_propensity"], 6), round(overlap["max_propensity"], 6)],
"rejected_designs": rejected_designs,
},
sort_keys=True,
)
)
if __name__ == "__main__":
main()

Read the independent expected values before the native call’s result checks. The script then repeats the calculation with cluster identifiers and submits three deliberately invalid designs. Each invalid design must raise the expected native error rather than silently weakening the requested overlap condition.

Successful execution prints:

{"ate": 5.25, "minimum_training_arm_clusters": 1, "minimum_training_arm_count": 1, "propensity_range": [0.333333, 0.666667], "rejected_designs": 3}

The estimate is 5.25, the held-out propensity range is one-third to two-thirds, and all three invalid designs are rejected. A minimum arm count of one is intentionally small enough to expose the mechanics of this six-row fixture. It is not a recommendation for empirical analysis.

For observation i, the checked score is mu1 - mu0 + T * (Y - mu1) / e - (1 - T) * (Y - mu0) / (1 - e). Here e is the training fold’s treatment fraction and mu0, mu1 are its control and treated outcome means within the stratum.

Held-out observation Outcome Treatment Training propensity Training control mean Training treated mean Score
1 1 0 2/3 4 5.5 10.5
2 2 0 2/3 4 5.5 7.5
3 3 1 2/3 4 5.5 -2.25
4 4 0 1/3 1.5 3 -2.25
5 5 1 1/3 1.5 3 7.5
6 6 1 1/3 1.5 3 10.5

The score average is 5.25. For this unclustered calculation, the example also checks the influence standard error against the score-based formula sqrt(sum((score - mean_score)^2) / (n * (n - 1))). These calculations validate the implemented arithmetic, not the coverage of an interval with six observations.

Reader task: recover the first score without calling the library. Its outcome regression difference is 1.5. The control residual correction is -(1 - 4) / (1 - 2/3) = 9, giving 10.5. The large correction illustrates why small training samples and limited overlap deserve scrutiny even when a threshold passes.

A causal interpretation requires assumptions including consistency, appropriate handling of interference, exchangeability given the chosen covariates, and positivity. Cole and Hernán (2008) explain the substantive consistency, exchangeability and positivity requirements. Passing an overlap-count threshold cannot establish them. The stratum-based nuisance estimates here also do not constitute a general-purpose machine-learning pipeline or resolve unmeasured confounding.

Cluster identifiers must represent the actual dependence structure. Repeated rows from one cluster do not create additional independent training clusters; the example checks that distinction and rejects a cluster spanning folds. Four synthetic clusters do not establish reliable cluster-based inference.

For a model-based intervention comparison, return to scenario experiments. For empirical analysis, define the estimand and design before interpreting this operation’s output. The native guide records remaining scientific acceptance requirements.