{"id":23089237,"url":"https://github.com/nhejazi/txshift","last_synced_at":"2025-08-16T08:31:43.771Z","repository":{"id":54647153,"uuid":"103704579","full_name":"nhejazi/txshift","owner":"nhejazi","description":":package: :game_die: R/txshift: Efficient Estimation of the Causal Effects of Stochastic Interventions, with Corrections for Outcome-Dependent Sampling","archived":false,"fork":false,"pushed_at":"2024-09-21T20:33:03.000Z","size":2430,"stargazers_count":13,"open_issues_count":3,"forks_count":4,"subscribers_count":6,"default_branch":"master","last_synced_at":"2024-09-23T17:47:34.391Z","etag":null,"topics":["causal-effects","causal-inference","censored-data","machine-learning","robust-statistics","statistics","stochastic-interventions","stochastic-treatment-regimes","targeted-learning","treatment-effects","variable-importance"],"latest_commit_sha":null,"homepage":"https://codex.nimahejazi.org/txshift","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":"2017-09-15T21:53:58.000Z","updated_at":"2024-09-21T20:33:06.000Z","dependencies_parsed_at":"2022-08-13T22:40:41.982Z","dependency_job_id":null,"html_url":"https://github.com/nhejazi/txshift","commit_stats":{"total_commits":339,"total_committers":4,"mean_commits":84.75,"dds":0.03244837758112096,"last_synced_commit":"59919faf2ee535eb0443df03fbc9e89e94a6c870"},"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nhejazi%2Ftxshift","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nhejazi%2Ftxshift/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nhejazi%2Ftxshift/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nhejazi%2Ftxshift/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nhejazi","download_url":"https://codeload.github.com/nhejazi/txshift/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230022881,"owners_count":18161071,"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-effects","causal-inference","censored-data","machine-learning","robust-statistics","statistics","stochastic-interventions","stochastic-treatment-regimes","targeted-learning","treatment-effects","variable-importance"],"created_at":"2024-12-16T20:31:08.526Z","updated_at":"2024-12-16T20:31:10.650Z","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\n# R/`txshift`\n\n\u003c!-- badges: start --\u003e\n[![R-CMD-check](https://github.com/nhejazi/txshift/workflows/R-CMD-check/badge.svg)](https://github.com/nhejazi/txshift/actions)\n[![Coverage Status](https://img.shields.io/codecov/c/github/nhejazi/txshift/master.svg)](https://codecov.io/github/nhejazi/txshift?branch=master)\n[![CRAN](https://www.r-pkg.org/badges/version/txshift)](https://www.r-pkg.org/pkg/txshift)\n[![CRAN downloads](https://cranlogs.r-pkg.org/badges/txshift)](https://CRAN.R-project.org/package=txshift)\n[![CRAN total downloads](http://cranlogs.r-pkg.org/badges/grand-total/txshift)](https://CRAN.R-project.org/package=txshift)\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](https://img.shields.io/badge/license-MIT-brightgreen.svg)](https://opensource.org/licenses/MIT)\n[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.4070042.svg)](https://doi.org/10.5281/zenodo.4070042)\n[![DOI](https://joss.theoj.org/papers/10.21105/joss.02447/status.svg)](https://doi.org/10.21105/joss.02447)\n\u003c!-- badges: end --\u003e\n\n\u003e Efficient Estimation of the Causal Effects of Stochastic Interventions\n\n__Authors:__ [Nima Hejazi](https://nimahejazi.org) and [David\nBenkeser](https://www.sph.emory.edu/faculty/profile/#!dbenkes)\n\n---\n\n## What's `txshift`?\n\nThe `txshift` R package is designed to provide facilities for the construction\nof efficient estimators of the counterfactual mean of an outcome under\nstochastic interventions that depend on the natural value of treatment\n[@diaz2012population; @haneuse2013estimation]. `txshift `implements and builds\nupon a simplified algorithm for the targeted maximum likelihood (TML) estimator\nof such a causal parameter, originally proposed by @diaz2018stochastic, and\nmakes use of analogous machinery to compute an efficient one-step estimator\n[@pfanzagl1985contributions]. `txshift` integrates with the [`sl3`\npackage](https://github.com/tlverse/sl3) [@coyle-sl3-rpkg] to allow for ensemble\nmachine learning to be leveraged in the estimation procedure.\n\nFor many practical applications (e.g., vaccine efficacy trials), observed data\nis often subject to a two-phase sampling mechanism (i.e., through the use of a\ntwo-stage design). In such cases, efficient estimators (of both varieties) must\nbe augmented to construct unbiased estimates of the population-level causal\nparameter. @rose2011targeted2sd first introduced an augmentation procedure that\nrelies on introducing inverse probability of censoring (IPC) weights directly to\nan appropriate loss function or to the efficient influence function estimating\nequation. `txshift` extends this approach to compute IPC-weighted one-step and\nTML estimators of the counterfactual mean outcome under a shift stochastic\ntreatment regime. The package is designed to implement the statistical\nmethodology described in @hejazi2020efficient and extensions thereof.\n\n---\n\n## Installation\n\nFor standard use, we recommend installing the package from\n[CRAN](https://CRAN.R-project.org/package=txshift) via\n\n```{r cran-installation, eval = FALSE}\ninstall.packages(\"txshift\")\n```\n\n_Note:_ If `txshift` is installed from\n[CRAN](https://CRAN.R-project.org/package=txshift), the `sl3`, an enhancing\ndependency that allows ensemble machine learning to be used for nuisance\nparameter estimation, won't be included. We highly recommend additionally\ninstalling `sl3` from GitHub via\n[`remotes`](https://CRAN.R-project.org/package=remotes):\n\n```{r sl3-gh-master-installation, eval = FALSE}\nremotes::install_github(\"tlverse/sl3@master\")\n```\n\nFor the latest features, install the most recent _stable version_  of `txshift`\nfrom GitHub via [`remotes`](https://CRAN.R-project.org/package=remotes):\n\n```{r gh-master-installation, eval = FALSE}\nremotes::install_github(\"nhejazi/txshift@master\")\n```\n\nTo contribute, install the _development version_ of `txshift` from GitHub via\n[`remotes`](https://CRAN.R-project.org/package=remotes):\n\n```{r gh-devel-installation, eval = FALSE}\nremotes::install_github(\"nhejazi/txshift@devel\")\n```\n\n---\n\n## Example\n\nTo illustrate how `txshift` may be used to ascertain the effect of a treatment,\nconsider the following example:\n\n```{r example, warning=FALSE}\nlibrary(txshift)\nlibrary(sl3)\nset.seed(429153)\n\n# simulate simple data\nn_obs \u003c- 500\nW \u003c- replicate(2, rbinom(n_obs, 1, 0.5))\nA \u003c- rnorm(n_obs, mean = 2 * W, sd = 1)\nY \u003c- rbinom(n_obs, 1, plogis(A + W + rnorm(n_obs, mean = 0, sd = 1)))\n\n# now, let's introduce a a two-stage sampling process\nC_samp \u003c- rbinom(n_obs, 1, plogis(W + Y))\n\n# fit the full-data TMLE (ignoring two-phase sampling)\ntmle \u003c- txshift(\n  W = W, A = A, Y = Y, delta = 0.5,\n  estimator = \"tmle\",\n  g_exp_fit_args = list(\n    fit_type = \"sl\",\n    sl_learners_density = Lrnr_density_hse$new(Lrnr_hal9001$new())\n  ),\n  Q_fit_args = list(fit_type = \"glm\", glm_formula = \"Y ~ .\")\n)\ntmle\n\n# fit a full-data one-step estimator for comparison (again, no sampling)\nos \u003c- txshift(\n  W = W, A = A, Y = Y, delta = 0.5,\n  estimator = \"onestep\",\n  g_exp_fit_args = list(\n    fit_type = \"sl\",\n    sl_learners_density = Lrnr_density_hse$new(Lrnr_hal9001$new())\n  ),\n  Q_fit_args = list(fit_type = \"glm\", glm_formula = \"Y ~ .\")\n)\nos\n\n# fit an IPCW-TMLE to account for the two-phase sampling process\ntmle_ipcw \u003c- txshift(\n  W = W, A = A, Y = Y, delta = 0.5, C_samp = C_samp, V = c(\"W\", \"Y\"),\n  estimator = \"tmle\", max_iter = 5, eif_reg_type = \"glm\",\n  samp_fit_args = list(fit_type = \"glm\"),\n  g_exp_fit_args = list(\n    fit_type = \"sl\",\n    sl_learners_density = Lrnr_density_hse$new(Lrnr_hal9001$new())\n  ),\n  Q_fit_args = list(fit_type = \"glm\", glm_formula = \"Y ~ .\")\n)\ntmle_ipcw\n\n# compare with an IPCW-agumented one-step estimator under two-phase sampling\nos_ipcw \u003c- txshift(\n  W = W, A = A, Y = Y, delta = 0.5, C_samp = C_samp, V = c(\"W\", \"Y\"),\n  estimator = \"onestep\", eif_reg_type = \"glm\",\n  samp_fit_args = list(fit_type = \"glm\"),\n  g_exp_fit_args = list(\n    fit_type = \"sl\",\n    sl_learners_density = Lrnr_density_hse$new(Lrnr_hal9001$new())\n  ),\n  Q_fit_args = list(fit_type = \"glm\", glm_formula = \"Y ~ .\")\n)\nos_ipcw\n```\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/txshift/issues). Further details on filing\nissues are provided in our [contribution\nguidelines](https://github.com/nhejazi/txshift/blob/master/CONTRIBUTING.md).\n\n---\n\n## Contributions\n\nContributions are very welcome. Interested contributors should consult our\n[contribution\nguidelines](https://github.com/nhejazi/txshift/blob/master/CONTRIBUTING.md)\nprior to submitting a pull request.\n\n---\n\n## Citation\n\nAfter using the `txshift` R package, please cite the following:\n\n        @article{hejazi2020efficient,\n          author = {Hejazi, Nima S and {van der Laan}, Mark J and Janes, Holly\n            E and Gilbert, Peter B and Benkeser, David C},\n          title = {Efficient nonparametric inference on the effects of\n            stochastic interventions under two-phase sampling, with\n            applications to vaccine efficacy trials},\n          year = {2021},\n          doi = {10.1111/biom.13375},\n          url = {https://doi.org/10.1111/biom.13375},\n          journal = {Biometrics},\n          publisher = {Wiley Online Library}\n        }\n\n        @article{hejazi2020txshift-joss,\n          author = {Hejazi, Nima S and Benkeser, David C},\n          title = {{txshift}: Efficient estimation of the causal effects of\n            stochastic interventions in {R}},\n          year  = {2020},\n          doi = {10.21105/joss.02447},\n          url = {https://doi.org/10.21105/joss.02447},\n          journal = {Journal of Open Source Software},\n          publisher = {The Open Journal}\n        }\n\n        @software{hejazi2022txshift-rpkg,\n          author = {Hejazi, Nima S and Benkeser, David C},\n          title = {{txshift}: Efficient Estimation of the Causal Effects of\n            Stochastic Interventions},\n          year  = {2022},\n          doi = {10.5281/zenodo.4070042},\n          url = {https://CRAN.R-project.org/package=txshift},\n          note = {R package version 0.3.9}\n        }\n\n---\n\n## Related\n\n* [R/`tmle3shift`](https://github.com/tlverse/tmle3shift) - An R package that\n  is an independent implementation of the same core methodology for TML\n  estimation as provided here but written based on the\n  [`tmle3`](https://github.com/tlverse/tmle3) engine of the [`tlverse`\n  ecosystem](https://github.com/tlverse). Unlike `txshift`, this package does\n  not provide tools for estimation under two-phase sampling designs.\n\n* [R/`medshift`](https://github.com/nhejazi/medshift) - An experimental R\n  package for estimating causal mediation effects with stochastic interventions,\n  including via inverse probability weighted and asymptotically efficient\n  one-step estimators, as first described in @diaz2020causal.\n\n* [R/`haldensify`](https://github.com/nhejazi/haldensify) - An R package for\n  estimating the generalized propensity score (conditional density) nuisance\n  parameter using the [highly adaptive\n  lasso](https://github.com/tlverse/hal9001) [@coyle-hal9001-rpkg;\n  @hejazi2020hal9001-joss] via an application of pooled hazard regression\n  [@diaz2011super].\n\n* [R/`lmtp`](https://github.com/nt-williams/lmtp) - An R package for estimating\n  the causal effects of *longitudinal* modified treatment policies, which are a\n  generalization of the type of effect considered in this package. The LMTP\n  framework was first introduced in @diaz2021nonparametric and the `lmtp`\n  package is described in @williams2023lmtp.\n\n---\n\n## Funding\n\nThe development of this software was supported in part through grants from the\nNational Library of Medicine (award no. [T32\nLM012417](https://reporter.nih.gov/project-details/9248418)), the National\nInstitute of Allergy and Infectious Diseases (award no.  [R01\nAI074345](https://reporter.nih.gov/project-details/9926564)), and the National\nScience Foundation (award no. [DMS\n2102840](https://www.nsf.gov/awardsearch/showAward?AWD_ID=2102840)).\n\n---\n\n## License\n\n\u0026copy; 2017-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) 2017-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","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnhejazi%2Ftxshift","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnhejazi%2Ftxshift","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnhejazi%2Ftxshift/lists"}