causalis.shared.confounder_clustering.CorrelationMethodCorrelationMethod
None
Python Docs
causalis
Package entry
causalisRoot package overview and namespace mapNamespaces
causalis.shared.confounder_clusteringSubmodule causalis.shared.confounder_clustering with no child pages and 6 documented members.
Functions
Jump directly into the documented functions for this page.
Data
Jump directly into the documented data for this page.
causalis.shared.confounder_clustering.CorrelationMethodNone
causalis.shared.confounder_clustering.LinkageMethodNone
causalis.shared.confounder_clustering.OutcomeImportanceMethodNone
causalis.shared.confounder_clustering.cluster_confoundersCluster confounders using their absolute pairwise correlations.
The clustering distance is
Hierarchical clustering is cut at 1 - min_abs_correlation. Negative
and positive correlations of the same magnitude are therefore treated as
equally similar. By default, complete linkage is used, so every pair of
features in a non-singleton cluster has an absolute correlation at least
as large as min_abs_correlation on the sampled data.
Parameters
Causal data contract exposing numeric df and confounders attributes.
Correlation cut-off in the closed interval [0, 1]. Larger values form smaller, more strongly related clusters.
Pairwise correlation measure. Spearman correlation is useful for monotonic non-linear relationships but requires more work and memory.
Hierarchical-linkage rule. Only complete linkage guarantees the pairwise threshold interpretation described above.
Maximum number of rows used to estimate correlations. If the dataset is larger, rows are sampled without replacement. Pass None to use all rows.
Seed used for row sampling.
Returns
Clusters in the original confounder order. Features within each cluster also preserve their original order. Singleton clusters are retained.
Examples
Notes
Missing correlations can occur when a rare feature is constant in the sampled rows. They are treated as zero correlation, leaving that feature separate unless it is linked to another feature by valid correlations.
Canonical target
causalis.shared.confounder_clustering.cluster_confounders
Sections
causalis.shared.confounder_clustering.rank_confounder_clustersCluster confounders and rank the clusters by joint nuisance importance.
For each correlation cluster Cg, the treatment and outcome importances are aggregated as
and, by default,
Clusters are sorted by score = importance_d * importance_y in
descending order. Native importance vectors are normalized separately for
m, g0, and g1 before aggregation.
Parameters
Data containing the confounders to cluster.
Fitted IRM, causal estimate with diagnostic data, or dictionary containing one of them. Feature importance must have been collected. min_abs_correlation, correlation_method, linkage_method, max_samples, random_state Forwarded to :func:cluster_confounders.
Combine the cluster-level g0 and g1 importance by their mean or maximum. "max" is more conservative for features important in only one treatment arm.
Returns
Cluster ranking with columns cluster_id, features, n_features, importance_d, importance_g0, importance_g1, importance_y, and score. Row zero is the highest-ranked cluster; features can be passed directly to sensitivity_benchmark_group.
Examples
Canonical target
causalis.shared.confounder_clustering.rank_confounder_clusters
Sections
causalis.shared.confounder_clustering.__all__[‘cluster_confounders’, ‘rank_confounder_clusters’]