{"id":32203602,"url":"https://github.com/flyaflya/causact","last_synced_at":"2026-02-23T14:02:34.861Z","repository":{"id":38822364,"uuid":"130230186","full_name":"flyaflya/causact","owner":"flyaflya","description":"causact:  R package to accelerate computational Bayesian inference workflows in R through interactive visualization of models and their output.","archived":false,"fork":false,"pushed_at":"2025-09-12T19:31:12.000Z","size":13557,"stargazers_count":48,"open_issues_count":10,"forks_count":12,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-10-10T17:08:41.098Z","etag":null,"topics":["bayesian-inference","dags","posterior-probability","probabilistic-graphical-models","probabilistic-programming","rstats-package"],"latest_commit_sha":null,"homepage":"http://causact.com","language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/flyaflya.png","metadata":{"files":{"readme":"README.Rmd","changelog":"NEWS.md","contributing":".github/contributing.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2018-04-19T14:42:45.000Z","updated_at":"2025-09-12T19:31:16.000Z","dependencies_parsed_at":"2022-08-27T03:06:49.821Z","dependency_job_id":"56028372-4e6e-4d8d-941c-2e4d55667c32","html_url":"https://github.com/flyaflya/causact","commit_stats":{"total_commits":343,"total_committers":7,"mean_commits":49.0,"dds":"0.24781341107871724","last_synced_commit":"8e8928dc9a1935c87b8167067df4d885c8414f2b"},"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"purl":"pkg:github/flyaflya/causact","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flyaflya%2Fcausact","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flyaflya%2Fcausact/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flyaflya%2Fcausact/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flyaflya%2Fcausact/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/flyaflya","download_url":"https://codeload.github.com/flyaflya/causact/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flyaflya%2Fcausact/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279006610,"owners_count":26084148,"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-11T02:00:06.511Z","response_time":55,"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":["bayesian-inference","dags","posterior-probability","probabilistic-graphical-models","probabilistic-programming","rstats-package"],"created_at":"2025-10-22T04:43:30.280Z","updated_at":"2025-10-22T04:43:32.855Z","avatar_url":"https://github.com/flyaflya.png","language":"R","readme":"---\noutput: github_document\neditor_options: \n  markdown: \n    wrap: 72\n---\n\n\u003c!-- README.md is generated from README.Rmd. Please edit that file --\u003e\n\n```{r, echo=FALSE}\nknitr::opts_chunk$set(\n  collapse = TRUE,\n  comment = \"#\u003e\",\n  fig.path = \"man/figures/\",\n  dpi = 600,\n  fig.asp = 0.618,\n  fig.width = 6\n)\n```\n\n\u003c!-- badges: start --\u003e\n\n[![R-CMD-check](https://github.com/flyaflya/causact/workflows/R-CMD-check/badge.svg)](https://github.com/flyaflya/causact/actions)\n[![CRAN\nstatus](https://www.r-pkg.org/badges/version/causact)](https://cran.r-project.org/package=causact)\n[![Codecov test\ncoverage](https://codecov.io/gh/flyaflya/causact/branch/master/graph/badge.svg)](https://app.codecov.io/gh/flyaflya/causact?branch=master)\n[![Lifecycle:Maturing](https://img.shields.io/badge/Lifecycle-Maturing-007EC6)](https://img.shields.io/badge/Lifecycle-Maturing-007EC6)\n[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.6949489.svg)](https://doi.org/10.5281/zenodo.6949489)\n[![DOI](https://joss.theoj.org/papers/10.21105/joss.04415/status.svg)](https://doi.org/10.21105/joss.04415)\n\n\u003c!-- badges: end --\u003e\n\n# causact\n\n*Accelerate computational Bayesian inference workflows* in R through\ninteractive modelling, visualization, and inference. The package\nleverages directed acyclic graphs (DAGs) to create a unified language\nlanguage for business stakeholders, statisticians, and programmers. Due\nto its visual nature and simple model construction, `causact` serves as\na great entry-point for newcomers to computational Bayesian inference.\n\n\u003e The `causact` package offers robust support for both foundational and\n\u003e advanced Bayesian models. While introductory models are well-covered,\n\u003e the utilization of multi-variate distributions such as multi-variate\n\u003e normal, multi-nomial, or dirichlet distributions, may not work as\n\u003e expected. There are ongoing enhancements in the pipeline to facilitate\n\u003e construction of these more intricate models.\n\n```{r demoGif, out.width = \"40%\", echo = FALSE, fig.align = \"center\"}\nknitr::include_graphics(\"man/figures/introScreenshot.png\")\n```\n\nWhile proficiency in R is the only requirement for users of this\npackage, it also functions as a introductory probabilistic programming\nlanguage, seamlessly incorporating the `numpyro` Python package to\nfacilitate Bayesian inference without the need to learn any syntax\noutside of the package or R. Furthermore, the package streamlines the\nprocess of indexing categorical variables, which often presents a\ncomplex syntax hurdle for those new to computational Bayesian methods.\n\nFor enhanced learning, the `causact` package for Bayesian inference is\nfeatured in `A Business Analyst's Introduction to Business Analytics`\navailable at \u003chttps://www.causact.com/\u003e.\n\n\u003e Feedback and encouragement is appreciated via github issues.\n\n## Installation Guide\n\nTo install the `causact` package, follow the steps outlined below:\n\n### CRAN Release Version (Recommended)\n\nFor the current stable release, which is tailored to integrate with\nPython's `numpyro` package, employ the following command:\n\n``` r\ninstall.packages(\"causact\")\n```\n\nThen, see [Essential Dependencies] if you want to be able to automate\nsampling using the `numpyro` package.\n\n### Development Release\n\nIf you want the most recent development version (not recommended),\nexecute the following:\n\n``` r\ninstall.packages(\"remotes\")\nremotes::install_github(\"flyaflya/causact\")\n```\n\n### Essential Dependencies\n\nTo harness the full potential of `causact` for DAG visualization and\nBayesian posterior analysis, it's vital to ensure proper integration\nwith the `numpyro` package. Given the Python-based nature of `numpyro`,\na few essential dependencies must be in place. Execute the following\ncommands after installing `causact`:\n\n``` r\nlibrary(causact)\ninstall_causact_deps()\n```\n\nIf prompted, respond with `Y` to any inquiries related to installing miniconda.\n\n\u003e **Note**: If opting for installation on Posit Cloud, temporarily\n\u003e adjust your project's RAM to 4GB during the installation process\n\u003e (remember to APPLY CHANGES). This preemptive measure helps avoid\n\u003e encountering an\n\u003e `Error: Error creating conda environment [exit code 137]`. After\n\u003e installation, feel free to revert the settings to 1GB of RAM.\n\n\u003e **Note**: The September 11, 2023 release of `reticulate` (`v1.32`) has\n\u003e caused an issue which gives a\n\u003e `TypeError: the first argument must be callable` error when using\n\u003e `dag_numpyro()` on windows. If you experience this, install the dev\n\u003e version of `reticulate` by following the below steps:\n\u003e\n\u003e 1)  Install RTOOLS by using installer at:\n\u003e     \u003chttps://cran.r-project.org/bin/windows/Rtools/\u003e\n\u003e\n\u003e 2)  Run this to get the dev version of `reticulate`:\n\n```\n# install DEV version of reticulate\n# install.packages(\"pak\") #uncomment as needed\npak::pak(\"rstudio/reticulate\")\n```\n\n### Retrograde Compatibility (Not Advised)\n\nIn cases where legacy compatibility is paramount and you still rely on\nthe operationality of the `dag_greta()` function, consider installing\n`v0.4.2` of the `causact` package. However, it's essential to emphasize\nthat this approach is **not recommended** for general usage:\n\n``` r\n### EXERCISE CAUTION BEFORE EXECUTING THESE LINES\n### Only proceed if dag_greta() is integral to your existing codebase\ninstall.packages(\"remotes\")\nremotes::install_github(\"flyaflya/causact@v0.4.2\")\n```\n\nYour judicious choice of installation method will ensure a seamless and\neffective integration of the `causact` package into your computational\ntoolkit.\n\n## Usage\n\nExample taken from\n\u003chttps://www.causact.com/graphical-models-tell-joint-distribution-stories.html#graphical-models-tell-joint-distribution-stories\u003e\nwith the packages `dag_foo()` functions further described here:\n\n\u003chttps://www.causact.com/causact-quick-inference-with-generative-dags.html#causact-quick-inference-with-generative-dags\u003e\n\n### Create beautiful model visualizations.\n\n```{r defineGraph, results = \"hide\", echo = FALSE}\nlibrary(causact)\ngraph = dag_create() %\u003e%\n  dag_node(descr = \"Get Card\",label = \"y\",\n           rhs = bernoulli(theta),\n           data = carModelDF$getCard) %\u003e%\n  dag_node(descr = \"Card Probability\",label = \"theta\",\n           rhs = beta(2,2),\n           child = \"y\") %\u003e%\n  dag_plate(descr = \"Car Model\", label = \"x\",  \n            data = carModelDF$carModel,  \n            nodeLabels = \"theta\",  \n            addDataNode = TRUE)\n```\n\n```{r cardP, eval = FALSE}\nlibrary(causact)\ngraph = dag_create() %\u003e%\n  dag_node(descr = \"Get Card\", label = \"y\",\n           rhs = bernoulli(theta),\n           data = carModelDF$getCard) %\u003e%\n  dag_node(descr = \"Card Probability\", label = \"theta\",\n           rhs = beta(2,2),\n           child = \"y\") %\u003e%\n  dag_plate(descr = \"Car Model\", label = \"x\",  \n            data = carModelDF$carModel,  \n            nodeLabels = \"theta\",  \n            addDataNode = TRUE)  \ngraph %\u003e% dag_render()\n```\n\n```{r cardPlatePlot, out.width = \"60%\", echo = FALSE}\nknitr::include_graphics(\"man/figures/cardPlot.png\")\n```\n\n### Hide model complexity, as appropriate, from domain experts and other less statistically minded stakeholders.\n\n```{r cardPSL, eval = FALSE}\ngraph %\u003e% dag_render(shortLabel = TRUE)\n```\n\n```{r cardPlateSLPlot, out.width = \"50%\", echo = FALSE}\nknitr::include_graphics(\"man/figures/cardPlotShortLabel.png\")\n```\n\n### Get posterior while automatically running the underlying `numpyro` code\n\n```{r greta, warning = FALSE, message = FALSE}\ndrawsDF = graph %\u003e% dag_numpyro()\ndrawsDF  ### see top of data frame\n```\n\n\u003e **Note**: if you have used older versions of causact, please know that\n\u003e dag_numpyro() is a drop-in replacement for dag_greta().\n\n### Get quick view of posterior distribution\n\n```{r gretaPost, fig.cap = \"Credible interval plots.\", fig.width = 6.5, fig.height = 4, out.width = \"70%\"}\ndrawsDF %\u003e% dagp_plot()\n```\n\n### OPTIONAL: See `numpyro` code without executing it (for debugging or learning)\n\n```{r gretaCode, warning = FALSE, message = TRUE}\nnumpyroCode = graph %\u003e% dag_numpyro(mcmc = FALSE)\n```\n\n## Getting Help and Suggesting Improvements\n\nWhether you encounter a clear bug, have a suggestion for improvement, or\njust have a question, we are thrilled to help you out. In all cases,\nplease file a [GitHub\nissue](https://github.com/flyaflya/causact/issues). If reporting a bug,\nplease include a minimal reproducible example.\n\n## Contributing\n\nWe welcome help turning `causact` into the most intuitive and fastest\nmethod of converting stakeholder narratives about data-generating\nprocesses into actionable insight from posterior distributions. If you\nwant to help us achieve this vision, we welcome your contributions after\nreading the [new contributor\nguide](https://github.com/flyaflya/causact/blob/master/.github/contributing.md).\nPlease note that this project is released with a [Contributor Code of\nConduct](https://github.com/flyaflya/causact/blob/master/CODE_OF_CONDUCT.md).\nBy participating in this project you agree to abide by its terms.\n\n## Further Usage\n\nFor more info, see\n`A Business Analyst's Introduction to Business Analytics` available at\n\u003chttps://www.causact.com\u003e. You can also check out the package's\nvignette: `vignette(\"narrative-to-insight-with-causact\")`. Two\nadditional examples are shown below.\n\n## Prosocial Chimpanzees Example from Statistical Rethinking\n\n\u003e McElreath, Richard. Statistical rethinking: A Bayesian course with\n\u003e examples in R and Stan. Chapman and Hall/CRC, 2018.\n\n```{r chimpsGraph, results =\"hide\", warning = FALSE, message = FALSE}\nlibrary(tidyverse)\nlibrary(causact)\n\n# data object used below, chimpanzeesDF, is built-in to causact package\n\ngraph = dag_create() %\u003e%\n  dag_node(\"Pull Left Handle\",\"L\",\n           rhs = bernoulli(p),\n           data = causact::chimpanzeesDF$pulled_left) %\u003e%\n  dag_node(\"Probability of Pull\", \"p\",\n           rhs = 1 / (1 + exp(-((alpha + gamma + beta)))),\n           child = \"L\") %\u003e%\n  dag_node(\"Actor Intercept\",\"alpha\",\n           rhs = normal(alphaBar, sigma_alpha),\n           child = \"p\") %\u003e%\n  dag_node(\"Block Intercept\",\"gamma\",\n           rhs = normal(0,sigma_gamma),\n           child = \"p\") %\u003e%\n  dag_node(\"Treatment Intercept\",\"beta\",\n           rhs = normal(0,0.5),\n           child = \"p\") %\u003e%\n  dag_node(\"Actor Population Intercept\",\"alphaBar\",\n           rhs = normal(0,1.5),\n           child = \"alpha\") %\u003e%\n  dag_node(\"Actor Variation\",\"sigma_alpha\",\n           rhs = exponential(1),\n           child = \"alpha\") %\u003e%\n  dag_node(\"Block Variation\",\"sigma_gamma\",\n           rhs = exponential(1),\n           child = \"gamma\") %\u003e%\n  dag_plate(\"Observation\",\"i\",\n            nodeLabels = c(\"L\",\"p\")) %\u003e%\n  dag_plate(\"Actor\",\"act\",\n            nodeLabels = c(\"alpha\"),\n            data = chimpanzeesDF$actor,\n            addDataNode = TRUE) %\u003e%\n  dag_plate(\"Block\",\"blk\",\n            nodeLabels = c(\"gamma\"),\n            data = chimpanzeesDF$block,\n            addDataNode = TRUE) %\u003e%\n  dag_plate(\"Treatment\",\"trtmt\",\n            nodeLabels = c(\"beta\"),\n            data = chimpanzeesDF$treatment,\n            addDataNode = TRUE)\n```\n\n### See graph\n\n```{r chimpsGraphRenderCode, eval = FALSE, warning = FALSE, message = FALSE}\ngraph %\u003e% dag_render(width = 2000, height = 800)\n```\n\n```{r chimpsGraphRenderPlot, out.width = \"120%\", echo = FALSE}\nknitr::include_graphics(\"man/figures/chimpStat.png\")\n```\n\n### Communicate with stakeholders for whom the statistics might be distracting\n\n```{r chimpsGraphRenderSL, eval=FALSE, message=FALSE, warning=FALSE}\ngraph %\u003e% dag_render(shortLabel = TRUE)\n```\n\n```{r chimpsGraphRenderPlotSL, out.width = \"100%\", echo = FALSE}\nknitr::include_graphics(\"man/figures/chimpStatSL.png\")\n```\n\n### Compute posterior\n\n```{r chimpsGraphGreta, warning = FALSE, message = FALSE}\ndrawsDF = graph %\u003e% dag_numpyro()\n```\n\n### Visualize posterior\n\n```{r chimpsGraphPost, out.width = \"100%\", fig.width = 9, fig.height = 6, warning = FALSE, message = FALSE}\ndrawsDF %\u003e% dagp_plot()\n```\n\n## Eight Schools Example from Bayesian Data Analysis\n\n\u003e Gelman, Andrew, Hal S. Stern, John B. Carlin, David B. Dunson, Aki\n\u003e Vehtari, and Donald B. Rubin. Bayesian data analysis. Chapman and\n\u003e Hall/CRC, 2013.\n\n```{r eightschoolsGraph, results =\"hide\", warning = FALSE, message = FALSE}\nlibrary(tidyverse)\nlibrary(causact)\n\n# data object used below, schoolDF, is built-in to causact package\n\ngraph = dag_create() %\u003e%\n  dag_node(\"Treatment Effect\",\"y\",\n           rhs = normal(theta, sigma),\n           data = causact::schoolsDF$y) %\u003e%\n  dag_node(\"Std Error of Effect Estimates\",\"sigma\",\n           data = causact::schoolsDF$sigma,\n           child = \"y\") %\u003e%\n  dag_node(\"Exp. Treatment Effect\",\"theta\",\n           child = \"y\",\n           rhs = avgEffect + schoolEffect) %\u003e%\n  dag_node(\"Pop Treatment Effect\",\"avgEffect\",\n           child = \"theta\",\n           rhs = normal(0,30)) %\u003e%\n  dag_node(\"School Level Effects\",\"schoolEffect\",\n           rhs = normal(0,30),\n           child = \"theta\") %\u003e%\n  dag_plate(\"Observation\",\"i\",nodeLabels = c(\"sigma\",\"y\",\"theta\")) %\u003e%\n  dag_plate(\"School Name\",\"school\",\n            nodeLabels = \"schoolEffect\",\n            data = causact::schoolsDF$schoolName,\n            addDataNode = TRUE)\n```\n\n### See graph\n\n```{r eightschoolsGraphRenderCode, eval = FALSE, warning = FALSE, message = FALSE}\ngraph %\u003e% dag_render()\n```\n\n```{r eightschoolsGraphRenderPlot, out.width = \"100%\", echo = FALSE}\nknitr::include_graphics(\"man/figures/eightSchoolStat.png\")\n```\n\n### Compute posterior\n\n```{r eightschoolsGraphGreta, warning = FALSE, message = FALSE}\ndrawsDF = graph %\u003e% dag_numpyro()\n```\n\n### Visualize posterior\n\n```{r eightschoolsGraphPost, out.width = \"100%\", eval = FALSE, fig.width = 9, fig.height = 6, warning = FALSE, message = FALSE}\ndrawsDF %\u003e% dagp_plot()\n```\n\n```{r eightschoolsGraphRenderPost, out.width = \"100%\", echo = FALSE}\nknitr::include_graphics(\"man/figures/eightschoolsGraphPost-1.png\")\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflyaflya%2Fcausact","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fflyaflya%2Fcausact","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflyaflya%2Fcausact/lists"}