`r2weight`

Machine learning-based summary of association with multivariate outcomes

**Authors:** David Benkeser

This 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.

You can install a stable release of `r2weight`

from GitHub via `devtools`

with:

```
devtools::install_github("benkeser/r2weight")
```

In the future, the package will be available from CRAN via

```
install.packages("r2weight")
```

The 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.

Here we illustrate the method using simulated data.

```
# sample size
n <- 500
# set the seed
set.seed(12345)
# simulate nine covariate predictors
x1 <- runif(n,0,4)
x2 <- runif(n,0,4)
x3 <- runif(n,0,4)
x4 <- rbinom(n,1,0.75)
x5 <- rbinom(n,1,0.25)
x6 <- rbinom(n,1,0.5)
x7 <- runif(n,0,4)
x8 <- runif(n,0,4)
x9 <- runif(n,0,4)
# put all predictors in single data.frame
X <- data.frame(x1=x1, x2=x2, x3=x3, x4=x4, x5=x5,
x6=x6, x7=x7, x8=x8, x9=x9)
# simulate three outcomes
y1 <- x1 + 2*x2 + 4*x3 + x4 + 2*x5 + 4*x6 + 2*x7 + rnorm(n, 0, 5)
y2 <- x1 + 2*x2 + 4*x3 + x4 + 2*x5 + 4*x6 + 2*x8 + rnorm(n, 0, 5)
y3 <- x1 + 2*x2 + 4*x3 + x4 + 2*x5 + 4*x6 + 2*x9 + rnorm(n, 0, 5)
# put all outcomes in single data.frame
Y <- data.frame(y1 = y1, y2 = y2, y3 = y3)
# call optWeight using simple Super Learner library
out1 <- optWeight(Y = Y, X = X, SL.library = c("SL.mean","SL.glm","SL.step"))
# print the object
out1
```

The 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.

```
# generate new data
newX <- data.frame(x1=1, x2=1, x3=1, x4=1, x5=1,
x6=1, x7=1, x8=1, x9=1)
# get prediction of combined outcome
predict(out1, newdata = newX)
```

```
## [,1]
## [1,] 15.80969
```

Next, we call `r2_optWeight`

to estimate the cross-validated R-squared for predicting the combined outcome with Super Learner.

```
# cross-validated R-squared
# set verbose = TRUE to see a progress bar
r2.out1 <- r2_optWeight(out1, Y = Y, X = X)
# print the output
r2.out1
```

The 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.

A 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.

```
# measure importance of x9
# call optWeight excluding x9 from X
out2 <- optWeight(Y = Y, X = X[,1:8], SL.library = c("SL.glm","SL.mean","SL.step"))
# print output
out2
# compare to full fit to get importance for each individual outcome
outDiff <- r2_diff(out1, out2)
# difference in R-squared for first outcome
# with confidence interval and p-value for two-sided test that
# the difference equals 0
outDiff$y1$diff
# for the third outcome
outDiff$y3$diff
# for combined outcome
r2.out2 <- r2_optWeight(out2, Y = Y, X = X[,1:8])
# print output, notice change in weights
r2.out2
# compare to full fit to get importance for combined outcome
outDiff.r2 <- r2_diff(r2.out1, r2.out2)
# print output
outDiff.r2
```

© 2016-2017 David C. Benkeser

The contents of this repository are distributed under the MIT license. See below for details:

```
The MIT License (MIT)
Copyright (c) 2016-2017 David C. Benkeser
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
```

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.