{"id":16525635,"url":"https://github.com/camdavidsonpilon/dog","last_synced_at":"2025-10-05T16:11:25.309Z","repository":{"id":66073628,"uuid":"142591754","full_name":"CamDavidsonPilon/dog","owner":"CamDavidsonPilon","description":"a simple casual graph evaluator (for experiments)","archived":false,"fork":false,"pushed_at":"2019-01-03T16:44:45.000Z","size":547,"stargazers_count":13,"open_issues_count":1,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-09-09T22:03:04.747Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/CamDavidsonPilon.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2018-07-27T15:05:45.000Z","updated_at":"2023-09-08T17:43:12.000Z","dependencies_parsed_at":null,"dependency_job_id":"5e57bcf7-3bd4-4e24-830d-2f14a0280160","html_url":"https://github.com/CamDavidsonPilon/dog","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/CamDavidsonPilon/dog","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CamDavidsonPilon%2Fdog","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CamDavidsonPilon%2Fdog/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CamDavidsonPilon%2Fdog/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CamDavidsonPilon%2Fdog/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/CamDavidsonPilon","download_url":"https://codeload.github.com/CamDavidsonPilon/dog/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CamDavidsonPilon%2Fdog/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278478870,"owners_count":25993738,"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","status":"online","status_checked_at":"2025-10-05T02:00:06.059Z","response_time":54,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":[],"created_at":"2024-10-11T17:04:24.857Z","updated_at":"2025-10-05T16:11:25.297Z","avatar_url":"https://github.com/CamDavidsonPilon.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"Dog\n------\n\n\nDog is a simple programming language for experimenting with causal diagram. With Dog, one can define a causal diagram using formulas and then both i) represent the diagram visually, ii) evaulate the effect of an exposure on an outcome variable. \n\nWhy? I wanted to quickly test ideas like:\n\n1) What happens to my regression coefficients when I introduce a mediator?\n2) What happens to my regression coefficients when I control for an independent factor?\n3) What's the impact of controlling inappropriately for a collider?\netc.\n\n\nSyntax and Grammar\n----------------------\n\n - `\u003cvariables\u003e`: these represent nodes in the causal diagram. There are  special variables, denoted `E` and `O` (exposure and outcome). The outcome variable, `O`, is necessary to be defined. \n - `~`: represent a causal relationship. The LHS is a child variable of all the  variables on the RHS.\n - `+`: assumes a linear relationship between variables\n - `\u003cfloats\u003e`: can be added or multiplied to variables\n - `*`: multiply a float by a variable.\n - `;`: end of line statement\n - `//`: inline comment\n - `(` and `)` are used to denote unobserved variables on either side of the `~`\n\nDog programs are represented as lines of forumlas, each line describing parent-child relationships. \n\nExample:\n\n```\n// graph.dg\nR ~ X1 + X2 + X3;\nZ ~ X4;\nZ ~ X2;\nZ ~ X4 + X5; // X4 will only be added once\nE ~ Z + R;\nO ~ 5.0*E + Z;\n```\n\nThis produces the following DAG:\n\n![dag](https://imgur.com/xMIOe00.png)\n\nYou can quickly iterate on this DAG by adding more lines, relationships or variables:\n\n```\n// graph2.dg\nR ~ X1 + X2 + X3;\nZ ~ X4;\nZ ~ X2;\nZ ~ X4 + X5; // X4 will only be added once\nE ~ 0.2*Z;\nO ~ 5.0*E + 0.1*Z + R + X6;\n```\n\n![dag2](https://imgur.com/yo5uBQJ.png)\n\nThe order of the formulas don't matter. This was to allow the user to quickly iterate on connections and not have to worry about maintaining the \"DAG\" on paper. \n\nVariables that never show up on the left hand, like `X1`, `X2`, etc. above, are treated as \"noise\" and given random values. \n\n\nUsage\n----------\n\n### Graphing and Plotting\nCreate a Dog program and save it with a `.dg` extension, can run the following to graph it:\n\n`python -m dog.grapher \u003cfilename.dg\u003e -o \u003coptional_filename_to_save_to\u003e` \n\nor to save to a output image:\n\n`python -m dog.grapher \u003cfilename.dg\u003e -o \u003coptional_filename_to_save_to\u003e --no-show` \n\n### Evaluation\n`python -m dog.evaluate \u003cfilename\u003e \u003cformula_for_regression\u003e`\n\nex:\n`python -m dog.evaluate example/test_dag.dg \"O ~ E + Z + R;\"`\n\n\nFuture\n--------\n- Implement sample size configs\n- Introduce non-linear relationships\n- Introduce different noise","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcamdavidsonpilon%2Fdog","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcamdavidsonpilon%2Fdog","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcamdavidsonpilon%2Fdog/lists"}