{"id":20195093,"url":"https://github.com/realrate/causing","last_synced_at":"2025-04-05T10:07:40.487Z","repository":{"id":38461570,"uuid":"266800515","full_name":"realrate/Causing","owner":"realrate","description":"Causing: CAUsal INterpretation using Graphs","archived":false,"fork":false,"pushed_at":"2025-04-02T07:56:15.000Z","size":4895,"stargazers_count":57,"open_issues_count":3,"forks_count":9,"subscribers_count":3,"default_branch":"develop","last_synced_at":"2025-04-05T10:07:34.346Z","etag":null,"topics":["automatic-differentiation","causal-networks","causality-analysis","dag","derivatives","do-calculus","effects-modeling","gnn","graph-theory","graphs","latent-variables","mediation-analysis","neural-networks","python","pytorch","simultaneous-equation","structural-analysis","structural-equation-modeling"],"latest_commit_sha":null,"homepage":"https://github.com/realrate/Causing","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/realrate.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"docs/contributing.md","funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-05-25T14:29:04.000Z","updated_at":"2025-03-27T20:47:36.000Z","dependencies_parsed_at":"2024-05-01T11:41:43.015Z","dependency_job_id":"06e1fe75-7a8d-43c6-9463-a371a0be284d","html_url":"https://github.com/realrate/Causing","commit_stats":{"total_commits":432,"total_committers":16,"mean_commits":27.0,"dds":0.6087962962962963,"last_synced_commit":"a480c9c9f3c53c82b0b818af3e971c7356704787"},"previous_names":[],"tags_count":17,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/realrate%2FCausing","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/realrate%2FCausing/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/realrate%2FCausing/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/realrate%2FCausing/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/realrate","download_url":"https://codeload.github.com/realrate/Causing/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247318744,"owners_count":20919484,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["automatic-differentiation","causal-networks","causality-analysis","dag","derivatives","do-calculus","effects-modeling","gnn","graph-theory","graphs","latent-variables","mediation-analysis","neural-networks","python","pytorch","simultaneous-equation","structural-analysis","structural-equation-modeling"],"created_at":"2024-11-14T04:15:45.409Z","updated_at":"2025-04-05T10:07:40.470Z","avatar_url":"https://github.com/realrate.png","language":"Python","readme":"# Causing: CAUSal INterpretation using Graphs\n\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n[![Python 3.7](https://img.shields.io/badge/python-3.7-blue.svg)](https://www.python.org/)\n\n_Causing is a multivariate graphical analysis tool helping you to interpret the causal\neffects of a given equation system._ \n\nGet a nice colored graph and immediately understand the causal effects between the variables.\n\n**Input:** You simply have to put in a dataset and provide an equation system in form of a\npython function. The endogenous variables on the left-hand side are assumed to be caused by\nthe variables on the right-hand side of the equation. Thus, you provide the causal structure\nin form of a directed acyclic graph (DAG).\n\n**Output:** As an output, you will get a colored graph of quantified effects acting between\nthe model variables. You can immediately interpret mediation chains for every\nindividual observation - even for highly complex nonlinear systems.\n\nHere is a table relating Causing to other approaches:\n\nCausing is | Causing is NOT\n--- | ---\n✅ causal model given | ❌ causal search\n✅ DAG directed acyclic graph | ❌ cyclic, undirected, or bidirected graph\n✅ latent variables | ❌ just observed / manifest variables\n✅ individual effects | ❌ just average effects\n✅ direct, total, and mediation effects | ❌ just total effects\n✅ structural model | ❌ reduced model\n✅ small and big data | ❌ big data requirement\n✅ graphical results | ❌ just numerical results\n✅ XAI explainable AI | ❌ black box neural network\n\nThe Causing approach is quite flexible. It can be applied to highly latent models with many of the modeled endogenous variables being unobserved. Exogenous variables are assumed to be observed and deterministic. The most severe restriction certainly is that you need to specify the causal model / causal ordering. \n\n## Causal Effects\n\nCausing combines total effects and mediation effects in one single graph that is easy to explain. \n\nThe total effects of a variable on the final variable are shown in the corresponding nodes of the graph. The total effects are split up over their outgoing edges, yielding the mediation effects shown on the edges. Just education has more than one outgoing edge to be interpreted in this way.\n\nThe effects differ from individual to individual. To emphasize  this, we talk about individual effects. And the corresponding graph, combining total and mediation effects is called the Individual  Mediation Effects (IME) graph. \n\n## Software\n\nCausing is free software written in _Python 3_. Graphs are generated using _Graphviz_. See dependencies in [setup.py](setup.py). Causing is available under MIT license. See [LICENSE](LICENSE.md \"LICENSE\").\n\nThe software is developed by RealRate, an AI rating agency aiming to re-invent the rating market by using AI, interpretability, and avoiding any conflict of interest. See www.realrate.ai.\n\nWhen starting `python -m causing.examples example` after cloning / downloading the Causing repository you will find the results  in the _output_ folder. The results are saved in SVG files. The IME files show the individual mediation effects graphs for the respective individual.\n\nSee `causing/examples` for the code generating some examples.\n\n## Start your Model\n\nTo start your model, you have to provide the following information, as done in the example code below:\n\n- Define all your model variables as SymPy symbols.\n- Note that in Sympy some operators are special, e.g. Max() instead of max().\n- Provide the model equations in topological order, that is, in order of computation.\n- Then the model is specified with:\n    - _xvars_: exogenous variables\n    - _yvars_: endogenous variables in topological order\n    - _equations_: previously defined equations\n    - _final_var_: the final variable of interest used for mediation effects\n\n## 1. A Simple Example\n\nAssume a model defined by the equation system:\n\nY\u003csub\u003e1\u003c/sub\u003e = X\u003csub\u003e1\u003c/sub\u003e\n\nY\u003csub\u003e2\u003c/sub\u003e = X\u003csub\u003e2\u003c/sub\u003e + 2 * Y\u003csub\u003e1\u003c/sub\u003e\u003csup\u003e2\u003c/sup\u003e\n\nY\u003csub\u003e3\u003c/sub\u003e = Y\u003csub\u003e1\u003c/sub\u003e + Y\u003csub\u003e2\u003c/sub\u003e.\n\nThis gives the following graphs. Some notes to understand them:\n\n- The data used consists of 200 observations. They are available for the x variables X\u003csub\u003e1\u003c/sub\u003e and X\u003csub\u003e2\u003c/sub\u003e with mean(X\u003csub\u003e1\u003c/sub\u003e) = 3 and mean(X\u003csub\u003e2\u003c/sub\u003e) = 2. Variables Y\u003csub\u003e1\u003c/sub\u003e and Y\u003csub\u003e2\u003c/sub\u003e are assumed to be latent / unobserved. Y\u003csub\u003e3\u003c/sub\u003e is assumed to be manifest / observed. Therefore, 200 observations are available for Y\u003csub\u003e3\u003c/sub\u003e.\n\n- To allow for benchmark comparisons, each individual effect is measured with respect to the mean of all observations. \n\n- Nodes and edges are colored, showing positive (_green_) and negative (_red_) effects they have on the final variable Y\u003csub\u003e3\u003c/sub\u003e.\n\n- Individual effects are based on the given model. For each individual, however, its _own_ exogenous data is put into the given graph function to yield the corresponding endogenous values. The effects are computed at this individual point. Individual effects are shown below just for individual no. 1 out of the 200 observations. \n\n- Total effects are shown below in the nodes and they are split up over the outgoing edges yielding the Mediation effects shown on the edges. Note, however, that just outgoing edges sum up to the node value, incoming edges do not. All effects are effects just on the final variable of interest, assumed here to be Y\u003csub\u003e3\u003c/sub\u003e.\n\n![Individual Mediation Effects (IME)](https://github.com/realrate/Causing/raw/develop/images_readme/IME_1.svg)\n\nAs you can see in the right-most graph for the individual mediation effects (IME), there is one green path starting at X\u003csub\u003e1\u003c/sub\u003e passing through Y\u003csub\u003e1\u003c/sub\u003e, Y\u003csub\u003e2\u003c/sub\u003e, and finally ending in Y\u003csub\u003e3\u003c/sub\u003e. This means that X\u003csub\u003e1\u003c/sub\u003e is the main cause for Y\u003csub\u003e3\u003c/sub\u003e taking on a value above average with its effect on Y\u003csub\u003e3\u003c/sub\u003e being +29.81. However, this positive effect is slightly reduced by X\u003csub\u003e2\u003c/sub\u003e. In total, accounting for all exogenous and endogenous effects, Y\u003csub\u003e3\u003c/sub\u003e is +27.07 above average. You can understand at one glance why Y\u003csub\u003e3\u003c/sub\u003e is above average for individual no. 1.\n\nYou can find the full source code for this example [here](https://github.com/realrate/Causing/blob/develop/causing/examples/models.py#L16-L45).\n\n## 2. Application to Education and Wages\n\nTo dig a bit deeper, here we have a real-world example from social sciences. We analyze how the wage earned by young American workers is determined by their educational attainment, family characteristics, and test scores.\n\nThis 5-minute introductory video gives a short overview of Causing and includes this real data example: See [Causing Introduction Video](https://youtu.be/GJLsjSZOk2w \"Causing_Introduction_Video\").\n\nSee here for a detailed analysis of the Education and Wages example: [An Application of Causing: Education and Wages](docs/education.md).\n\n## 3. Application to Insurance Ratings\n\nThe Causing approach and its formulas together with an application are given in:\n\n\u003e Bartel, Holger (2020), \"Causal Analysis - With an Application to Insurance Ratings\"\nDOI: 10.13140/RG.2.2.31524.83848\nhttps://www.researchgate.net/publication/339091133\n\nNote that in this early paper the mediation effects on the final variable of interest are called final effects. Also, while the current Causing version just uses numerically computed effects, that paper uses closed formulas.\n\nThe paper proposes simple linear algebra formulas for the causal analysis of equation systems. The effect of one variable on another is the total derivative. It is extended to endogenous system variables. These total effects are identical to the effects used in graph theory and its do-calculus. Further, mediation effects are defined, decomposing the total effect of one variable on a final variable of interest over all its directly caused variables. This allows for an easy but in-depth causal and mediation analysis. \n\nThe equation system provided by the user is represented as a structural neural network (SNN). The network's nodes are represented by the model variables and its edge weights are given by the effects. Unlike classical deep neural networks, we follow a sparse and 'small data' approach. This new methodology is applied to the financial strength ratings of insurance companies. \n\n\u003e **Keywords:** total derivative, graphical effect, graph theory, do-Calculus, structural neural network, linear Simultaneous Equations Model (SEM), Structural Causal Model (SCM), insurance rating\n\n## Award\n\nRealRate's AI software _Causing_ is a winner of the PyTorch AI Hackathon.\n\n\u003cimg src=\"https://github.com/realrate/Causing/raw/develop/images_readme/RealRate_AI_Software_Winner.png\"\u003e\n\nWe are excited to be a winner of the PyTorch AI Hackathon 2020 in the Responsible AI category. This is quite an honor given that more than 2,500 teams submitted their projects.\n\n[devpost.com/software/realrate-explainable-ai-for-company-ratings](https://devpost.com/software/realrate-explainable-ai-for-company-ratings \"devpost.com/software/realrate-explainable-ai-for-company-ratings\").\n\n## GitHub Star History\n\n[star-history.com](https://www.star-history.com/#realrate/Causing\u0026Date)\n![star-history-2025327](https://github.com/user-attachments/assets/67271706-0534-4b97-b9da-7fe502f1d94a)\n\n## Contact\n\nDr. Holger Bartel  \nRealRate  \nCecilienstr. 14, D-12307 Berlin  \n[holger.bartel@realrate.ai](mailto:holger.bartel@realrate.ai?subject=[Causing])  \nPhone: +49 160 957 90 844  \n[realrate.ai](https://realrate.ai)  \n[drbartel.com](https://drbartel.com)  \n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frealrate%2Fcausing","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frealrate%2Fcausing","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frealrate%2Fcausing/lists"}