{"id":23089262,"url":"https://github.com/nhejazi/medshift","last_synced_at":"2025-09-18T23:55:04.804Z","repository":{"id":85377082,"uuid":"146507621","full_name":"nhejazi/medshift","owner":"nhejazi","description":":package: :game_die: R/medshift: Causal Mediation Analysis for Stochastic Interventions","archived":false,"fork":false,"pushed_at":"2023-05-19T17:06:08.000Z","size":803,"stargazers_count":9,"open_issues_count":4,"forks_count":3,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-07-10T06:57:27.291Z","etag":null,"topics":["causal-inference","inverse-probability-weights","machine-learning","mediation-analysis","stochastic-interventions","targeted-learning","treatment-effects"],"latest_commit_sha":null,"homepage":"https://codex.nimahejazi.org/medshift","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}},"created_at":"2018-08-28T21:14:49.000Z","updated_at":"2024-02-22T18:39:42.000Z","dependencies_parsed_at":null,"dependency_job_id":"ee7ee575-af87-44ab-807c-c2d9ddce3db1","html_url":"https://github.com/nhejazi/medshift","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/nhejazi/medshift","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nhejazi%2Fmedshift","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nhejazi%2Fmedshift/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nhejazi%2Fmedshift/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nhejazi%2Fmedshift/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nhejazi","download_url":"https://codeload.github.com/nhejazi/medshift/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nhejazi%2Fmedshift/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271665297,"owners_count":24799304,"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-08-22T02:00:08.480Z","response_time":65,"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":["causal-inference","inverse-probability-weights","machine-learning","mediation-analysis","stochastic-interventions","targeted-learning","treatment-effects"],"created_at":"2024-12-16T20:31:16.170Z","updated_at":"2025-09-18T23:54:59.757Z","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/`medshift`\n\n\u003c!-- badges: start --\u003e\n[![R-CMD-check](https://github.com/nhejazi/medshift/workflows/R-CMD-check/badge.svg)](https://github.com/nhejazi/medshift/actions)\n[![Coverage Status](https://img.shields.io/codecov/c/github/nhejazi/medshift/master.svg)](https://app.codecov.io/github/nhejazi/medshift)\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\u003c!-- badges: end --\u003e\n\n\u003e Causal Mediation Analysis for Stochastic Interventions\n\n__Authors:__ [Nima Hejazi](https://nimahejazi.org) and [Iván\nDíaz](https://idiaz.xyz)\n\n---\n\n## What's `medshift`?\n\nThe `medshift` R package is designed to provide facilities for estimating a\nparameter that arises in a decomposition of the population intervention causal\neffect into the (in)direct effects under stochastic interventions in the setting\nof mediation analysis. `medshift` is designed as an implementation to accompany\nthe methodology described in @diaz2020causal. Implemented estimators include the\nclassical substitution (G-computation) estimator, an inverse probability\nweighted (IPW) estimator, an efficient one-step estimator using cross-fitting\n[@pfanzagl1985contributions; @zheng2011cross; @chernozhukov2018double], and a\ncross-validated targeted minimum loss (TML) estimator [@vdl2011targeted;\n@zheng2011cross]. `medshift` integrates with the [`sl3` R\npackage](https://github.com/tlverse/sl3) [@coyle-gh-sl3] to allow constructed\nestimators to leverage machine learning for nuisance estimation.\n\n---\n\n## Installation\n\nInstall the _most recent version_ from the `master` branch on GitHub via\n[`remotes`](https://CRAN.R-project.org/package=remotes):\n\n```{r gh-master-installation, eval=FALSE}\nremotes::install_github(\"nhejazi/medshift\")\n```\n\n---\n\n## Example\n\nTo illustrate how `medshift` may be used to estimate the effect of applying a\nstochastic intervention to the treatment (`A`) while keeping the mediator(s)\n(`Z`) fixed, consider the following example:\n\n```{r simple_example, message=FALSE, warning=FALSE}\nlibrary(data.table)\nlibrary(medshift)\n\n# produces a simple data set based on ca causal model with mediation\nmake_simple_mediation_data \u003c- function(n_obs = 1000) {\n  # baseline covariate -- simple, binary\n  W \u003c- rbinom(n_obs, 1, prob = 0.50)\n\n  # create treatment based on baseline W\n  A \u003c- as.numeric(rbinom(n_obs, 1, prob = W / 4 + 0.1))\n\n  # single mediator to affect the outcome\n  z1_prob \u003c- 1 - plogis((A^2 + W) / (A + W^3 + 0.5))\n  Z \u003c- rbinom(n_obs, 1, prob = z1_prob)\n\n  # create outcome as a linear function of A, W + white noise\n  Y \u003c- Z + A - 0.1 * W + rnorm(n_obs, mean = 0, sd = 0.25)\n\n  # full data structure\n  data \u003c- as.data.table(cbind(Y, Z, A, W))\n  setnames(data, c(\"Y\", \"Z\", \"A\", \"W\"))\n  return(data)\n}\n\n# set seed and simulate example data\nset.seed(75681)\nexample_data \u003c- make_simple_mediation_data()\n\n# compute one-step estimate for an incremental propensity score intervention\n# that triples (delta = 3) the individual-specific odds of receiving treatment\nos_medshift \u003c- medshift(W = example_data$W, A = example_data$A,\n                        Z = example_data$Z, Y = example_data$Y,\n                        delta = 3, estimator = \"onestep\",\n                        estimator_args = list(cv_folds = 3))\nsummary(os_medshift)\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 this 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/medshift/issues).\n\n---\n\n## Contributions\n\nContributions are very welcome. Interested contributors should consult our\n[contribution\nguidelines](https://github.com/nhejazi/medshift/blob/master/CONTRIBUTING.md)\nprior to submitting a pull request.\n\n---\n\n## Citation\n\nAfter using the `medshift` R package, please cite the following:\n\n        @article{diaz2020causal,\n          title={Causal mediation analysis for stochastic interventions},\n          author={D{\\'\\i}az, Iv{\\'a}n and Hejazi, Nima S},\n          year={2020},\n          url = {https://doi.org/10.1111/rssb.12362},\n          doi = {10.1111/rssb.12362},\n          journal={Journal of the Royal Statistical Society: Series B\n            (Statistical Methodology)},\n          volume={},\n          number={},\n          pages={},\n          publisher={Wiley Online Library}\n        }\n\n        @manual{hejazi2020medshift,\n          author = {Hejazi, Nima S and D{\\'\\i}az, Iv{\\'a}n},\n          title = {{medshift}: Causal mediation analysis for stochastic\n            interventions},\n          year  = {2020},\n          url = {https://github.com/nhejazi/medshift},\n          note = {R package version 0.1.4}\n        }\n\n---\n\n## License\n\n\u0026copy; 2018-2022 [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) 2018-2022 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","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnhejazi%2Fmedshift","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnhejazi%2Fmedshift","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnhejazi%2Fmedshift/lists"}