statspai.transport¶
transport ¶
Transportability (sp.transport): generalize causal effects across
populations. Combines Pearl-Bareinboim identification (selection
diagrams) with Dahabreh-Stuart-style density-ratio weighting.
Quick start
import statspai as sp g = sp.dag("S -> X; X -> Y; S -> Y") sp.transport.identify_transport(g, treatment="X", outcome="Y", ... selection_nodes={"S"}) sp.transport.weights(source=rct, target=target_df, ... features=["age", "sex"], ... treatment="treat", outcome="y")
EvidenceSynthesisResult
dataclass
¶
Output of :func:synthesise_evidence.
HeterogeneityResult
dataclass
¶
Effect-heterogeneity diagnostic.
ConcordanceResult
dataclass
¶
RCT-vs-RWD concordance report.
weights ¶
weights(source: DataFrame, target: DataFrame, features: Sequence[str], treatment: str, outcome: str, truncate: tuple[float, float] | None = (0.01, 0.99)) -> TransportWeightResult
Compute transport weights and a transported ATE.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
DataFrame
|
Source (must contain |
required |
target
|
DataFrame
|
Source (must contain |
required |
features
|
list[str]
|
Baseline covariates shared by both populations that identify target-conditional exchangeability. |
required |
treatment
|
str
|
Column names in |
required |
outcome
|
str
|
Column names in |
required |
truncate
|
tuple[float, float] | None
|
Weight quantiles for truncation. |
(0.01, 0.99)
|
Returns:
| Type | Description |
|---|---|
TransportWeightResult
|
|
identify_transport ¶
Test s-admissibility of some conditioning set.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dag
|
DAG
|
Causal graph. |
required |
treatment
|
str | Iterable[str]
|
Intervention set X. |
required |
outcome
|
str | Iterable[str]
|
Outcome set Y. |
required |
selection_nodes
|
Iterable[str]
|
Nodes ( |
required |
Returns:
| Type | Description |
|---|---|
TransportIdentificationResult
|
|
synthesise_evidence ¶
synthesise_evidence(*, rct_estimate: float, rct_se: float, rwd_estimate: float, rwd_se: float, transport_shift: float = 0.0, transport_shift_se: float = 0.0, alpha: float = 0.05, weight_mode: str = 'inverse_variance') -> EvidenceSynthesisResult
Pool an RCT and an RWD estimate into a single evidence-synthesis.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rct_estimate
|
float
|
RCT effect estimate and its SE. |
required |
rct_se
|
float
|
RCT effect estimate and its SE. |
required |
rwd_estimate
|
float
|
RWD effect estimate and its SE (already transport-weighted if that is the design). |
required |
rwd_se
|
float
|
RWD effect estimate and its SE (already transport-weighted if that is the design). |
required |
transport_shift
|
float
|
Additive adjustment applied to the RCT estimate to transport it to the RWD target population (e.g. using density-ratio weights). |
0.0
|
transport_shift_se
|
float
|
SE of the transport shift, added in quadrature to the RCT SE. |
0.0
|
alpha
|
float
|
|
0.05
|
weight_mode
|
('inverse_variance', 'rct_heavy')
|
|
'inverse_variance'
|
Returns:
| Type | Description |
|---|---|
EvidenceSynthesisResult
|
|
References
Dahabreh et al. (2020); Yang, Gamalo & Fu (arXiv:2511.19735, 2025). [@yang2025integrating]
heterogeneity_of_effect ¶
heterogeneity_of_effect(estimates: Sequence[float], ses: Sequence[float]) -> HeterogeneityResult
Effect-heterogeneity diagnostic (DerSimonian-Laird).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
estimates
|
sequence of float
|
|
required |
ses
|
sequence of float
|
|
required |
Returns:
| Type | Description |
|---|---|
HeterogeneityResult
|
|
rwd_rct_concordance ¶
rwd_rct_concordance(*, rct_estimate: float, rct_se: float, rwd_estimate: float, alpha: float = 0.05) -> ConcordanceResult
Report-card metric for whether an RWD estimate agrees with the RCT.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rct_estimate
|
float
|
|
required |
rct_se
|
float
|
|
required |
rwd_estimate
|
float
|
|
required |
alpha
|
float
|
|
0.05
|
Returns:
| Type | Description |
|---|---|
ConcordanceResult
|
|