MoonBit port of DoWhy 0.14 (PyWhy). Causal graph construction and analysis, effect identification (backdoor / frontdoor / complete adjustment), estimation (linear regression, generalized linear model, propensity score weighting / matching / stratification, doubly robust, instrumental variable, two stage, regression discontinuity), refutation (bootstrap, placebo treatment, data subset, dummy outcome, unobserved common cause, the assess overlap refuter that learns the rules of the support and of the overlap with boolean rules), intervention sampling (do samplers), temporal graphs, causal discovery (the PC algorithm with the Fisher-z test) and the portable core of the graphical causal models (the p-value merging, the bootstrap confidence intervals, the Kullback-Leibler divergences, the density estimators, the Shapley values, the independence tests, the prediction models, the causal mechanisms, the fitting of a causal model, the what-if queries (the interventional samples, the counterfactual samples and the average causal effect), the validation layer (the kernel based conditional independence test, the validation of a causal structure and the validation of an invertible model) and the falsification layer (the local Markov condition, the pairwise dependencies, the parental d-separations, the causal minimality and the permutation test of a graph) and the model evaluation layer (the normalised mean squared error, the continuous ranked probability score, the performance of the causal mechanisms, the test of the invertibility assumption and the report of the evaluation) and the distribution change layer (the test of the change of a mechanism, the attribution of the change of the distribution of a target node, the multiply-robust attribution of the change of the mean or of the variance of a target node and the scores of the change of the distribution of every node). Pure MoonBit with zero external runtime dependencies.
| Area | Upstream | This port |
|---|---|---|
| Causal graph, d-separation | dowhy.graph, dowhy.causal_graph | ported (the graph, the d-separation, the backdoor and the frontdoor paths, and the readers of the GML graphs, of the DOT graphs and of the graphs of the daggity web site) |
| Causal model | dowhy.causal_model | ported (the entry point, the graph given as a graph or as a string, the common causes, the instruments and the effect modifiers of the graph, the cache of the estimators, the conditional estimates of the regression based estimators) |
| Identification | dowhy.causal_identifier | ported (backdoor -- default, exhaustive, minimal, maximal, the three efficient strategies of Smucler-Sapienza-Rotnitzky and the optimized search -- frontdoor, general adjustment, IV, mediation -- the mediator, the confounders of its two stages and the natural indirect effect --, and the ID algorithm of Shpitser-Pearl) |
| Estimation | dowhy.causal_estimators | ported (linear regression, generalised linear model, propensity score weighting / matching / stratification, doubly robust, instrumental variable, two stage regression -- the two stages of the frontdoor and of the mediation estimand --, regression discontinuity) |
| Refutation | dowhy.causal_refuters | ported (bootstrap, placebo treatment, data subset, dummy outcome, random common cause, unobserved common cause, the significance test of the refutations, and the assess overlap refuter, which learns the rules of the support and of the overlap with boolean rules) |
| Synthetic data | dowhy.datasets | ported (linear_dataset and the fixtures the upstream tests use) |
| Categorical encoding | dowhy.utils.encoding | ported (the one-hot encoder and the encoder registry of the estimators) |
| Dimensionality reduction | dowhy.data_transformers | ported (the PCA reducer) |
| Intervention sampling | dowhy.do_sampler, dowhy.do_samplers | ported (the weighting, multivariate weighting and kernel density samplers) -- the MCMC sampler is not ported, it needs an inference engine upstream takes from PyMC3 |
| Time series | dowhy.timeseries | ported (the temporal graph and the temporal shift) |
| Causal discovery | dowhy.graph_learners | ported (the PC algorithm with the Fisher-z test of conditional independence) |
| Causal discovery | dowhy.graph_learners (GES, CDT, LiNGAM) | not ported -- upstream delegates those to causal-learn / cdt / lingam, which this dependency-free port does not wrap |
| Graphical causal models | dowhy.gcm | partially ported -- the configuration, the general helpers, the p-value merging, the F-test, the marginal expectation, the bootstrap confidence intervals, the Kullback-Leibler divergences, the kernel density estimator, the Shapley values, the independence tests (the regression, with and without categorical data, the generalised covariance measure and the kernel based one), the prediction models, the causal mechanisms, the stochastic models, the noise of a causal model, the feature relevance, the intrinsic causal influence, the equation parser, the probabilistic causal models, the fitting of a causal model, the automatic assignment of the mechanisms, the what-if queries, the validation layer, the falsification layer, the model evaluation layer, the anomaly detection layer (the detection and the attribution), the unit change layer, the uncertainty estimates, the distribution change layer -- the plain one and the multiply-robust one -- and the arrow strength layer are ported |
| Causal prediction | dowhy.causal_prediction | not ported -- upstream depends on PyTorch |
moon add riantr/moonbit_dowhyimport "riantr/moonbit_dowhy"
import "riantr/moonbit_dowhy/datasets"
/// Build a confounded data set: `W0 -> v0`, `W0 -> y`, `v0 -> y`.
let dataset = @datasets.linear_dataset(
42,
1000,
@datasets.LinearConfig::confounded(),
)
/// Build the model. The graph is derived from the semantic roles of the
/// variables when no explicit graph is given.
let model = @moonbit_dowhy.CausalModel::new(
dataset.frame(),
dataset.treatments(),
[dataset.outcome()],
None,
dataset.common_causes(),
dataset.instruments(),
dataset.effect_modifiers(),
dataset.frontdoor_variables(),
)
/// Identify the effect with the backdoor criterion.
let estimand = model.identify_effect("backdoor")
/// Estimate the average treatment effect.
let estimate = model.estimate_effect(
"backdoor.linear_regression",
1.0,
0.0,
"ate",
)
println("ATE: " + estimate.estimate().to_string())
println("95% CI: [" + estimate.confidence_interval_lower().to_string() +
", " + estimate.confidence_interval_upper().to_string() + "]")| Package | Import path | Ports |
|---|---|---|
| api | riantr/moonbit_dowhy/api | the subset of pandas.DataFrame the estimators use, plus the one-hot encoder |
| utils | riantr/moonbit_dowhy/utils | matrices, least squares, generalised linear models, distributions, descriptive statistics, a deterministic generator |
| graph | riantr/moonbit_dowhy/graph | dowhy.graph, dowhy.causal_graph, and the readers of the GML graphs, of the DOT graphs and of the graphs of the daggity web site |
| identifiers | riantr/moonbit_dowhy/identifiers | dowhy.causal_identifier, with the mediation identification and the natural indirect effect |
| model | riantr/moonbit_dowhy/model | dowhy.causal_estimator (the estimate objects) |
| estimators | riantr/moonbit_dowhy/estimators | dowhy.causal_estimators, with the conditional estimates of the regression based ones and the two stage regression of the frontdoor and of the mediation estimand |
| refuters | riantr/moonbit_dowhy/refuters | dowhy.causal_refuters |
| overrule | riantr/moonbit_dowhy/overrule | the OverRule algorithm of the refuter that assesses the support and the overlap: the binariser of the features, the sampler of the reference samples, the beam search of the pricing problem, the program of the rules and its rounding |
| datasets | riantr/moonbit_dowhy/datasets | dowhy.datasets and the deterministic test fixtures |
| data_transformers | riantr/moonbit_dowhy/data_transformers | dowhy.data_transformers (the PCA reducer) |
| do_samplers | riantr/moonbit_dowhy/do_samplers | dowhy.do_sampler, dowhy.do_samplers |
| timeseries | riantr/moonbit_dowhy/timeseries | dowhy.timeseries (the temporal graph and the temporal shift) |
| cm | riantr/moonbit_dowhy/cm | the PC causal discovery algorithm and the Fisher-z independence test |
| gcm | riantr/moonbit_dowhy/gcm | the portable core of dowhy.gcm: the statistics, the confidence intervals, the divergences, the density estimators, the Shapley values, the independence tests, the prediction models, the causal mechanisms, the feature relevance, the intrinsic causal influence, the equation parser, the fitting of a causal model, the what-if queries, the validation layer, the falsification layer, the model evaluation layer, the anomaly detection layer, the unit change layer, the uncertainty estimates, the distribution change layer -- the plain one and the multiply-robust one -- and the arrow strength layer |
| tests | riantr/moonbit_dowhy/tests | the cross-package integration tests, including the cases of the upstream test files of the causal model, of the estimators, of the two stage regression estimator, of the placebo treatment refuter, of the bootstrap refuter and of the data subset refuter |
| examples | riantr/moonbit_dowhy/examples | the runnable quick start |
moon check --deny-warn # a warning is a failure
moon test --deny-warn
moon fmt --check
typospub struct CausalModel {
data : DataFrame
treatment : Array[String]
outcome : Array[String]
graph : CausalGraph
observed_nodes : Array[String]
estimand : IdentifiedEstimand
estimator_cache : Map[String, CausalEstimator]
proceed_when_unidentifiable : Bool
identify_vars : Bool
estimand_type : String
}fn CausalModel::estimate_effect(self : CausalModel, method_name : String, treatment_value : Double, control_value : Double, target_units : String, effect_modifier_names? : Array[String], fit_estimator? : Bool) -> CausalEstimatefn CausalModel::new(data : DataFrame, treatment : Array[String], outcome : Array[String], graph : DirectedGraph?, common_causes : Array[String], instruments : Array[String], effect_modifiers : Array[String], mediators : Array[String], missing_nodes_as_confounders? : Bool, identify_vars? : Bool, proceed_when_unidentifiable? : Bool, estimand_type? : String) -> CausalModelfn CausalModel::new_with_graph_string(data : DataFrame, treatment : Array[String], outcome : Array[String], graph : String, common_causes : Array[String], instruments : Array[String], effect_modifiers : Array[String], missing_nodes_as_confounders? : Bool, identify_vars? : Bool, proceed_when_unidentifiable? : Bool, estimand_type? : String) -> CausalModelfn CausalModel::refute_assess_overlap(self : CausalModel, support_config? : SupportConfig, overlap_config? : OverlapConfig, overlap_eps? : Double, support_only? : Bool, overlap_only? : Bool) -> OverlapAnalyzerfn CausalModel::refute_estimate(self : CausalModel, method_name : String, estimate : CausalEstimate, refuter_name : String, num_simulations : Int, random : Random, placebo_type? : PlaceboType) -> CausalRefutationfn is_supported_graph_format(graph : String) -> BoolInstall
Download zipMoonBit port of DoWhy 0.14 (PyWhy). Causal graph construction and analysis, effect identification (backdoor / frontdoor / complete adjustment), estimation (linear regression, generalized linear model, propensity score weighting / matching / stratification, doubly robust, instrumental variable, two stage, regression discontinuity), refutation (bootstrap, placebo treatment, data subset, dummy outcome, unobserved common cause, the assess overlap refuter that learns the rules of the support and of the overlap with boolean rules), intervention sampling (do samplers), temporal graphs, causal discovery (the PC algorithm with the Fisher-z test) and the portable core of the graphical causal models (the p-value merging, the bootstrap confidence intervals, the Kullback-Leibler divergences, the density estimators, the Shapley values, the independence tests, the prediction models, the causal mechanisms, the fitting of a causal model, the what-if queries (the interventional samples, the counterfactual samples and the average causal effect), the validation layer (the kernel based conditional independence test, the validation of a causal structure and the validation of an invertible model) and the falsification layer (the local Markov condition, the pairwise dependencies, the parental d-separations, the causal minimality and the permutation test of a graph) and the model evaluation layer (the normalised mean squared error, the continuous ranked probability score, the performance of the causal mechanisms, the test of the invertibility assumption and the report of the evaluation) and the distribution change layer (the test of the change of a mechanism, the attribution of the change of the distribution of a target node, the multiply-robust attribution of the change of the mean or of the variance of a target node and the scores of the change of the distribution of every node). Pure MoonBit with zero external runtime dependencies.