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 automatic assignment of the causal mechanisms with the selection of the model of a node by cross validation, 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, the refutation of the graph, the do operator, the view of the graph and the interpretation of an estimate) |
| 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 -- with its list of transformations of the outcome, with its random forest, its neural network and its support vector regressor, and its two branches --, random common cause, unobserved common cause -- with its linear sensitivity analysis, its E-value analysis and the default strength it infers for its confounder --, the significance test of the refutations, the assess overlap refuter, which learns the rules of the support and of the overlap with boolean rules, and the graph refutation, which tests the conditional independences the graph entails against the data) |
| Synthetic data | dowhy.datasets | ported (linear_dataset, the sales data set, the random graph data set 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, its readers of a CSV and of a DOT, and the temporal shift) |
| Plotting | dowhy.utils.plotting, dowhy.utils.graphviz_plotting, dowhy.utils.networkx_plotting | ported (the width of the arrows, the label and the colour of the nodes and of the edges, the layer of every node, the uncertainty bars of a bar plot and the graph of an adjacency matrix) -- the port draws nothing, it computes the attributes of the two backends of the upstream and writes the ones of the Graphviz backend as a DOT document |
| 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 CatBoost encoder of the categorical columns, 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, the kernel based one, with categorical data, and the randomised one), the prediction models -- the linear one, the polynomial ones and the decision tree --, the causal mechanisms, the stochastic models, with the beta distribution, with the automatic selection of the family and with the Bayesian Gaussian mixture, the noise of a causal model, with a categorical root and with a categorical target, the feature relevance, the intrinsic causal influence, with a categorical target and with a categorical root, the equation parser, the probabilistic causal models, the fitting of a causal model, the automatic assignment of the mechanisms, with the selection of the model of a node by cross validation, the test of a linear relationship and the missing values, the what-if queries, with the categorical variables and with the discrete data, the validation layer, the falsification layer, with the categorical data, the model evaluation layer, the anomaly detection layer (the detection and the attribution, with a non-linear mechanism and without a causal model), the unit change layer, with its dispatcher and with the predicates of the exceptions of the upstream, 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, the tests of the conditional independence |
| 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) |
| interpreters | riantr/moonbit_dowhy/interpreters | dowhy.interpreters: the sentence that reads an estimate |
| estimators | riantr/moonbit_dowhy/estimators | dowhy.causal_estimators, with the conditional estimates of the regression based ones, the two stage regression of the frontdoor and of the mediation estimand and the do operator |
| refuters | riantr/moonbit_dowhy/refuters | dowhy.causal_refuters, with the graph refutation |
| 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 (the linear_dataset generator, the sales data set and the random graph data set) 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) |
| plotting | riantr/moonbit_dowhy/plotting | dowhy.utils.plotting, dowhy.utils.graphviz_plotting and dowhy.utils.networkx_plotting: the width of the arrows, the label and the colour of the nodes and of the edges, the layer of every node, the uncertainty bars of a bar plot and the graph of an adjacency matrix |
| 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 CatBoost encoder of the categorical columns, the prediction models with the decision tree, the causal mechanisms, the stochastic models with their Bayesian Gaussian mixture, the automatic assignment of the mechanisms with the selection of the model of a node by cross validation, the test of a linear relationship and the missing values, the noise of a causal model with a categorical root, the feature relevance, the intrinsic causal influence with a categorical target and with a categorical root, the equation parser, the fitting of a causal model, the what-if queries, the validation layer, the falsification layer with the categorical data, the model evaluation layer, the anomaly detection layer, the unit change layer with its dispatcher, 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, of the data subset refuter, of the dummy outcome refuter, of the unobserved common cause refuter, of the linear sensitivity analysis, of the E-value analysis, of the default strength of the confounder and of the graph refutation |
| 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::do_operator(self : CausalModel, x : Double, estimand : IdentifiedEstimand, method_name : String, fit_estimator? : Bool) -> Doublefn 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_e_value(causal_model : CausalModel, estimator : CausalEstimator, target_units? : String) -> EValueSensitivityAnalyzerfn CausalModel::refute_estimate(self : CausalModel, method_name : String, estimate : CausalEstimate, refuter_name : String, num_simulations : Int, random : Random, placebo_type? : PlaceboType) -> CausalRefutationfn CausalModel::refute_graph(self : CausalModel, k? : Int, independence_test? : IndependenceTests?, independence_constraints? : Array[Implication]) -> GraphRefutationfn CausalModel::refute_linear_sensitivity(self : CausalModel, estimator : CausalEstimator, benchmark_common_causes : Array[String], frac_strength_treatment : Array[Double], frac_strength_outcome : Array[Double]?, percent_change_estimate : Double, significance_level : Double, confounder_increases_estimate? : Bool) -> LinearSensitivityAnalyzerfn 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 automatic assignment of the causal mechanisms with the selection of the model of a node by cross validation, 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.