{"id":23089251,"url":"https://github.com/nhejazi/medoutcon","last_synced_at":"2025-08-16T08:31:44.363Z","repository":{"id":45315476,"uuid":"179904082","full_name":"nhejazi/medoutcon","owner":"nhejazi","description":":package: R/medoutcon: Efficient Causal Mediation Analysis with Natural and Interventional Direct/Indirect Effects","archived":false,"fork":false,"pushed_at":"2024-03-18T15:08:00.000Z","size":844,"stargazers_count":11,"open_issues_count":2,"forks_count":4,"subscribers_count":8,"default_branch":"master","last_synced_at":"2024-04-15T09:12:44.621Z","etag":null,"topics":["causal-inference","causal-machine-learning","inverse-probability-weights","machine-learning","mediation-analysis","r","r-package","stochastic-interventions","targeted-learning","treatment-effects"],"latest_commit_sha":null,"homepage":"https://codex.nimahejazi.org/medoutcon","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/nhejazi.png","metadata":{"files":{"readme":"README.Rmd","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","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}},"created_at":"2019-04-07T01:13:19.000Z","updated_at":"2024-02-20T06:06:01.000Z","dependencies_parsed_at":"2024-03-18T16:50:51.037Z","dependency_job_id":null,"html_url":"https://github.com/nhejazi/medoutcon","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nhejazi%2Fmedoutcon","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nhejazi%2Fmedoutcon/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nhejazi%2Fmedoutcon/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nhejazi%2Fmedoutcon/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nhejazi","download_url":"https://codeload.github.com/nhejazi/medoutcon/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230022911,"owners_count":18161076,"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":["causal-inference","causal-machine-learning","inverse-probability-weights","machine-learning","mediation-analysis","r","r-package","stochastic-interventions","targeted-learning","treatment-effects"],"created_at":"2024-12-16T20:31:11.937Z","updated_at":"2025-08-16T08:31:44.348Z","avatar_url":"https://github.com/nhejazi.png","language":"R","funding_links":[],"categories":[],"sub_categories":[],"readme":"---\noutput:\n  rmarkdown::github_document\nbibliography: \"inst/REFERENCES.bib\"\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 = \"README-\"\n)\n```\n\n# R/`medoutcon`\n\n\u003c!-- badges: start --\u003e\n[![R-CMD-check](https://github.com/nhejazi/medoutcon/actions/workflows/R-CMD-check.yml/badge.svg)](https://github.com/nhejazi/medoutcon/actions/workflows/R-CMD-check.yml)\n[![Coverage Status](https://img.shields.io/codecov/c/github/nhejazi/medoutcon/master.svg)](https://codecov.io/github/nhejazi/medoutcon?branch=master)\n[![Project Status: Active – The project has reached a stable, usable state and is being actively developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active)\n[![MIT license](http://img.shields.io/badge/license-MIT-brightgreen.svg)](http://opensource.org/licenses/MIT)\n[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.5809519.svg)](https://doi.org/10.5281/zenodo.5809519)\n[![DOI](https://joss.theoj.org/papers/10.21105/joss.03979/status.svg)](https://doi.org/10.21105/joss.03979)\n\u003c!-- badges: end --\u003e\n\n\u003e Efficient Causal Mediation Analysis for the Natural and Interventional Effects\n\n__Authors:__ [Nima Hejazi](https://nimahejazi.org), [Iván\nDíaz](https://idiaz.xyz), and [Kara\nRudolph](https://kararudolph.github.io/)\n\n---\n\n## What's `medoutcon`?\n\nThe `medoutcon` R package provides facilities for efficient estimation of\npath-specific (in)direct effects that measure the impact of a treatment variable\n$A$ on an outcome variable $Y$, through a direct path (through $A$ only) and an\nindirect path (through a set of mediators $M$ only). In the presence of an\nintermediate \u003cb\u003emed\u003c/b\u003eiator-\u003cb\u003eout\u003c/b\u003ecome \u003cb\u003econ\u003c/b\u003efounder $Z$, itself\naffected by the treatment $A$, these correspond to the _interventional_\n(in)direct effects described by @diaz2020nonparametric, though similar (yet less\ngeneral) effect definitions and/or estimation strategies have appeared i`n\n@`vanderweele2014effect, @rudolph2017robust, @zheng2017longitudinal, and\n@benkeser2020nonparametric. When no intermediate confounders are present, these\neffect definitions simplify to the well-studied _natural_ (in)direct effects,\nand our estimators are analogs of those formulated by @zheng2012targeted.  Both\nan efficient one-step bias-corrected estimator with cross-fitting\n[@pfanzagl1985contributions; @zheng2011cross; @chernozhukov2018double] and a\ncross-validated targeted minimum loss estimator (TMLE) [@vdl2011targeted;\n@zheng2011cross] are made available. `medoutcon` integrates with the [`sl3` R\npackage](https://github.com/tlverse/sl3) [@coyle-gh-sl3] to leverage statistical\nmachine learning in the estimation procedure.\n\n---\n\n## Installation\n\nInstall the most recent _stable release_ from GitHub via\n[`remotes`](https://CRAN.R-project.org/package=remotes):\n\n```{r gh-master-installation, eval=FALSE}\nremotes::install_github(\"nhejazi/medoutcon\")\n```\n\n---\n\n## Example\n\nTo illustrate how `medoutcon` may be used to estimate stochastic interventional\n(in)direct effects of the exposure (`A`) on the outcome (`Y`) in the presence of\nmediator(s) (`M`) and a mediator-outcome confounder (`Z`), consider the\nfollowing example:\n\n```{r example, warning=FALSE}\nlibrary(data.table)\nlibrary(stringr)\nlibrary(medoutcon)\nset.seed(02138)\n\n# produces a simple data set based on ca causal model with mediation\nmake_example_data \u003c- function(n_obs = 1000) {\n  ## baseline covariates\n  w_1 \u003c- rbinom(n_obs, 1, prob = 0.6)\n  w_2 \u003c- rbinom(n_obs, 1, prob = 0.3)\n  w_3 \u003c- rbinom(n_obs, 1, prob = pmin(0.2 + (w_1 + w_2) / 3, 1))\n  w \u003c- cbind(w_1, w_2, w_3)\n  w_names \u003c- paste(\"W\", seq_len(ncol(w)), sep = \"_\")\n\n  ## exposure\n  a \u003c- as.numeric(rbinom(n_obs, 1, plogis(rowSums(w) - 2)))\n\n  ## mediator-outcome confounder affected by treatment\n  z \u003c- rbinom(n_obs, 1, plogis(rowMeans(-log(2) + w - a) + 0.2))\n\n  ## mediator -- could be multivariate\n  m \u003c- rbinom(n_obs, 1, plogis(rowSums(log(3) * w[, -3] + a - z)))\n  m_names \u003c- \"M\"\n\n  ## outcome\n  y \u003c- rbinom(n_obs, 1, plogis(1 / (rowSums(w) - z + a + m)))\n\n  ## construct output\n  dat \u003c- as.data.table(cbind(w = w, a = a, z = z, m = m, y = y))\n  setnames(dat, c(w_names, \"A\", \"Z\", m_names, \"Y\"))\n  return(dat)\n}\n\n# set seed and simulate example data\nexample_data \u003c- make_example_data(n_obs = 5000L)\nw_names \u003c- str_subset(colnames(example_data), \"W\")\nm_names \u003c- str_subset(colnames(example_data), \"M\")\n\n# quick look at the data\nhead(example_data)\n\n# compute one-step estimate of the interventional direct effect\nos_de \u003c- medoutcon(\n  W = example_data[, ..w_names],\n  A = example_data$A,\n  Z = example_data$Z,\n  M = example_data[, ..m_names],\n  Y = example_data$Y,\n  effect = \"direct\",\n  estimator = \"onestep\"\n)\nos_de\n\n# compute targeted minimum loss estimate of the interventional direct effect\ntmle_de \u003c- medoutcon(\n  W = example_data[, ..w_names],\n  A = example_data$A,\n  Z = example_data$Z,\n  M = example_data[, ..m_names],\n  Y = example_data$Y,\n  effect = \"direct\",\n  estimator = \"tmle\"\n)\ntmle_de\n```\n\nFor details on how to use data adaptive regression (machine learning) techniques\nin the estimation of nuisance parameters, consider consulting the vignette that\naccompanies the package.\n\n---\n\n## Issues\n\nIf you encounter any bugs or have any specific feature requests, please [file an\nissue](https://github.com/nhejazi/medoutcon/issues).\n\n---\n\n## Contributions\n\nContributions are very welcome. Interested contributors should consult our\n[contribution\nguidelines](https://github.com/nhejazi/medoutcon/blob/master/CONTRIBUTING.md)\nprior to submitting a pull request.\n\n---\n\n## Citation\n\nAfter using the `medoutcon` R package, please cite the following:\n\n        @article{diaz2020nonparametric,\n          title={Non-parametric efficient causal mediation with intermediate\n            confounders},\n          author={D{\\'\\i}az, Iv{\\'a}n and Hejazi, Nima S and Rudolph, Kara E\n            and {van der Laan}, Mark J},\n          year={2020},\n          url = {https://arxiv.org/abs/1912.09936},\n          doi = {10.1093/biomet/asaa085},\n          journal={Biometrika},\n          volume = {108},\n          number = {3},\n          pages = {627--641},\n          publisher={Oxford University Press}\n        }\n\n        @article{hejazi2022medoutcon-joss,\n          author = {Hejazi, Nima S and Rudolph, Kara E and D{\\'\\i}az,\n            Iv{\\'a}n},\n          title = {{medoutcon}: Nonparametric efficient causal mediation\n            analysis with machine learning in {R}},\n          year = {2022},\n          doi = {10.21105/joss.03979},\n          url = {https://doi.org/10.21105/joss.03979},\n          journal = {Journal of Open Source Software},\n          publisher = {The Open Journal}\n        }\n\n        @software{hejazi2022medoutcon-rpkg,\n          author={Hejazi, Nima S and D{\\'\\i}az, Iv{\\'a}n and Rudolph, Kara E},\n          title = {{medoutcon}: Efficient natural and interventional causal\n            mediation analysis},\n          year  = {2024},\n          doi = {10.5281/zenodo.5809519},\n          url = {https://github.com/nhejazi/medoutcon},\n          note = {R package version 0.2.3}\n        }\n\n---\n\n## License\n\n\u0026copy; 2020-2024 [Nima S. Hejazi](https://nimahejazi.org)\n\nThe contents of this repository are distributed under the MIT license. See below\nfor details:\n```\nMIT License\n\nCopyright (c) 2020-2024 Nima S. Hejazi\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n```\n\n---\n\n## References\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnhejazi%2Fmedoutcon","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnhejazi%2Fmedoutcon","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnhejazi%2Fmedoutcon/lists"}