joinet.html 18.9 KB
Newer Older
Armin Rauschenberger's avatar
Armin Rauschenberger committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<!DOCTYPE html>
<!-- Generated by pkgdown: do not edit by hand --><html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Multivariate Elastic Net Regression • joinet</title>
<!-- jquery --><script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script><!-- Bootstrap --><link href="https://cdnjs.cloudflare.com/ajax/libs/bootswatch/3.4.0/spacelab/bootstrap.min.css" rel="stylesheet" crossorigin="anonymous">
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.4.1/js/bootstrap.min.js" integrity="sha256-nuL8/2cJ5NDSSwnKD8VqreErSWHtnEP9E7AySL+1ev4=" crossorigin="anonymous"></script><!-- bootstrap-toc --><link rel="stylesheet" href="../bootstrap-toc.css">
<script src="../bootstrap-toc.js"></script><!-- Font Awesome icons --><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.12.1/css/all.min.css" integrity="sha256-mmgLkCYLUQbXn0B1SRqzHar6dCnv9oZFPEC1g1cwlkk=" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.12.1/css/v4-shims.min.css" integrity="sha256-wZjR52fzng1pJHwx4aV2AO3yyTOXrcDW7jBpJtTwVxw=" crossorigin="anonymous">
<!-- clipboard.js --><script src="https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.6/clipboard.min.js" integrity="sha256-inc5kl9MA1hkeYUt+EC3BhlIgyp/2jDIyBLS6k3UxPI=" crossorigin="anonymous"></script><!-- headroom.js --><script src="https://cdnjs.cloudflare.com/ajax/libs/headroom/0.11.0/headroom.min.js" integrity="sha256-AsUX4SJE1+yuDu5+mAVzJbuYNPHj/WroHuZ8Ir/CkE0=" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/headroom/0.11.0/jQuery.headroom.min.js" integrity="sha256-ZX/yNShbjqsohH1k95liqY9Gd8uOiE1S4vZc+9KQ1K4=" crossorigin="anonymous"></script><!-- pkgdown --><link href="../pkgdown.css" rel="stylesheet">
<script src="../pkgdown.js"></script><meta property="og:title" content="Multivariate Elastic Net Regression">
<meta property="og:description" content="joinet">
<!-- mathjax --><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js" integrity="sha256-nvJJv9wWKEm88qvoQl9ekL2J+k/RWIsaSScxxlsrv8k=" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/config/TeX-AMS-MML_HTMLorMML.js" integrity="sha256-84DKXVJXs0/F8OTMzX4UR909+jtl4G7SPypPavF+GfA=" crossorigin="anonymous"></script><!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body data-spy="scroll" data-target="#toc">
    <div class="container template-article">
      <header><div class="navbar navbar-default navbar-fixed-top" role="navigation">
  <div class="container">
    <div class="navbar-header">
      <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false">
        <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
      <span class="navbar-brand">
        <a class="navbar-link" href="../index.html">joinet</a>
Armin Rauschenberger's avatar
Armin Rauschenberger committed
34
        <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">0.0.8</span>
Armin Rauschenberger's avatar
Armin Rauschenberger committed
35
36
37
38
39
40
41
42
43
44
45
46
47
48
      </span>
    </div>

    <div id="navbar" class="navbar-collapse collapse">
      <ul class="nav navbar-nav">
<li>
  <a href="../reference/index.html">functions</a>
</li>
<li>
  <a href="../articles/joinet.html">vignette</a>
</li>
<li>
  <a href="../articles/article.html">article</a>
</li>
Armin Rauschenberger's avatar
Armin Rauschenberger committed
49
50
51
<li>
  <a href="../articles/script.html">script</a>
</li>
Armin Rauschenberger's avatar
Armin Rauschenberger committed
52
53
54
55
56
57
58
<li>
  <a href="../news/index.html">news</a>
</li>
      </ul>
<ul class="nav navbar-nav navbar-right">
<li>
  <a href="https://github.com/rauschenberger/joinet">
Armin Rauschenberger's avatar
Armin Rauschenberger committed
59
    <span class="fas fa-github"></span>
Armin Rauschenberger's avatar
Armin Rauschenberger committed
60
61
62
63
64
     
  </a>
</li>
<li>
  <a href="https://cran.r-project.org/package=joinet">
Armin Rauschenberger's avatar
Armin Rauschenberger committed
65
    <span class="fas fa-download"></span>
Armin Rauschenberger's avatar
Armin Rauschenberger committed
66
67
68
69
70
71
72
73
74
75
76
77
78
     
  </a>
</li>
      </ul>
</div>
<!--/.nav-collapse -->
  </div>
<!--/.container -->
</div>
<!--/.navbar -->

      

Armin Rauschenberger's avatar
Armin Rauschenberger committed
79
      </header><script src="joinet_files/header-attrs-2.8/header-attrs.js"></script><div class="row">
Armin Rauschenberger's avatar
Armin Rauschenberger committed
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
  <div class="col-md-9 contents">
    <div class="page-header toc-ignore">
      <h1 data-toc-skip>Multivariate Elastic Net Regression</h1>
            
      
      <small class="dont-index">Source: <a href="https://github.com/rauschenberger/joinet/blob/master/vignettes/joinet.Rmd"><code>vignettes/joinet.Rmd</code></a></small>
      <div class="hidden name"><code>joinet.Rmd</code></div>

    </div>

    
    
<div id="installation" class="section level2">
<h2 class="hasAnchor">
<a href="#installation" class="anchor"></a>Installation</h2>
<p>Install the current release from <a href="https://CRAN.R-project.org/package=joinet">CRAN</a>:</p>
Armin Rauschenberger's avatar
Armin Rauschenberger committed
96
97
<div class="sourceCode" id="cb1"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="fu"><a href="https://rdrr.io/r/utils/install.packages.html">install.packages</a></span><span class="op">(</span><span class="st">"joinet"</span><span class="op">)</span></code></pre></div>
Armin Rauschenberger's avatar
Armin Rauschenberger committed
98
<p>Or install the latest development version from <a href="https://github.com/rauschenberger/joinet">GitHub</a>:</p>
Armin Rauschenberger's avatar
Armin Rauschenberger committed
99
100
101
<div class="sourceCode" id="cb2"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="co">#install.packages("devtools")</span>
<span class="fu">devtools</span><span class="fu">::</span><span class="fu"><a href="https://devtools.r-lib.org//reference/remote-reexports.html">install_github</a></span><span class="op">(</span><span class="st">"rauschenberger/joinet"</span><span class="op">)</span></code></pre></div>
Armin Rauschenberger's avatar
Armin Rauschenberger committed
102
103
104
105
106
</div>
<div id="initialisation" class="section level2">
<h2 class="hasAnchor">
<a href="#initialisation" class="anchor"></a>Initialisation</h2>
<p>Load and attach the package:</p>
Armin Rauschenberger's avatar
Armin Rauschenberger committed
107
108
<div class="sourceCode" id="cb3"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="kw"><a href="https://rdrr.io/r/base/library.html">library</a></span><span class="op">(</span><span class="va"><a href="https://github.com/rauschenberger/joinet">joinet</a></span><span class="op">)</span></code></pre></div>
Armin Rauschenberger's avatar
Armin Rauschenberger committed
109
<p>And access the <a href="https://rauschenberger.github.io/joinet/">documentation</a>:</p>
Armin Rauschenberger's avatar
Armin Rauschenberger committed
110
111
112
113
<div class="sourceCode" id="cb4"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="op">?</span><span class="va">joinet</span>
<span class="fu"><a href="https://rdrr.io/r/utils/help.html">help</a></span><span class="op">(</span><span class="va">joinet</span><span class="op">)</span>
<span class="fu"><a href="https://rdrr.io/r/utils/browseVignettes.html">browseVignettes</a></span><span class="op">(</span><span class="st">"joinet"</span><span class="op">)</span></code></pre></div>
Armin Rauschenberger's avatar
Armin Rauschenberger committed
114
115
116
117
118
</div>
<div id="simulation" class="section level2">
<h2 class="hasAnchor">
<a href="#simulation" class="anchor"></a>Simulation</h2>
<p>For <code>n</code> samples, we simulate <code>p</code> inputs (features, covariates) and <code>q</code> outputs (outcomes, responses). We assume high-dimensional inputs (<code>p</code> <span class="math inline">\(\gg\)</span> <code>n</code>) and low-dimensional outputs (<code>q</code> <span class="math inline">\(\ll\)</span> <code>n</code>).</p>
Armin Rauschenberger's avatar
Armin Rauschenberger committed
119
120
121
122
<div class="sourceCode" id="cb5"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="va">n</span> <span class="op">&lt;-</span> <span class="fl">100</span>
<span class="va">q</span> <span class="op">&lt;-</span> <span class="fl">2</span>
<span class="va">p</span> <span class="op">&lt;-</span> <span class="fl">500</span></code></pre></div>
Armin Rauschenberger's avatar
Armin Rauschenberger committed
123
<p>We simulate the <code>p</code> inputs from a multivariate normal distribution. For the mean, we use the <code>p</code>-dimensional vector <code>mu</code>, where all elements equal zero. For the covariance, we use the <code>p</code> <span class="math inline">\(\times\)</span> <code>p</code> matrix <code>Sigma</code>, where the entry in row <span class="math inline">\(i\)</span> and column <span class="math inline">\(j\)</span> equals <code>rho</code><span class="math inline">\(^{|i-j|}\)</span>. The parameter <code>rho</code> determines the strength of the correlation among the inputs, with small <code>rho</code> leading weak correlations, and large <code>rho</code> leading to strong correlations (0 &lt; <code>rho</code> &lt; 1). The input matrix <code>X</code> has <code>n</code> rows and <code>p</code> columns.</p>
Armin Rauschenberger's avatar
Armin Rauschenberger committed
124
125
126
127
128
<div class="sourceCode" id="cb6"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="va">mu</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/rep.html">rep</a></span><span class="op">(</span><span class="fl">0</span>,times<span class="op">=</span><span class="va">p</span><span class="op">)</span>
<span class="va">rho</span> <span class="op">&lt;-</span> <span class="fl">0.90</span>
<span class="va">Sigma</span> <span class="op">&lt;-</span> <span class="va">rho</span><span class="op">^</span><span class="fu"><a href="https://rdrr.io/r/base/MathFun.html">abs</a></span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/base/col.html">col</a></span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/base/diag.html">diag</a></span><span class="op">(</span><span class="va">p</span><span class="op">)</span><span class="op">)</span><span class="op">-</span><span class="fu"><a href="https://rdrr.io/r/base/row.html">row</a></span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/base/diag.html">diag</a></span><span class="op">(</span><span class="va">p</span><span class="op">)</span><span class="op">)</span><span class="op">)</span>
<span class="va">X</span> <span class="op">&lt;-</span> <span class="fu">MASS</span><span class="fu">::</span><span class="fu"><a href="https://rdrr.io/pkg/MASS/man/mvrnorm.html">mvrnorm</a></span><span class="op">(</span>n<span class="op">=</span><span class="va">n</span>,mu<span class="op">=</span><span class="va">mu</span>,Sigma<span class="op">=</span><span class="va">Sigma</span><span class="op">)</span></code></pre></div>
Armin Rauschenberger's avatar
Armin Rauschenberger committed
129
<p>We simulate the input-output effects from independent Bernoulli distributions. The parameter <code>pi</code> determines the number of effects, with small <code>pi</code> leading to few effects, and large <code>pi</code> leading to many effects (0 &lt; <code>pi</code> &lt; 1). The scalar <code>alpha</code> represents the intercept, and the <code>p</code>-dimensional vector <code>beta</code> represents the slopes.</p>
Armin Rauschenberger's avatar
Armin Rauschenberger committed
130
131
132
133
<div class="sourceCode" id="cb7"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="va">pi</span> <span class="op">&lt;-</span> <span class="fl">0.01</span>
<span class="va">alpha</span> <span class="op">&lt;-</span> <span class="fl">0</span>
<span class="va">beta</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/stats/Binomial.html">rbinom</a></span><span class="op">(</span>n<span class="op">=</span><span class="va">p</span>,size<span class="op">=</span><span class="fl">1</span>,prob<span class="op">=</span><span class="va">pi</span><span class="op">)</span></code></pre></div>
Armin Rauschenberger's avatar
Armin Rauschenberger committed
134
<p>From the intercept <code>alpha</code>, the slopes <code>beta</code> and the inputs <code>X</code>, we calculate the linear predictor, the <code>n</code>-dimensional vector <code>eta</code>. Rescale the linear predictor to make the effects weaker or stronger. Set the argument <code>family</code> to <code>"gaussian"</code>, <code>"binomial"</code>, or <code>"poisson"</code> to define the distribution. The <code>n</code> times <code>p</code> matrix <code>Y</code> represents the outputs. We assume the outcomes are <em>positively</em> correlated.</p>
Armin Rauschenberger's avatar
Armin Rauschenberger committed
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
<div class="sourceCode" id="cb8"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="va">eta</span> <span class="op">&lt;-</span> <span class="va">alpha</span> <span class="op">+</span> <span class="va">X</span> <span class="op">%*%</span> <span class="va">beta</span>
<span class="va">eta</span> <span class="op">&lt;-</span> <span class="fl">1.5</span><span class="op">*</span><span class="fu"><a href="https://rdrr.io/r/base/scale.html">scale</a></span><span class="op">(</span><span class="va">eta</span><span class="op">)</span>
<span class="va">family</span> <span class="op">&lt;-</span> <span class="st">"gaussian"</span>

<span class="kw">if</span><span class="op">(</span><span class="va">family</span><span class="op">==</span><span class="st">"gaussian"</span><span class="op">)</span><span class="op">{</span>
  <span class="va">mean</span> <span class="op">&lt;-</span> <span class="va">eta</span>
  <span class="va">Y</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/lapply.html">replicate</a></span><span class="op">(</span>n<span class="op">=</span><span class="va">q</span>,expr<span class="op">=</span><span class="fu"><a href="https://rdrr.io/r/stats/Normal.html">rnorm</a></span><span class="op">(</span>n<span class="op">=</span><span class="va">n</span>,mean<span class="op">=</span><span class="va">mean</span><span class="op">)</span><span class="op">)</span>
<span class="op">}</span>

<span class="kw">if</span><span class="op">(</span><span class="va">family</span><span class="op">==</span><span class="st">"binomial"</span><span class="op">)</span><span class="op">{</span>
  <span class="va">prob</span> <span class="op">&lt;-</span> <span class="fl">1</span><span class="op">/</span><span class="op">(</span><span class="fl">1</span><span class="op">+</span><span class="fu"><a href="https://rdrr.io/r/base/Log.html">exp</a></span><span class="op">(</span><span class="op">-</span><span class="va">eta</span><span class="op">)</span><span class="op">)</span>
  <span class="va">Y</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/lapply.html">replicate</a></span><span class="op">(</span>n<span class="op">=</span><span class="va">q</span>,expr<span class="op">=</span><span class="fu"><a href="https://rdrr.io/r/stats/Binomial.html">rbinom</a></span><span class="op">(</span>n<span class="op">=</span><span class="va">n</span>,size<span class="op">=</span><span class="fl">1</span>,prob<span class="op">=</span><span class="va">prob</span><span class="op">)</span><span class="op">)</span>
<span class="op">}</span>

<span class="kw">if</span><span class="op">(</span><span class="va">family</span><span class="op">==</span><span class="st">"poisson"</span><span class="op">)</span><span class="op">{</span>
  <span class="va">lambda</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/Log.html">exp</a></span><span class="op">(</span><span class="va">eta</span><span class="op">)</span>
  <span class="va">Y</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/lapply.html">replicate</a></span><span class="op">(</span>n<span class="op">=</span><span class="va">q</span>,expr<span class="op">=</span><span class="fu"><a href="https://rdrr.io/r/stats/Poisson.html">rpois</a></span><span class="op">(</span>n<span class="op">=</span><span class="va">n</span>,lambda<span class="op">=</span><span class="va">lambda</span><span class="op">)</span><span class="op">)</span>
<span class="op">}</span>

<span class="fu"><a href="https://rdrr.io/r/stats/cor.html">cor</a></span><span class="op">(</span><span class="va">Y</span><span class="op">)</span></code></pre></div>
Armin Rauschenberger's avatar
Armin Rauschenberger committed
156
157
158
159
160
</div>
<div id="application" class="section level2">
<h2 class="hasAnchor">
<a href="#application" class="anchor"></a>Application</h2>
<p>The function <code>joinet</code> fits univariate and multivariate regression. Set the argument <code>alpha.base</code> to 0 (ridge) or 1 (lasso).</p>
Armin Rauschenberger's avatar
Armin Rauschenberger committed
161
162
<div class="sourceCode" id="cb9"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="va">object</span> <span class="op">&lt;-</span> <span class="fu"><a href="../reference/joinet.html">joinet</a></span><span class="op">(</span>Y<span class="op">=</span><span class="va">Y</span>,X<span class="op">=</span><span class="va">X</span>,family<span class="op">=</span><span class="va">family</span><span class="op">)</span></code></pre></div>
Armin Rauschenberger's avatar
Armin Rauschenberger committed
163
<p>Standard methods are available. The function <code>predict</code> returns the predicted values from the univariate (<code>base</code>) and multivariate (<code>meta</code>) models. The function <code>coef</code> returns the estimated intercepts (<code>alpha</code>) and slopes (<code>beta</code>) from the multivariate model (input-output effects). And the function <code>weights</code> returns the weights from stacking (output-output effects).</p>
Armin Rauschenberger's avatar
Armin Rauschenberger committed
164
165
<div class="sourceCode" id="cb10"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="fu"><a href="https://rdrr.io/r/stats/predict.html">predict</a></span><span class="op">(</span><span class="va">object</span>,newx<span class="op">=</span><span class="va">X</span><span class="op">)</span>
Armin Rauschenberger's avatar
Armin Rauschenberger committed
166

Armin Rauschenberger's avatar
Armin Rauschenberger committed
167
<span class="fu"><a href="https://rdrr.io/r/stats/coef.html">coef</a></span><span class="op">(</span><span class="va">object</span><span class="op">)</span>
Armin Rauschenberger's avatar
Armin Rauschenberger committed
168

Armin Rauschenberger's avatar
Armin Rauschenberger committed
169
<span class="fu"><a href="https://rdrr.io/r/stats/weights.html">weights</a></span><span class="op">(</span><span class="va">object</span><span class="op">)</span></code></pre></div>
Armin Rauschenberger's avatar
Armin Rauschenberger committed
170
<p>The function <code>cv.joinet</code> compares the predictive performance of univariate (<code>base</code>) and multivariate (<code>meta</code>) regression by nested cross-validation. The argument <code>type.measure</code> determines the loss function.</p>
Armin Rauschenberger's avatar
Armin Rauschenberger committed
171
172
<div class="sourceCode" id="cb11"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="fu"><a href="../reference/cv.joinet.html">cv.joinet</a></span><span class="op">(</span>Y<span class="op">=</span><span class="va">Y</span>,X<span class="op">=</span><span class="va">X</span>,family<span class="op">=</span><span class="va">family</span><span class="op">)</span></code></pre></div>
Armin Rauschenberger's avatar
Armin Rauschenberger committed
173
174
175
176
177
178
179
180
181
<pre><code>##           [,1]     [,2]
## base  1.204741 1.523550
## meta  1.185200 1.278125
## FALSE       NA       NA
## none  3.206394 3.495571</code></pre>
</div>
<div id="reference" class="section level2">
<h2 class="hasAnchor">
<a href="#reference" class="anchor"></a>Reference</h2>
Armin Rauschenberger's avatar
Armin Rauschenberger committed
182
<p>Armin Rauschenberger and Enrico Glaab (2021). “Predicting correlated outcomes from molecular data”. <em>Manuscript in preparation.</em></p>
Armin Rauschenberger's avatar
Armin Rauschenberger committed
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
</div>
  </div>

  <div class="col-md-3 hidden-xs hidden-sm" id="pkgdown-sidebar">

        <nav id="toc" data-toggle="toc"><h2 data-toc-skip>Contents</h2>
    </nav>
</div>

</div>



      <footer><div class="copyright">
  <p>Developed by <a href="https://rauschenberger.github.io">Armin Rauschenberger</a>.</p>
</div>

<div class="pkgdown">
Armin Rauschenberger's avatar
Armin Rauschenberger committed
201
  <p>Site built with <a href="https://pkgdown.r-lib.org/">pkgdown</a> 1.6.1.</p>
Armin Rauschenberger's avatar
Armin Rauschenberger committed
202
203
204
205
206
207
208
209
210
211
</div>

      </footer>
</div>

  


  </body>
</html>