8000 GitHub - amazon-science/azcausal: Causal Inference in Python
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

amazon-science/azcausal

{"props":{"initialPayload":{"allShortcutsEnabled":false,"path":"/","repo":{"id":650218147,"defaultBranch":"main","name":"azcausal","ownerLogin":"amazon-science","currentUserCanPush":false,"isFork":false,"isEmpty":false,"createdAt":"2023-06-06T15:40:48.000Z","ownerAvatar":"https://avatars.githubusercontent.com/u/70298811?v=4","public":true,"private":false,"isOrgOwned":true},"currentUser":null,"refInfo":{"name":"main","listCacheKey":"v0:1732233635.0","canEdit":false,"refType":"branch","currentOid":"840e539c6b3b22c650f38bf46cbc314ec1235241"},"tree":{"items":[{"name":".github/workflows","path":".github/workflows","contentType":"directory","hasSimplifiedPath":true},{"name":"aws","path":"aws","contentType":"directory"},{"name":"azcausal","path":"azcausal","contentType":"directory"},{"name":"docs","path":"docs","contentType":"directory"},{"name":"examples","path":"examples","contentType":"directory"},{"name":"requirements","path":"requirements","contentType":"directory"},{"name":"tests","path":"tests","contentType":"directory"},{"name":".gitignore","path":".gitignore","contentType":"file"},{"name":".pre-commit-config.yaml","path":".pre-commit-config.yaml","contentType":"file"},{"name":"CODE_OF_CONDUCT.md","path":"CODE_OF_CONDUCT.md","contentType":"file"},{"name":"CONTRIBUTING.md","path":"CONTRIBUTING.md","contentType":"file"},{"name":"LICENSE","path":"LICENSE","contentType":"file"},{"name":"MANIFEST.in","path":"MANIFEST.in","contentType":"file"},{"name":"NOTICE","path":"NOTICE","contentType":"file"},{"name":"README.rst","path":"README.rst","contentType":"file"},{"name":"setup.py","path":"setup.py","contentType":"file"}],"templateDirectorySuggestionUrl":null,"readme":null,"totalCount":16,"showBranchInfobar":false},"fileTree":null,"fileTreeProcessingTime":null,"foldersToFetch":[],"treeExpanded":false,"symbolsExpanded":false,"isOverview":true,"overview":{"banners":{"shouldRecommendReadme":false,"isPersonalRepo":false,"showUseActionBanner":false,"actionSlug":null,"actionId":null,"showProtectBranchBanner":false,"publishBannersInfo":{"dismissActionNoticePath":"/settings/dismiss-notice/publish_action_from_repo","releasePath":"/amazon-science/azcausal/releases/new?marketplace=true","showPublishActionBanner":false},"interactionLimitBanner":null,"showInvitationBanner":false,"inviterName":null,"actionsMigrationBannerInfo":{"releaseTags":[],"showImmutableActionsMigrationBanner":false,"initialMigrationStatus":null}},"codeButton":{"contactPath":"/contact","isEnterprise":false,"local":{"protocolInfo":{"httpAvailable":true,"sshAvailable":null,"httpUrl":"https://github.com/amazon-science/azcausal.git","showCloneWarning":null,"sshUrl":null,"sshCertificatesRequired":null,"sshCertificatesAvailable":null,"ghCliUrl":"gh repo clone amazon-science/azcausal","defaultProtocol":"http","newSshKeyUrl":"/settings/ssh/new","setProtocolPath":"/users/set_protocol"},"platformInfo":{"cloneUrl":"https://desktop.github.com","showVisualStudioCloneButton":false,"visualStudioCloneUrl":"https://windows.github.com","showXcodeCloneButton":false,"xcodeCloneUrl":"xcode://clone?repo=https%3A%2F%2Fgithub.com%2Famazon-science%2Fazcausal","zipballUrl":"/amazon-science/azcausal/archive/refs/heads/main.zip"}},"newCodespacePath":"/codespaces/new?hide_repo_select=true\u0026repo=650218147"},"popovers":{"rename":null,"renamedParentRepo":null},"commitCount":"60","overviewFiles":[{"displayName":"README.rst","repoName":"azcausal","refName":"main","path":"README.rst","preferredFileType":"readme","tabName":"README","richText":"\u003carticle class=\"markdown-body entry-content container-lg\" itemprop=\"text\"\u003e\u003cdiv class=\"markdown-heading\" dir=\"auto\"\u003e\u003ch1 tabindex=\"-1\" class=\"heading-element\" dir=\"auto\"\u003eazcausal: Causal Inference in Python\u003c/h1\u003e\u003ca id=\"user-content-azcausal-causal-inference-in-python\" class=\"anchor\" aria-label=\"Permalink: azcausal: Causal Inference in Python\" href=\"#azcausal-causal-inference-in-python\"\u003e\u003csvg class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"\u003e\u003cpath d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"\u003e\u003c/path\u003e\u003c/svg\u003e\u003c/a\u003e\u003c/div\u003e\n\u003cp dir=\"auto\"\u003eCausal inference is an important component of the experiment evaluation. We highly recommend to have a look at the open-source\nbook: \u003ca href=\"https://matheusfacure.github.io/python-causality-handbook/landing-page.html\" rel=\"nofollow\"\u003eCausal Inference for The Brave and True\u003c/a\u003e\u003c/p\u003e\n\u003cp dir=\"auto\"\u003ePlease find the software documentation here: \u003ca href=\"https://amazon-science.github.io/azcausal/latest/\" rel=\"nofollow\"\u003ehttps://amazon-science.github.io/azcausal/latest/\u003c/a\u003e\u003c/p\u003e\n\u003cp dir=\"auto\"\u003eCurrently, azcausal provides two well-known and widely used causal inference methods: Difference-in-Difference (DID) and\nSynthetic Difference-in-Difference (SDID). Moreover, error estimates via Placebo, Boostrap, or JackKnife are available.\u003c/p\u003e\n\u003ca name=\"user-content-id1\"\u003e\u003c/a\u003e\n\u003cdiv class=\"markdown-heading\" dir=\"auto\"\u003e\u003ch2 tabindex=\"-1\" class=\"heading-element\" dir=\"auto\"\u003eInstallation\u003c/h2\u003e\u003ca id=\"user-content-installation\" class=\"anchor\" aria-label=\"Permalink: Installation\" href=\"#installation\"\u003e\u003csvg class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"\u003e\u003cpath d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"\u003e\u003c/path\u003e\u003c/svg\u003e\u003c/a\u003e\u003c/div\u003e\n\u003cp dir=\"auto\"\u003eTo install the current release, please execute:\u003c/p\u003e\n\u003cdiv class=\"highlight highlight-source-shell notranslate position-relative overflow-auto\" dir=\"auto\" data-snippet-clipboard-copy-content=\"pip install git+https://github.com/amazon-science/azcausal.git\"\u003e\u003cpre\u003epip install git+https://github.com/amazon-science/azcausal.git\u003c/pre\u003e\u003c/div\u003e\n\u003ca name=\"user-content-id2\"\u003e\u003c/a\u003e\n\u003cdiv class=\"markdown-heading\" dir=\"auto\"\u003e\u003ch2 tabindex=\"-1\" class=\"heading-element\" dir=\"auto\"\u003eUsage\u003c/h2\u003e\u003ca id=\"user-content-usage\" class=\"anchor\" aria-label=\"Permalink: Usage\" href=\"#usage\"\u003e\u003csvg class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"\u003e\u003cpath d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"\u003e\u003c/path\u003e\u003c/svg\u003e\u003c/a\u003e\u003c/div\u003e\n\u003cdiv class=\"highlight highlight-source-python notranslate position-relative overflow-auto\" dir=\"auto\" data-snippet-clipboard-copy-content=\"from azcausal.core.error import JackKnife\nfrom azcausal.core.panel import CausalPanel\nfrom azcausal.data import CaliforniaProp99\nfrom azcausal.estimators.panel.sdid import SDID\nfrom azcausal.util import to_panels\n\n\n# load an example data set with the columns Year, State, PacksPerCapita, treated.\ndf = CaliforniaProp99().df()\n\n# create the panel data from the frame and define the causal types\ndata = to_panels(df, 'Year', 'State', ['PacksPerCapita', 'treated'])\nctypes = dict(outcome='PacksPerCapita', time='Year', unit='State', intervention='treated')\n\n# initialize the panel\npanel = CausalPanel(data).setup(**ctypes)\n\n# initialize an estimator object, here synthetic difference in difference (sdid)\nestimator = SDID()\n\n# run the estimator\nresult = estimator.fit(panel)\n\n# run the error validation method\nestimator.error(result, JackKnife())\n\n# plot the results\nestimator.plot(result)\n\n# print out information about the estimate\nprint(result.summary(title=\u0026quot;CaliforniaProp99\u0026quot;))\"\u003e\u003cpre\u003e\u003cspan class=\"pl-k\"\u003efrom\u003c/span\u003e \u003cspan class=\"pl-s1\"\u003eazcausal\u003c/span\u003e.\u003cspan class=\"pl-s1\"\u003ecore\u003c/span\u003e.\u003cspan class=\"pl-s1\"\u003eerror\u003c/span\u003e \u003cspan class=\"pl-k\"\u003eimport\u003c/span\u003e \u003cspan class=\"pl-v\"\u003eJackKnife\u003c/span\u003e\n\u003cspan class=\"pl-k\"\u003efrom\u003c/span\u003e \u003cspan class=\"pl-s1\"\u003eazcausal\u003c/span\u003e.\u003cspan class=\"pl-s1\"\u003ecore\u003c/span\u003e.\u003cspan class=\"pl-s1\"\u003epanel\u003c/span\u003e \u003cspan class=\"pl-k\"\u003eimport\u003c/span\u003e \u003cspan class=\"pl-v\"\u003eCausalPanel\u003c/span\u003e\n\u003cspan class=\"pl-k\"\u003efrom\u003c/span\u003e \u003cspan class=\"pl-s1\"\u003eazcausal\u003c/span\u003e.\u003cspan class=\"pl-s1\"\u003edata\u003c/span\u003e \u003cspan class=\"pl-k\"\u003eimport\u003c/span\u003e \u003cspan class=\"pl-v\"\u003eCaliforniaProp99\u003c/span\u003e\n\u003cspan class=\"pl-k\"\u003efrom\u003c/span\u003e \u003cspan class=\"pl-s1\"\u003eazcausal\u003c/span\u003e.\u003cspan class=\"pl-s1\"\u003eestimators\u003c/span\u003e.\u003cspan class=\"pl-s1\"\u003epanel\u003c/span\u003e.\u003cspan class=\"pl-s1\"\u003esdid\u003c/span\u003e \u003cspan class=\"pl-k\"\u003eimport\u003c/span\u003e \u003cspan class=\"pl-c1\"\u003eSDID\u003c/span\u003e\n\u003cspan class=\"pl-k\"\u003efrom\u003c/span\u003e \u003cspan class=\"pl-s1\"\u003eazcausal\u003c/span\u003e.\u003cspan class=\"pl-s1\"\u003eutil\u003c/span\u003e \u003cspan class=\"pl-k\"\u003eimport\u003c/span\u003e \u003cspan class=\"pl-s1\"\u003eto_panels\u003c/span\u003e\n\n\n\u003cspan class=\"pl-c\"\u003e# load an example data set with the columns Year, State, PacksPerCapita, treated.\u003c/span\u003e\n\u003cspan class=\"pl-s1\"\u003edf\u003c/span\u003e \u003cspan class=\"pl-c1\"\u003e=\u003c/span\u003e \u003cspan class=\"pl-en\"\u003eCaliforniaProp99\u003c/span\u003e().\u003cspan class=\"pl-c1\"\u003edf\u003c/span\u003e()\n\n\u003cspan class=\"pl-c\"\u003e# create the panel data from the frame and define the causal types\u003c/span\u003e\n\u003cspan class=\"pl-s1\"\u003edata\u003c/span\u003e \u003cspan class=\"pl-c1\"\u003e=\u003c/span\u003e \u003cspan class=\"pl-en\"\u003eto_panels\u003c/span\u003e(\u003cspan class=\"pl-s1\"\u003edf\u003c/span\u003e, \u003cspan class=\"pl-s\"\u003e'Year'\u003c/span\u003e, \u003cspan class=\"pl-s\"\u003e'State'\u003c/span\u003e, [\u003cspan class=\"pl-s\"\u003e'PacksPerCapita'\u003c/span\u003e, \u003cspan class=\"pl-s\"\u003e'treated'\u003c/span\u003e])\n\u003cspan class=\"pl-s1\"\u003ectypes\u003c/span\u003e \u003cspan class=\"pl-c1\"\u003e=\u003c/span\u003e \u003cspan class=\"pl-en\"\u003edict\u003c/span\u003e(\u003cspan class=\"pl-s1\"\u003eoutcome\u003c/span\u003e\u003cspan class=\"pl-c1\"\u003e=\u003c/span\u003e\u003cspan class=\"pl-s\"\u003e'PacksPerCapita'\u003c/span\u003e, \u003cspan class=\"pl-s1\"\u003etime\u003c/span\u003e\u003cspan class=\"pl-c1\"\u003e=\u003c/span\u003e\u003cspan class=\"pl-s\"\u003e'Year'\u003c/span\u003e, \u003cspan class=\"pl-s1\"\u003eunit\u003c/span\u003e\u003cspan class=\"pl-c1\"\u003e=\u003c/span\u003e\u003cspan class=\"pl-s\"\u003e'State'\u003c/span\u003e, \u003cspan class=\"pl-s1\"\u003eintervention\u003c/span\u003e\u003cspan class=\"pl-c1\"\u003e=\u003c/span\u003e\u003cspan class=\"pl-s\"\u003e'treated'\u003c/span\u003e)\n\n\u003cspan class=\"pl-c\"\u003e# initialize the panel\u003c/span\u003e\n\u003cspan class=\"pl-s1\"\u003epanel\u003c/span\u003e \u003cspan class=\"pl-c1\"\u003e=\u003c/span\u003e \u003cspan class=\"pl-en\"\u003eCausalPanel\u003c/span\u003e(\u003cspan class=\"pl-s1\"\u003edata\u003c/span\u003e).\u003cspan class=\"pl-c1\"\u003esetup\u003c/span\u003e(\u003cspan class=\"pl-c1\"\u003e**\u003c/span\u003e\u003cspan class=\"pl-s1\"\u003ectypes\u003c/span\u003e)\n\n\u003cspan class=\"pl-c\"\u003e# initialize an estimator object, here synthetic difference in difference (sdid)\u003c/span\u003e\n\u003cspan class=\"pl-s1\"\u003eestimator\u003c/span\u003e \u003cspan class=\"pl-c1\"\u003e=\u003c/span\u003e \u003cspan class=\"pl-en\"\u003eSDID\u003c/span\u003e()\n\n\u003cspan class=\"pl-c\"\u003e# run the estimator\u003c/span\u003e\n\u003cspan class=\"pl-s1\"\u003eresult\u003c/span\u003e \u003cspan class=\"pl-c1\"\u003e=\u003c/span\u003e \u003cspan class=\"pl-s1\"\u003eestimator\u003c/span\u003e.\u003cspan class=\"pl-c1\"\u003efit\u003c/span\u003e(\u003cspan class=\"pl-s1\"\u003epanel\u003c/span\u003e)\n\n\u003cspan class=\"pl-c\"\u003e# run the error validation method\u003c/span\u003e\n\u003cspan class=\"pl-s1\"\u003eestimator\u003c/span\u003e.\u003cspan class=\"pl-c1\"\u003eerror\u003c/span\u003e(\u003cspan class=\"pl-s1\"\u003eresult\u003c/span\u003e, \u003cspan class=\"pl-en\"\u003eJackKnife\u003c/span\u003e())\n\n\u003cspan class=\"pl-c\"\u003e# plot the results\u003c/span\u003e\n\u003cspan class=\"pl-s1\"\u003eestimator\u003c/span\u003e.\u003cspan class=\"pl-c1\"\u003eplot\u003c/span\u003e(\u003cspan class=\"pl-s1\"\u003eresult\u003c/span\u003e)\n\n\u003cspan class=\"pl-c\"\u003e# print out information about the estimate\u003c/span\u003e\n\u003cspan class=\"pl-en\"\u003eprint\u003c/span\u003e(\u003cspan class=\"pl-s1\"\u003eresult\u003c/span\u003e.\u003cspan class=\"pl-c1\"\u003esummary\u003c/span\u003e(\u003cspan class=\"pl-s1\"\u003etitle\u003c/span\u003e\u003cspan class=\"pl-c1\"\u003e=\u003c/span\u003e\u003cspan class=\"pl-s\"\u003e\"CaliforniaProp99\"\u003c/span\u003e))\u003c/pre\u003e\u003c/div\u003e\n\u003cdiv class=\"highlight highlight-source-shell notranslate position-relative overflow-auto\" dir=\"auto\" data-snippet-clipboard-copy-content=\"╭──────────────────────────────────────────────────────────────────────────────╮\n| CaliforniaProp99 |\n├──────────────────────────────────────────────────────────────────────────────┤\n| Panel |\n| Time Periods: 31 (19/12) total (pre/post) |\n| Units: 39 (38/1) total (contr/treat) |\n├──────────────────────────────────────────────────────────────────────────────┤\n| ATT |\n| Effect (±SE): -15.60 (±2.9161) |\n| Confidence Interval (95%): [-21.32 , -9.8884] (-) |\n| Observed: 60.35 |\n| Counter Factual: 75.95 |\n├──────────────────────────────────────────────────────────────────────────────┤\n| Percentage |\n| Effect (±SE): -20.54 (±3.8393) |\n| Confidence Interval (95%): [-28.07 , -13.02] (-) |\n| Observed: 79.46 |\n| Counter Factual: 100.00 |\n├──────────────────────────────────────────────────────────────────────────────┤\n| Cumulative |\n| Effect (±SE): -187.25 (±34.99) |\n| Confidence Interval (95%): [-255.83 , -118.66] (-) |\n| Observed: 724.20 |\n| Counter Factual: 911.45 |\n╰──────────────────────────────────────────────────────────────────────────────╯\"\u003e\u003cpre\u003e╭──────────────────────────────────────────────────────────────────────────────╮\n\u003cspan class=\"pl-k\"\u003e|\u003c/span\u003e CaliforniaProp99 \u003cspan class=\"pl-k\"\u003e|\u003c/span\u003e\n├──────────────────────────────────────────────────────────────────────────────┤\n\u003cspan class=\"pl-k\"\u003e|\u003c/span\u003e Panel \u003cspan class=\"pl-k\"\u003e|\u003c/span\u003e\n\u003cspan class=\"pl-k\"\u003e|\u003c/span\u003e Time Periods: 31 (19/12) total (pre/post) \u003cspan class=\"pl-k\"\u003e|\u003c/span\u003e\n\u003cspan class=\"pl-k\"\u003e|\u003c/span\u003e Units: 39 (38/1) total (contr/treat) \u003cspan class=\"pl-k\"\u003e|\u003c/span\u003e\n├──────────────────────────────────────────────────────────────────────────────┤\n\u003cspan class=\"pl-k\"\u003e|\u003c/span\u003e ATT \u003cspan class=\"pl-k\"\u003e|\u003c/span\u003e\n\u003cspan class=\"pl-k\"\u003e|\u003c/span\u003e Effect (±SE): -15.60 (±2.9161) \u003cspan class=\"pl-k\"\u003e|\u003c/span\u003e\n\u003cspan class=\"pl-k\"\u003e|\u003c/span\u003e Confidence Interval (95%): [-21.32 , -9.8884] (-) \u003cspan class=\"pl-k\"\u003e|\u003c/span\u003e\n\u003cspan class=\"pl-k\"\u003e|\u003c/span\u003e Observed: 60.35 \u003cspan class=\"pl-k\"\u003e|\u003c/span\u003e\n\u003cspan class=\"pl-k\"\u003e|\u003c/span\u003e Counter Factual: 75.95 \u003cspan class=\"pl-k\"\u003e|\u003c/span\u003e\n├──────────────────────────────────────────────────────────────────────────────┤\n\u003cspan class=\"pl-k\"\u003e|\u003c/span\u003e Percentage \u003cspan class=\"pl-k\"\u003e|\u003c/span\u003e\n\u003cspan class=\"pl-k\"\u003e|\u003c/span\u003e Effect (±SE): -20.54 (±3.8393) \u003cspan class=\"pl-k\"\u003e|\u003c/span\u003e\n\u003cspan class=\"pl-k\"\u003e|\u003c/span\u003e Confidence Interval (95%): [-28.07 , -13.02] (-) \u003cspan class=\"pl-k\"\u003e|\u003c/span\u003e\n\u003cspan class=\"pl-k\"\u003e|\u003c/span\u003e Observed: 79.46 \u003cspan class=\"pl-k\"\u003e|\u003c/span\u003e\n\u003cspan class=\"pl-k\"\u003e|\u003c/span\u003e Counter Factual: 100.00 \u003cspan class=\"pl-k\"\u003e|\u003c/span\u003e\n├──────────────────────────────────────────────────────────────────────────────┤\n\u003cspan class=\"pl-k\"\u003e|\u003c/span\u003e Cumulative \u003cspan class=\"pl-k\"\u003e|\u003c/span\u003e\n\u003cspan class=\"pl-k\"\u003e|\u003c/span\u003e Effect (±SE): -187.25 (±34.99) \u003cspan class=\"pl-k\"\u003e|\u003c/span\u003e\n\u003cspan class=\"pl-k\"\u003e|\u003c/span\u003e Confidence Interval (95%): [-255.83 , -118.66] (-) \u003cspan class=\"pl-k\"\u003e|\u003c/span\u003e\n\u003cspan class=\"pl-k\"\u003e|\u003c/span\u003e Observed: 724.20 \u003cspan class=\"pl-k\"\u003e|\u003c/span\u003e\n\u003cspan class=\"pl-k\"\u003e|\u003c/span\u003e Counter Factual: 911.45 \u003cspan class=\"pl-k\"\u003e|\u003c/span\u003e\n╰──────────────────────────────────────────────────────────────────────────────╯\u003c/pre\u003e\u003c/div\u003e\n\u003cp dir=\"auto\"\u003e\u003ca target=\"_blank\" rel=\"noopener noreferrer\" href=\"/amazon-science/azcausal/blob/main/docs/source/images/sdid.png\"\u003e\u003cimg alt=\"docs/source/images/sdid.png\" src=\"/amazon-science/azcausal/raw/main/docs/source/images/sdid.png\" style=\"max-width: 100%;\"\u003e\u003c/a\u003e\u003c/p\u003e\n\u003ca name=\"user-content-id3\"\u003e\u003c/a\u003e\n\u003cdiv class=\"markdown-heading\" dir=\"auto\"\u003e\u003ch2 tabindex=\"-1\" class=\"heading-element\" dir=\"auto\"\u003eEstimators\u003c/h2\u003e\u003ca id=\"user-content-estimators\" class=\"anchor\" aria-label=\"Permalink: Estimators\" href=\"#estimators\"\u003e\u003csvg class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"\u003e\u003cpath d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"\u003e\u003c/path\u003e\u003c/svg\u003e\u003c/a\u003e\u003c/div\u003e\n\u003cul dir=\"auto\"\u003e\n\u003cli\u003e\u003cstrong\u003eDifference-in-Difference (DID):\u003c/strong\u003e Simple implementation of the well-known Difference-in-Difference estimator.\u003c/li\u003e\n\u003cli\u003e\u003cstrong\u003eSynthetic Difference-in-Difference (SDID):\u003c/strong\u003e Arkhangelsky, Dmitry Athey, Susan Hirshberg, David A. Imbens, Guido W. Wager, Stefan Synthetic Difference-in-Differences American Economic Review 111 12 4088-4118 2021 10.1257/aer.20190159 \u003ca href=\"https://www.aeaweb.org/articles?id=10.1257/aer.20190159\" rel=\"nofollow\"\u003ehttps://www.aeaweb.org/articles?id=10.1257/aer.20190159\u003c/a\u003e. Implementation based on \u003ca href=\"https://synth-inference.github.io/synthdid/\" rel=\"nofollow\"\u003ehttps://synth-inference.github.io/synthdid/\u003c/a\u003e\u003c/li\u003e\n\u003c/ul\u003e\n\u003ca name=\"user-content-id4\"\u003e\u003c/a\u003e\n\u003cdiv class=\"markdown-heading\" dir=\"auto\"\u003e\u003ch2 tabindex=\"-1\" class=\"heading-element\" dir=\"auto\"\u003eContact\u003c/h2\u003e\u003ca id=\"user-content-contact\" class=\"anchor\" aria-label=\"Permalink: Contact\" href=\"#contact\"\u003e\u003csvg class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"\u003e\u003cpath d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"\u003e\u003c/path\u003e\u003c/svg\u003e\u003c/a\u003e\u003c/div\u003e\n\u003cp dir=\"auto\"\u003eFeel free to contact me if you have any questions:\u003c/p\u003e\n\u003cdiv dir=\"auto\"\u003e\n\u003cdiv dir=\"auto\"\u003e\u003ca href=\"http://julianblank.com\" rel=\"nofollow\"\u003eJulian Blank\u003c/a\u003e (blankjul [at] amazon.com)\u003c/div\u003e\n\u003cdiv dir=\"auto\"\u003eAmazon.com\u003c/div\u003e\n\u003cdiv dir=\"auto\"\u003eApplied Scientist, Amazon\u003c/div\u003e\n\u003cdiv dir=\"auto\"\u003e410 Terry Ave N, Seattle 98109, WA.\u003c/div\u003e\n\u003c/div\u003e\n\n\u003c/article\u003e","loaded":true,"timedOut":false,"errorMessage":null,"headerInfo":{"toc":[{"level":1,"text":"azcausal: Causal Inference in Python","anchor":"azcausal-causal-inference-in-python","htmlText":"azcausal: Causal Inference in Python"},{"level":2,"text":"Installation","anchor":"installation","htmlText":"Installation"},{"level":2,"text":"Usage","anchor":"usage","htmlText":"Usage"},{"level":2,"text":"Estimators","anchor":"estimators","htmlText":"Estimators"},{"level":2,"text":"Contact","anchor":"contact","htmlText":"Contact"}],"siteNavLoginPath":"/login?return_to=https%3A%2F%2Fgithub.com%2Famazon-science%2Fazcausal"}},{"displayName":"CODE_OF_CONDUCT.md","repoName":"azcausal","refName":"main","path":"CODE_OF_CONDUCT.md","preferredFileType":"code_of_conduct","tabName":"Code of conduct","richText":null,"loaded":false,"timedOut":false,"errorMessage":null,"headerInfo":{"toc":null,"siteNavLoginPath":"/login?return_to=https%3A%2F%2Fgithub.com%2Famazon-science%2Fazcausal"}},{"displayName":"LICENSE","repoName":"azcausal","refName":"main","path":"LICENSE","preferredFileType":"license","tabName":"Apache-2.0","richText":null,"loaded":false,"timedOut":false,"errorMessage":null,"headerInfo":{"toc":null,"siteNavLoginPath":"/login?return_to=https%3A%2F%2Fgithub.com%2Famazon-science%2Fazcausal"}},{"displayName":"SECURITY.md","repoName":".github","refName":"master","path":"SECURITY.md","preferredFileType":"security","tabName":"Security","richText":null,"loaded":false,"timedOut":false,"errorMessage":null,"headerInfo":{"toc":null,"siteNavLoginPath":"/login?return_to=https%3A%2F%2Fgithub.com%2Famazon-science%2Fazcausal"}}],"overviewFilesProcessingTime":0}},"appPayload":{"helpUrl":"https://docs.github.com","findFileWorkerPath":"/assets-cdn/worker/find-file-worker-7d7eb7c71814.js","findInFileWorkerPath":"/assets-cdn/worker/find-in-file-worker-708ec8ade250.js","githubDevUrl":null,"enabled_features":{"copilot_workspace":null,"code_nav_ui_events":false,"react_blob_overlay":false,"accessible_code_button":true,"github_models_repo_integration":false}}}}

azcausal: Causal Inference in Python

Causal inference is an important component of the experiment evaluation. We highly recommend to have a look at the open-source book: Causal Inference for The Brave and True

Please find the software documentation here: https://amazon-science.github.io/azcausal/latest/

Currently, azcausal provides two well-known and widely used causal inference methods: Difference-in-Difference (DID) and Synthetic Difference-in-Difference (SDID). Moreover, error estimates via Placebo, Boostrap, or JackKnife are available.

Installation

To install the current release, please execute:

pip install git+https://github.com/amazon-science/azcausal.git

Usage

from azcausal.core.error import JackKnife
from azcausal.core.panel import CausalPanel
from azcausal.data import CaliforniaProp99
from azcausal.estimators.panel.sdid import SDID
from azcausal.util import to_panels


# load an example data set with the columns Year, State, PacksPerCapita, treated.
df = CaliforniaProp99().df()

# create the panel data from the frame and define the causal types
data = to_panels(df, 'Year', 'State', ['PacksPerCapita', 'treated'])
ctypes = dict(outcome='PacksPerCapita', time='Year', unit='State', intervention='treated')

# initialize the panel
panel = CausalPanel(data).setup(**ctypes)

# initialize an estimator object, here synthetic difference in difference (sdid)
estimator = SDID()

# run the estimator
result = estimator.fit(panel)

# run the error validation method
estimator.error(result, JackKnife())

# plot the results
estimator.plot(result)

# print out information about the estimate
print(result.summary(title="CaliforniaProp99"))
╭──────────────────────────────────────────────────────────────────────────────╮
|                               CaliforniaProp99                               |
├──────────────────────────────────────────────────────────────────────────────┤
|                                    Panel                                     |
|  Time Periods: 31 (19/12)                                  total (pre/post)  |
|  Units: 39 (38/1)                                       total (contr/treat)  |
├──────────────────────────────────────────────────────────────────────────────┤
|                                     ATT                                      |
|  Effect (±SE): -15.60 (±2.9161)                                              |
|  Confidence Interval (95%): [-21.32 , -9.8884]                          (-)  |
|  Observed: 60.35                                                             |
|  Counter Factual: 75.95                                                      |
├──────────────────────────────────────────────────────────────────────────────┤
|                                  Percentage                                  |
|  Effect (±SE): -20.54 (±3.8393)                                              |
|  Confidence Interval (95%): [-28.07 , -13.02]                           (-)  |
|  Observed: 79.46                                                             |
|  Counter Factual: 100.00                                                     |
├──────────────────────────────────────────────────────────────────────────────┤
|                                  Cumulative                                  |
|  Effect (±SE): -187.25 (±34.99)                                              |
|  Confidence Interval (95%): [-255.83 , -118.66]                         (-)  |
|  Observed: 724.20                                                            |
|  Counter Factual: 911.45                                                     |
╰──────────────────────────────────────────────────────────────────────────────╯

docs/source/images/sdid.png

Estimators

Contact

Feel free to contact me if you have any questions:

Julian Blank (blankjul [at] amazon.com)
Amazon.com
Applied Scientist, Amazon
410 Terry Ave N, Seattle 98109, WA.
0