{"id":17152804,"url":"https://github.com/jackmwolf/tehtuner","last_synced_at":"2025-04-13T12:43:57.774Z","repository":{"id":62849846,"uuid":"425356001","full_name":"jackmwolf/tehtuner","owner":"jackmwolf","description":"An R Package to Fit and Tune to Models to Detect Treatment Effect Heterogeneity ","archived":false,"fork":false,"pushed_at":"2025-04-09T23:09:16.000Z","size":1034,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-10T00:22:02.070Z","etag":null,"topics":["clinical-trials","heterogeneity-of-treatment-effect","r","subgroup-identification"],"latest_commit_sha":null,"homepage":"","language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jackmwolf.png","metadata":{"files":{"readme":"README.Rmd","changelog":"NEWS.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","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}},"created_at":"2021-11-06T21:50:51.000Z","updated_at":"2025-04-09T23:09:20.000Z","dependencies_parsed_at":"2025-04-10T00:20:18.024Z","dependency_job_id":"32687412-2878-4a52-803c-46247490bdc4","html_url":"https://github.com/jackmwolf/tehtuner","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jackmwolf%2Ftehtuner","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jackmwolf%2Ftehtuner/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jackmwolf%2Ftehtuner/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jackmwolf%2Ftehtuner/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jackmwolf","download_url":"https://codeload.github.com/jackmwolf/tehtuner/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248717240,"owners_count":21150387,"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":["clinical-trials","heterogeneity-of-treatment-effect","r","subgroup-identification"],"created_at":"2024-10-14T21:44:35.363Z","updated_at":"2025-04-13T12:43:57.750Z","avatar_url":"https://github.com/jackmwolf.png","language":"R","funding_links":[],"categories":[],"sub_categories":[],"readme":"---\noutput: github_document\neditor_options: \n  chunk_output_type: console\n---\n\n\u003c!-- README.md is generated from README.Rmd. Please edit that file --\u003e\n\n```{r, include = FALSE}\nknitr::opts_chunk$set(\n  collapse = TRUE,\n  comment = \"#\u003e\",\n  fig.path = \"man/figures/README-\",\n  out.width = \"100%\"\n)\n\nlibrary(ggplot2)\nlibrary(ggtext)\nlibrary(magrittr)\nlibrary(kableExtra)\nlibrary(Cairo)\nlibrary(rpart.plot)\n```\n\n# tehtuner\n\n\u003c!-- badges: start --\u003e\n[![CRAN status](https://www.r-pkg.org/badges/version/tehtuner)](https://CRAN.R-project.org/package=tehtuner)\n[![DOI](https://joss.theoj.org/papers/10.21105/joss.05453/status.svg)](https://doi.org/10.21105/joss.05453)\n[![R-CMD-check](https://github.com/jackmwolf/tehtuner/workflows/R-CMD-check/badge.svg)](https://github.com/jackmwolf/tehtuner/actions)\n\u003c!-- badges: end --\u003e\n\nThe goal of `tehtuner` is to implement methods to fit models to detect and model\ntreatment effect heterogeneity (TEH) while controlling the Type-I error of falsely \ndetecting a differential effect when the conditional average treatment effect is\nuniform across the study population.\n\nCurrently `tehtuner` supports Virtual Twins models (Foster \net al., 2011) for detecting TEH using the permutation procedure proposed in (Wolf et al., 2022).\n\nVirtual Twins is a two-step approach to detecting differential treatment\neffects. Subjects' conditional average treatment effects (CATEs) are first\nestimated in Step 1 using a flexible model. Then, a simple and interpretable\nmodel is fit in Step 2 to model these estimated CATEs as a function of the\ncovariates.\n\nThe Step 2 model is dependent on some tuning parameter. This parameter is\nselected to control the Type-I error rate by permuting the data under the\nnull hypothesis of a constant treatment effect and identifying the minimal\nnull penalty parameter (MNPP), which is the smallest penalty parameter that\nyields a Step 2 model with no covariate effects. The $1-\\alpha$ quantile\nof the distribution of is then used to fit the Step 2 model on the original\ndata.\nIn dong so, the Type-I error rate is controlled to be $\\alpha$.\n\n## Installation\n\n`tehtuner` is available on [CRAN](https://CRAN.R-project.org); you can download the release version with:\n\n``` r\ninstall.packages(\"tehtuner\")\n```\n\nYou can download the development version from [GitHub](https://github.com/) with:\n\n``` r\n# install.packages(\"devtools\")\ndevtools::install_github(\"jackmwolf/tehtuner\")\n```\n## Example\n\nWe consider simulated data from a small clinical trial with 1000 subjects.\nEach subject has 10 measured covariates, 8 continuous and 2 binary.\nWe are interested in estimating and understanding the CATE through Virtual Twins.\n\n```{r}\nlibrary(tehtuner)\ndata(\"tehtuner_example\")\n```\n\nWe will consider a Virtual Twins model using a random forest to estimate the CATEs in Step 1 and then fitting a regression tree on the estimated CATEs in Step 2 with the Type-I error rate set at $\\alpha = 0.2$.\n\n```{r cache=TRUE}\nset.seed(100)\nvt_cate \u003c- tunevt(\n  data = tehtuner_example, Y = \"Y\", Trt = \"Trt\", step1 = \"randomforest\",\n  step2 = \"rtree\", alpha0 = 0.2, p_reps = 100, ntree = 50\n)\nvt_cate\n```\n\nThe fitted Step 2 model can be accessed via `$vtmod`. \nIn this case, as we used a regression tree in Step 2, our final model model is of class `rpart.object`.\n```{r dev='CairoPNG', warning = FALSE}\nvt_cate$vtmod\n\nrpart.plot::rpart.plot(vt_cate$vtmod, digits = -2)\n```\n\nThe fitted model for the CATE is a function of the covariates (`V1`, and `V3`), so we would conclude that there is treatment effect heterogeneity at the 20% level. \n\nWe can also look at the null distribution of the MNPP through `vt_cate$theta_null`.\nThe 80th percentile of $\\hat\\theta$ under the null hypothesis is\n```{r}\nquantile(vt_cate$theta_null, 0.8)\n```\n\nwhile the MNPP of our observed data is\n```{r}\nvt_cate$mnpp\n```\n\nThe procedure fit the Step 2 model using the 80th quantile of the null distribution which resulted in a model that included covariates since the MNPP was above the 80th quantile.\n\n```{r mnpp_plot, dev='CairoPNG', echo = FALSE}\nggplot(mapping = aes(x = vt_cate$theta_null, y = after_stat(density))) +\n  geom_histogram(color = \"black\", fill = \"white\", binwidth = 0.025) +\n  theme_minimal() +\n  scale_y_continuous(expand = expansion(mult = c(0, 0.1))) +\n  geom_vline(\n    aes(xintercept = c(vt_cate$mnpp, quantile(vt_cate$theta_null, 0.8))),\n    color = c(\"#0072B2\", \"#D55E00\"),\n    linewidth = 2,\n    linetype = 2\n  ) + \n  labs(\n    y = \"Density\",\n    x = expression(hat(theta)),\n    title =  expression(\"Sampling distribution of\" ~ hat(theta) ~ \"under\" ~ H[0]),\n    subtitle = paste0(\n      \"\u003cspan style='color:#D55E00;'\u003e\",\n        \"80th quantile (critical value): \", formatC(quantile(vt_cate$theta_null, 0.8), digits = 2, format = \"f\"),\n      \"\u003c/span\u003e\",\n      \"; \",\n      \"\u003cspan style='color:#0072B2;'\u003e\",\n        \"Observed MNPP: \", formatC(vt_cate$mnpp, 2, format = \"f\"), \n      \"\u003c/span\u003e\"\n      )\n  ) +\n  theme(\n    plot.subtitle = element_markdown(size = 12)\n  )\n```\n\n### Running in Parallel\n\nVersion `0.2.0` added the `parallel` option to `tunevt()` which allows the user to perform the permutation procedure in parallel to reduce computation times. \nBefore doing so, you must register a parallel backend; see `?foreach::foreach` for more information.\n\nFor example, to carry out 100 permutations across 2 processors:\n\n```{r eval = FALSE}\ncl \u003c- parallel::makeCluster(2)\ndoParallel::registerDoParallel(cl)\n\nvt_cate_parallel \u003c- tunevt(\n  data = tehtuner_example, Y = \"Y\", Trt = \"Trt\", step1 = \"randomforest\",\n  step2 = \"rtree\", alpha0 = 0.2, p_reps = 100, ntree = 50, parallel = TRUE\n)\n\nparallel::stopCluster(cl)\n```\n\n\n## References\n\n- Foster, J. C., Taylor, J. M., \u0026 Ruberg, S. J. (2011). Subgroup identification from randomized clinical trial data. _Statistics in Medicine, 30_(24), 2867–2880. https://doi.org/10.1002/sim.4322\n\n- Wolf, J. M., Koopmeiners, J. S., \u0026 Vock, D. M. (2022). A permutation procedure to detect heterogeneous treatment effects in randomized clinical trials while controlling the type-I error rate. _Clinical Trials, 19_(5). https://doi.org/10.1177/17407745221095855\n\n- Deng C., Wolf J. M., Vock D. M., Carroll D. M., Hatsukami D. K., Leng N., \u0026 Koopmeiners J. S. (2023). “Practical guidance on modeling choices for the virtual twins method.” _Journal of Biopharmaceutical Statistics_. https://doi.org/10.1080/10543406.2023.2170404\n\n- Wolf, J. M., (2023). tehtuner: An R package to fit and tune models for the conditional average treatment effect. _Journal of Open Source Software, 8_(86), 5453. https://doi.org/10.21105/joss.05453\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjackmwolf%2Ftehtuner","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjackmwolf%2Ftehtuner","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjackmwolf%2Ftehtuner/lists"}