Package: esa-2scm
ESA-2SCM: Elastic Segment Allocation-based 2SLS Structural Causal Model for Causal DiscoveryESA-2SCM is a new method for detecting causality based on Elastic Segment Allocation-based synthetic instrumental variables with 2SLS application for estimating structural causal models.For details of the model design, please refer to my Original Article:Lee, Sanghoon (2024).ESA-2SCM for Causal Discovery: Causal Modeling with Elastic Segmentation-based Synthetic Instrumental Variable,SnB Political and Economic Research Institute,1,16. <snbperi.org/article/227>Model OverviewSuppose that you are interested in discovering the causal relationship between $x_1$ and $x_2$ (e.g., determining thetrue causal direction: $x_1$ -> $x_2$ vs. $x_2$ -> $x_1$, measuring the magnitude ofcausal impact):Estimation of the above equation under standard OLS isstructurallybiased and inconsistent due to endogeneity:wherethus,The estimators are also inconsistent, as:ESA-2SCMprovides a countermeasure to such problem, enabling the determination of truecausal directionand estimation of the truecausal coefficientthrough the following procedures.Vector definition:Sorting:Set initial number of segments(M):Segment size allocation:Elastic adjustment algorithm for adjusting the number of segments:Grouping:Segment value assignment:Apply 2SLS using the generated Synthetic IV vectors(Z):Model Specification:Get $z_1$ and  $z_2$ via applying the process (1) to (7) for  $x_1$ and  $x_2$, then perform 2SLS to estimate for:RequirementsPython3numpypandasscipyscikit-learnInstallationTo install the ESA-2SCM package, usepipas follows:pipinstallesa-2scmExample Usageimportnumpyasnpimportpandasaspdfromesa_2scmimportESA2SCM# For causal discovery and determination of the true causal direction, input x_1 and x_2 as follows to initialize the ESA-2SCM model:model=ESA2SCM(x1,x2)# Fit the model, using Synthetic IV generation method(syniv_method, default: 'ESA') to estimate causality# Adjust the parameter M(default=2) to manually manage the degree of correlation between the Synthetic IVs (2SLS-converted) and the respective endogenous variablesmodel.fit(syniv_method="esa",M=2)# To confirm the estimated causal direction:print(model.causal_direction)# To confirm the goodness of fit and causal coefficient for the detected causal direction:print(model.score)print(model.causal_coef)# To check the degree of correlation between the generated Synthetic IVs and the endogenous variables (x1 and x2, respectively):print(model.corr_x1_to_slsiv)print(model.corr_x2_to_slsiv)# For model summary:model.summary()DocumentationOriginal Article of the ESA-2SCM:Lee, Sanghoon (2024).ESA-2SCM for Causal Discovery: Causal Modeling with Elastic Segmentation-based Synthetic Instrumental Variable,SnB Political and Economic Research Institute,1,16. <snbperi.org/article/227>[ARTICLE LINK]ExamplesExamples of running ESA-2SCM in Jupyter Notebook are included inesa_2scm/examplesLicenseMy package is licensed under the terms of theMIT licenseReferencesESA-2SCM PackageShould you use my package to perform ESA-2SCM for causal discovery, please kindly cite my Original Article:Lee, Sanghoon (2024).ESA-2SCM for Causal Discovery: Causal Modeling with Elastic Segmentation-based Synthetic Instrumental Variable,SnB Political and Economic Research Institute,1,16. <snbperi.org/article/227>[ARTICLE LINK]