{"id":23100651,"url":"https://github.com/benkeser/r2weight","last_synced_at":"2025-04-03T20:45:17.559Z","repository":{"id":129606534,"uuid":"66289334","full_name":"benkeser/r2weight","owner":"benkeser","description":"Machine learning-based summaries of association with multivariate outcomes","archived":false,"fork":false,"pushed_at":"2017-09-15T14:27:33.000Z","size":8141,"stargazers_count":1,"open_issues_count":1,"forks_count":1,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-02-09T09:11:14.491Z","etag":null,"topics":["cross-validation","ensemble-learning","multivariate-analysis","prediction"],"latest_commit_sha":null,"homepage":"https://benkeser.github.io/r2weight/","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/benkeser.png","metadata":{"files":{"readme":"README.Rmd","changelog":"NEWS.md","contributing":null,"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,"publiccode":null,"codemeta":null}},"created_at":"2016-08-22T16:28:30.000Z","updated_at":"2017-10-07T21:55:55.000Z","dependencies_parsed_at":"2023-03-23T16:32:16.859Z","dependency_job_id":null,"html_url":"https://github.com/benkeser/r2weight","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/benkeser%2Fr2weight","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/benkeser%2Fr2weight/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/benkeser%2Fr2weight/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/benkeser%2Fr2weight/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/benkeser","download_url":"https://codeload.github.com/benkeser/r2weight/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247078801,"owners_count":20879950,"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":["cross-validation","ensemble-learning","multivariate-analysis","prediction"],"created_at":"2024-12-16T23:33:31.755Z","updated_at":"2025-04-03T20:45:17.534Z","avatar_url":"https://github.com/benkeser.png","language":"R","funding_links":[],"categories":[],"sub_categories":[],"readme":"---\noutput: \n    github_document\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/`r2weight`\n\n[![Travis-CI Build Status](https://travis-ci.org/benkeser/r2weight.svg?branch=master)](https://travis-ci.org/benkeser/r2weight)\n[![AppVeyor Build  Status](https://ci.appveyor.com/api/projects/status/github/benkeser/r2weight?branch=master\u0026svg=true)](https://ci.appveyor.com/project/benkeser/r2weight)\n[![Coverage Status](https://img.shields.io/codecov/c/github/benkeser/r2weight/master.svg)](https://codecov.io/github/benkeser/r2weight?branch=master)\n[![MIT license](http://img.shields.io/badge/license-MIT-brightgreen.svg)](http://opensource.org/licenses/MIT)\n\n\u003e Machine learning-based summary of association with multivariate outcomes\n\n__Authors:__ [David Benkeser](https://www.benkeserstatistics.com/)\n\n## Introduction\n\nThis package provides a method for summarizing the strength of association between a set of variables and a multivariate outcome. In particular, cross-validation is combined with stacked regression (aka super learning) to estimate the convex combination of a multivariate outcome that maximizes cross-validated R-squared of a super learner-based prediction. The method is particularly well suited for situations with high-dimensional covariates and/or complex relationships between covariates and outcomes. \n\n## Installation\n\nYou can install a stable release of `r2weight` from GitHub via\n[`devtools`](https://www.rstudio.com/products/rpackages/devtools/) with:\n\n```{r gh-installation, eval = FALSE}\ndevtools::install_github(\"benkeser/r2weight\")\n```\n\nIn the future, the package will be available from [CRAN](https://cran.r-project.org/) via\n\n```{r cran-installation, eval = FALSE}\ninstall.packages(\"r2weight\")\n```\n\n## Use\n\nThe basic workflow of the package is to call the function `optWeight`, which estimates the optimal weights for the combined outcome. The function `r2_optWeight` is then be called using the `optWeight` object to obtain a cross-validated estimate of the R-squared for predicting the optimally combined outcome. This measure provides a summary of the strength of association between covariates and outcome. \n\nHere we illustrate the method using simulated data.\n\n``` r\n# sample size\nn \u003c- 500\n\n# set the seed\nset.seed(12345)\n\n# simulate nine covariate predictors\nx1 \u003c- runif(n,0,4)\nx2 \u003c- runif(n,0,4)\nx3 \u003c- runif(n,0,4)\nx4 \u003c- rbinom(n,1,0.75)\nx5 \u003c- rbinom(n,1,0.25)\nx6 \u003c- rbinom(n,1,0.5)\nx7 \u003c- runif(n,0,4)\nx8 \u003c- runif(n,0,4)\nx9 \u003c- runif(n,0,4)\n# put all predictors in single data.frame\nX \u003c- data.frame(x1=x1, x2=x2, x3=x3, x4=x4, x5=x5, \n                x6=x6, x7=x7, x8=x8, x9=x9)\n\n# simulate three outcomes\ny1 \u003c- x1 + 2*x2 + 4*x3 + x4 + 2*x5 + 4*x6 + 2*x7 + rnorm(n, 0, 5)\ny2 \u003c- x1 + 2*x2 + 4*x3 + x4 + 2*x5 + 4*x6 + 2*x8 + rnorm(n, 0, 5)\ny3 \u003c- x1 + 2*x2 + 4*x3 + x4 + 2*x5 + 4*x6 + 2*x9 + rnorm(n, 0, 5)\n# put all outcomes in single data.frame\nY \u003c- data.frame(y1 = y1, y2 = y2, y3 = y3)\n\n# call optWeight using simple Super Learner library\nout1 \u003c- optWeight(Y = Y, X = X, SL.library = c(\"SL.mean\",\"SL.glm\",\"SL.step\"))\n\n# print the object\nout1\n```\n\nThe estimated optimal weights are shown along with the estimated cross validated R-squared for predicting each outcome using the Super Learner. If desired, there is an S3-method for predicting the combined outcome on new data.\n\n``` r\n# generate new data\nnewX \u003c- data.frame(x1=1, x2=1, x3=1, x4=1, x5=1, \n                   x6=1, x7=1, x8=1, x9=1)\n# get prediction of combined outcome\npredict(out1, newdata = newX)\n```\n\n    ##          [,1]\n    ## [1,] 15.80969\n\nNext, we call `r2_optWeight` to estimate the cross-validated R-squared for predicting the combined outcome with Super Learner.\n\n``` r\n# cross-validated R-squared\n# set verbose = TRUE to see a progress bar\nr2.out1 \u003c- r2_optWeight(out1, Y = Y, X = X)\n\n# print the output\nr2.out1\n```\n\nThe R-squared for each individual outcome is shown, as well as for the combined outcome. In this example, the true R-squared for individual outcomes is about 0.6 and for the combined outcome about 0.8.\n\n## Variable importance\n\nA measure of variable importance for a particular variable can be defined as the difference in R-squared for the combined outcome when including and excluding that variable. These measures can be estimated using the `r2_diff` function.\n\n``` r\n# measure importance of x9\n# call optWeight excluding x9 from X\nout2 \u003c- optWeight(Y = Y, X = X[,1:8], SL.library = c(\"SL.glm\",\"SL.mean\"))\n\n# print output\nout2 \n\n# compare to full fit to get importance for each individual outcome\noutDiff \u003c- r2_diff(out1, out2)\n# difference in R-squared for first outcome\n# with confidence interval and p-value for two-sided test that \n# the difference equals 0\noutDiff$y1$diff\n# for the third outcome\noutDiff$y3$diff\n# for combined outcome \nr2.out2 \u003c- r2_optWeight(out2, Y = Y, X = X[,1:8])\n# print output, notice change in weights\nr2.out2\n# compare to full fit to get importance for combined outcome\noutDiff.r2 \u003c- r2_diff(r2.out1, r2.out2)\n\n# print output\noutDiff.r2\n```\n\n## License\n\u0026copy; 2016-2017 [David C. Benkeser](http://www.benkeserstatistics.com)\n\nThe contents of this repository are distributed under the MIT license. See\nbelow for details:\n```\nThe MIT License (MIT)\n\nCopyright (c) 2016-2017 David C. Benkeser\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```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbenkeser%2Fr2weight","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbenkeser%2Fr2weight","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbenkeser%2Fr2weight/lists"}