script.html 168 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
49
50
51
52
53
54
55
56
57
58
      </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>
<li>
  <a href="../articles/script.html">script</a>
</li>
<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="script_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
  <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/script.Rmd"><code>vignettes/script.Rmd</code></a></small>
      <div class="hidden name"><code>script.Rmd</code></div>

    </div>

    
    
Armin Rauschenberger's avatar
Armin Rauschenberger committed
92
93
94
95
96
97
98
<div class="sourceCode" id="cb1"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="va">box</span> <span class="op">&lt;-</span> <span class="kw">function</span><span class="op">(</span><span class="va">x</span>,<span class="va">y</span>,<span class="va">w</span><span class="op">=</span><span class="fl">0.2</span>,<span class="va">h</span><span class="op">=</span><span class="fl">0.2</span>,<span class="va">labels</span><span class="op">=</span><span class="st">""</span>,<span class="va">col</span><span class="op">=</span><span class="st">"black"</span>,<span class="va">turn</span><span class="op">=</span><span class="cn">FALSE</span>,<span class="va">...</span><span class="op">)</span><span class="op">{</span>
  <span class="va">xs</span> <span class="op">&lt;-</span> <span class="va">x</span> <span class="op">+</span> <span class="fl">0.5</span><span class="op">*</span><span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op">(</span><span class="op">-</span><span class="fl">1</span>,<span class="op">-</span><span class="fl">1</span>,<span class="fl">1</span>,<span class="fl">1</span><span class="op">)</span><span class="op">*</span><span class="va">w</span>
  <span class="va">ys</span> <span class="op">&lt;-</span> <span class="va">y</span> <span class="op">+</span> <span class="fl">0.5</span><span class="op">*</span><span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op">(</span><span class="op">-</span><span class="fl">1</span>,<span class="fl">1</span>,<span class="fl">1</span>,<span class="op">-</span><span class="fl">1</span><span class="op">)</span><span class="op">*</span><span class="va">h</span>
  <span class="fu">graphics</span><span class="fu">::</span><span class="fu"><a href="https://rdrr.io/r/graphics/polygon.html">polygon</a></span><span class="op">(</span>x<span class="op">=</span><span class="va">xs</span>,y<span class="op">=</span><span class="va">ys</span>,border<span class="op">=</span><span class="va">col</span>,col<span class="op">=</span><span class="fu"><a href="https://rdrr.io/r/grDevices/gray.html">grey</a></span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/base/ifelse.html">ifelse</a></span><span class="op">(</span><span class="va">col</span><span class="op">==</span><span class="st">"grey"</span>,<span class="fl">0.99</span>,<span class="fl">0.99</span><span class="op">)</span><span class="op">)</span>,lwd<span class="op">=</span><span class="fl">2</span>,<span class="va">...</span><span class="op">)</span>
  <span class="fu">graphics</span><span class="fu">::</span><span class="fu"><a href="https://rdrr.io/r/graphics/text.html">text</a></span><span class="op">(</span>x<span class="op">=</span><span class="va">x</span>,y<span class="op">=</span><span class="va">y</span>,labels<span class="op">=</span><span class="va">labels</span>,col<span class="op">=</span><span class="va">col</span>,srt<span class="op">=</span><span class="fu"><a href="https://rdrr.io/r/base/ifelse.html">ifelse</a></span><span class="op">(</span><span class="va">turn</span>,<span class="fl">90</span>,<span class="fl">0</span><span class="op">)</span><span class="op">)</span>
<span class="op">}</span>
Armin Rauschenberger's avatar
Armin Rauschenberger committed
99

Armin Rauschenberger's avatar
Armin Rauschenberger committed
100
<span class="co">#grDevices::pdf(file="manuscript/figure_ABS.pdf",width=4,height=2.5)</span>
Armin Rauschenberger's avatar
Armin Rauschenberger committed
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
<span class="fu">grDevices</span><span class="fu">::</span><span class="fu"><a href="https://rdrr.io/r/grDevices/ps.options.html">setEPS</a></span><span class="op">(</span><span class="op">)</span>
<span class="fu">grDevices</span><span class="fu">::</span><span class="fu"><a href="https://rdrr.io/r/grDevices/postscript.html">postscript</a></span><span class="op">(</span>file<span class="op">=</span><span class="st">"manuscript/figure_ABS.eps"</span>,width<span class="op">=</span><span class="fl">4</span>,height<span class="op">=</span><span class="fl">2.5</span><span class="op">)</span>
<span class="fu">graphics</span><span class="fu">::</span><span class="fu"><a href="https://rdrr.io/r/graphics/par.html">par</a></span><span class="op">(</span>mar<span class="op">=</span><span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op">(</span><span class="fl">0</span>,<span class="fl">0</span>,<span class="fl">0</span>,<span class="fl">0</span><span class="op">)</span><span class="op">)</span>
<span class="fu">graphics</span><span class="fu">::</span><span class="fu"><a href="https://rdrr.io/r/graphics/frame.html">plot.new</a></span><span class="op">(</span><span class="op">)</span>
<span class="fu">graphics</span><span class="fu">::</span><span class="fu"><a href="https://rdrr.io/r/graphics/plot.window.html">plot.window</a></span><span class="op">(</span>xlim<span class="op">=</span><span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op">(</span><span class="fl">0</span>,<span class="fl">2</span><span class="op">)</span>,ylim<span class="op">=</span><span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op">(</span><span class="op">-</span><span class="fl">0.1</span>,<span class="fl">1.1</span><span class="op">)</span><span class="op">)</span>

<span class="va">n</span> <span class="op">&lt;-</span> <span class="fl">0.45</span>; <span class="va">p</span> <span class="op">&lt;-</span> <span class="fl">0.4</span>; <span class="va">q</span> <span class="op">&lt;-</span> <span class="fl">0.4</span>
<span class="va">h</span> <span class="op">&lt;-</span> <span class="va">w</span> <span class="op">&lt;-</span> <span class="fl">0.4</span>

<span class="va">y0</span> <span class="op">&lt;-</span> <span class="fl">0.10</span>; <span class="va">y1</span> <span class="op">&lt;-</span> <span class="fl">0.50</span>; <span class="va">y2</span> <span class="op">&lt;-</span> <span class="fl">0.90</span>
<span class="va">x0</span> <span class="op">&lt;-</span> <span class="fl">0.20</span>; <span class="va">x1</span> <span class="op">&lt;-</span> <span class="fl">1.00</span>; <span class="va">x2</span> <span class="op">&lt;-</span> <span class="fl">1.80</span>
<span class="va">y</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/seq.html">seq</a></span><span class="op">(</span>from<span class="op">=</span><span class="fl">1</span>,to<span class="op">=</span><span class="fl">0</span>,length.out<span class="op">=</span><span class="fl">5</span><span class="op">)</span>

<span class="va">w</span> <span class="op">&lt;-</span> <span class="fl">0.15</span>
<span class="va">d</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/seq.html">seq</a></span><span class="op">(</span>from<span class="op">=</span><span class="fl">0.06</span>,to<span class="op">=</span><span class="op">-</span><span class="fl">0.06</span>,length.out<span class="op">=</span><span class="fl">4</span><span class="op">)</span><span class="op">[</span><span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op">(</span><span class="fl">1</span>,<span class="fl">2</span>,<span class="fl">3</span>,<span class="cn">Inf</span>,<span class="fl">4</span><span class="op">)</span><span class="op">]</span>
<span class="kw">for</span><span class="op">(</span><span class="va">i</span> <span class="kw">in</span> <span class="fl">1</span><span class="op">:</span><span class="fl">5</span><span class="op">)</span><span class="op">{</span>
  <span class="kw">if</span><span class="op">(</span><span class="va">i</span><span class="op">==</span><span class="fl">4</span><span class="op">)</span><span class="op">{</span><span class="fu">graphics</span><span class="fu">::</span><span class="fu"><a href="https://rdrr.io/r/graphics/text.html">text</a></span><span class="op">(</span>x<span class="op">=</span><span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op">(</span><span class="va">x1</span>,<span class="va">x2</span><span class="op">)</span>,y<span class="op">=</span><span class="va">y</span><span class="op">[</span><span class="fl">4</span><span class="op">]</span>,labels<span class="op">=</span><span class="st">"..."</span>,srt<span class="op">=</span><span class="fl">90</span>,font<span class="op">=</span><span class="fl">2</span>,cex<span class="op">=</span><span class="fl">1.2</span><span class="op">)</span>;<span class="kw">next</span><span class="op">}</span>
  <span class="fu">graphics</span><span class="fu">::</span><span class="fu"><a href="https://rdrr.io/r/graphics/arrows.html">arrows</a></span><span class="op">(</span>x0<span class="op">=</span><span class="va">x0</span><span class="op">+</span><span class="va">p</span><span class="op">/</span><span class="fl">2</span>,x1<span class="op">=</span><span class="va">x1</span><span class="op">-</span><span class="va">q</span><span class="op">/</span><span class="fl">2</span><span class="op">-</span><span class="fl">0.02</span>,y0<span class="op">=</span><span class="va">y1</span>,y1<span class="op">=</span><span class="va">y</span><span class="op">[</span><span class="va">i</span><span class="op">]</span>,lwd<span class="op">=</span><span class="fl">2</span>,length<span class="op">=</span><span class="fl">0.1</span>,col<span class="op">=</span><span class="st">"grey"</span><span class="op">)</span>
  <span class="va">labels</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/paste.html">paste</a></span><span class="op">(</span><span class="st">"target"</span>,<span class="fu"><a href="https://rdrr.io/r/base/ifelse.html">ifelse</a></span><span class="op">(</span><span class="va">i</span><span class="op">==</span><span class="fl">5</span>,<span class="st">"q"</span>,<span class="va">i</span><span class="op">)</span><span class="op">)</span>
  <span class="kw">for</span><span class="op">(</span><span class="va">j</span> <span class="kw">in</span> <span class="fl">1</span><span class="op">:</span><span class="fl">5</span><span class="op">)</span><span class="op">{</span>
    <span class="kw">if</span><span class="op">(</span><span class="va">j</span><span class="op">==</span><span class="fl">4</span><span class="op">)</span><span class="op">{</span><span class="kw">next</span><span class="op">}</span>
      <span class="fu">graphics</span><span class="fu">::</span><span class="fu"><a href="https://rdrr.io/r/graphics/arrows.html">arrows</a></span><span class="op">(</span>x0<span class="op">=</span><span class="va">x1</span><span class="op">+</span><span class="va">p</span><span class="op">/</span><span class="fl">2</span>,x1<span class="op">=</span><span class="va">x2</span><span class="op">-</span><span class="va">q</span><span class="op">/</span><span class="fl">2</span><span class="op">-</span><span class="fl">0.02</span>,y0<span class="op">=</span><span class="va">y</span><span class="op">[</span><span class="va">i</span><span class="op">]</span>,y1<span class="op">=</span><span class="va">y</span><span class="op">[</span><span class="va">j</span><span class="op">]</span><span class="op">+</span><span class="va">d</span><span class="op">[</span><span class="va">i</span><span class="op">]</span>,lwd<span class="op">=</span><span class="fl">2</span>,length<span class="op">=</span><span class="fl">0.1</span>,col<span class="op">=</span><span class="fu"><a href="https://rdrr.io/r/base/ifelse.html">ifelse</a></span><span class="op">(</span><span class="va">i</span><span class="op">==</span><span class="va">j</span>,<span class="st">"grey"</span>,<span class="st">"grey"</span><span class="op">)</span><span class="op">)</span>
  <span class="op">}</span>
  <span class="fu"><a href="https://rdrr.io/r/graphics/box.html">box</a></span><span class="op">(</span>x<span class="op">=</span><span class="va">x1</span>,y<span class="op">=</span><span class="va">y</span><span class="op">[</span><span class="va">i</span><span class="op">]</span>,h<span class="op">=</span><span class="fl">0.5</span><span class="op">*</span><span class="va">h</span>,w<span class="op">=</span><span class="va">q</span>,labels<span class="op">=</span><span class="va">labels</span><span class="op">)</span>
  <span class="fu"><a href="https://rdrr.io/r/graphics/box.html">box</a></span><span class="op">(</span>x<span class="op">=</span><span class="va">x2</span>,y<span class="op">=</span><span class="va">y</span><span class="op">[</span><span class="va">i</span><span class="op">]</span>,h<span class="op">=</span><span class="fl">0.5</span><span class="op">*</span><span class="va">h</span>,w<span class="op">=</span><span class="va">q</span>,labels<span class="op">=</span><span class="va">labels</span><span class="op">)</span>
<span class="op">}</span>
<span class="fu"><a href="https://rdrr.io/r/graphics/box.html">box</a></span><span class="op">(</span>x<span class="op">=</span><span class="va">x0</span>,y<span class="op">=</span><span class="va">y1</span>,h<span class="op">=</span><span class="fl">0.5</span><span class="op">*</span><span class="va">h</span>,w<span class="op">=</span><span class="va">p</span>,labels<span class="op">=</span><span class="st">"features"</span><span class="op">)</span>

<span class="fu">grDevices</span><span class="fu">::</span><span class="fu"><a href="https://rdrr.io/r/grDevices/dev.html">dev.off</a></span><span class="op">(</span><span class="op">)</span></code></pre></div>
<div class="sourceCode" id="cb2"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="co">#grDevices::pdf(file="manuscript/figure_OUT.pdf",width=5,height=3)</span>
<span class="fu">grDevices</span><span class="fu">::</span><span class="fu"><a href="https://rdrr.io/r/grDevices/postscript.html">postscript</a></span><span class="op">(</span>file<span class="op">=</span><span class="st">"manuscript/figure_OUT.eps"</span>,width<span class="op">=</span><span class="fl">5</span>,height<span class="op">=</span><span class="fl">3</span><span class="op">)</span>

<span class="va">ellipse</span> <span class="op">&lt;-</span> <span class="kw">function</span><span class="op">(</span><span class="va">x</span>,<span class="va">y</span>,<span class="va">text</span><span class="op">=</span><span class="cn">NULL</span>,<span class="va">a</span><span class="op">=</span><span class="fl">0.5</span>,<span class="va">b</span><span class="op">=</span><span class="fl">0.5</span>,<span class="va">border</span><span class="op">=</span><span class="st">"black"</span>,<span class="va">col</span><span class="op">=</span><span class="cn">NULL</span>,<span class="va">txt.col</span><span class="op">=</span><span class="st">"black"</span>,<span class="va">...</span><span class="op">)</span><span class="op">{</span>
    <span class="va">n</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/Extremes.html">max</a></span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/base/length.html">length</a></span><span class="op">(</span><span class="va">x</span><span class="op">)</span>,<span class="fu"><a href="https://rdrr.io/r/base/length.html">length</a></span><span class="op">(</span><span class="va">y</span><span class="op">)</span><span class="op">)</span><span class="op">)</span>
    <span class="kw">if</span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/base/NULL.html">is.null</a></span><span class="op">(</span><span class="va">col</span><span class="op">)</span><span class="op">)</span><span class="op">{</span><span class="va">col</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="fu"><a href="https://rdrr.io/r/grDevices/gray.html">grey</a></span><span class="op">(</span><span class="fl">0.9</span><span class="op">)</span>,times<span class="op">=</span><span class="va">n</span><span class="op">)</span><span class="op">}</span>
    <span class="kw">if</span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/base/length.html">length</a></span><span class="op">(</span><span class="va">col</span><span class="op">)</span><span class="op">==</span><span class="fl">1</span><span class="op">)</span><span class="op">{</span><span class="va">col</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="va">col</span>,times<span class="op">=</span><span class="va">n</span><span class="op">)</span><span class="op">}</span>
    <span class="kw">if</span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/base/length.html">length</a></span><span class="op">(</span><span class="va">x</span><span class="op">)</span><span class="op">==</span><span class="fl">1</span><span class="op">)</span><span class="op">{</span><span class="va">x</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="va">x</span>,times<span class="op">=</span><span class="va">n</span><span class="op">)</span><span class="op">}</span>
    <span class="kw">if</span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/base/length.html">length</a></span><span class="op">(</span><span class="va">y</span><span class="op">)</span><span class="op">==</span><span class="fl">1</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/rep.html">rep</a></span><span class="op">(</span><span class="va">y</span>,times<span class="op">=</span><span class="va">n</span><span class="op">)</span><span class="op">}</span>
    <span class="kw">if</span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/base/length.html">length</a></span><span class="op">(</span><span class="va">text</span><span class="op">)</span><span class="op">==</span><span class="fl">1</span><span class="op">)</span><span class="op">{</span><span class="va">text</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="va">text</span>,times<span class="op">=</span><span class="va">n</span><span class="op">)</span><span class="op">}</span>
    <span class="kw">if</span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/base/length.html">length</a></span><span class="op">(</span><span class="va">border</span><span class="op">)</span><span class="op">==</span><span class="fl">1</span><span class="op">)</span><span class="op">{</span><span class="va">border</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="va">border</span>,times<span class="op">=</span><span class="va">n</span><span class="op">)</span><span class="op">}</span>
    <span class="kw">for</span><span class="op">(</span><span class="va">i</span> <span class="kw">in</span> <span class="fu"><a href="https://rdrr.io/r/base/seq.html">seq_len</a></span><span class="op">(</span><span class="va">n</span><span class="op">)</span><span class="op">)</span><span class="op">{</span>
        <span class="va">angle</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/seq.html">seq</a></span><span class="op">(</span>from<span class="op">=</span><span class="fl">0</span>,to<span class="op">=</span><span class="fl">2</span><span class="op">*</span><span class="va">pi</span>,length<span class="op">=</span><span class="fl">100</span><span class="op">)</span>
        <span class="va">xs</span> <span class="op">&lt;-</span> <span class="va">x</span><span class="op">[</span><span class="va">i</span><span class="op">]</span> <span class="op">+</span> <span class="va">a</span> <span class="op">*</span> <span class="fu"><a href="https://rdrr.io/r/base/Trig.html">cos</a></span><span class="op">(</span><span class="va">angle</span><span class="op">)</span>
        <span class="va">ys</span> <span class="op">&lt;-</span> <span class="va">y</span><span class="op">[</span><span class="va">i</span><span class="op">]</span> <span class="op">+</span> <span class="va">b</span> <span class="op">*</span> <span class="fu"><a href="https://rdrr.io/r/base/Trig.html">sin</a></span><span class="op">(</span><span class="va">angle</span><span class="op">)</span>
        <span class="fu">graphics</span><span class="fu">::</span><span class="fu"><a href="https://rdrr.io/r/graphics/polygon.html">polygon</a></span><span class="op">(</span>x<span class="op">=</span><span class="va">xs</span>,y<span class="op">=</span><span class="va">ys</span>,col<span class="op">=</span><span class="va">col</span><span class="op">[</span><span class="va">i</span><span class="op">]</span>,border<span class="op">=</span><span class="va">border</span><span class="op">[</span><span class="va">i</span><span class="op">]</span><span class="op">)</span>
        <span class="fu">graphics</span><span class="fu">::</span><span class="fu"><a href="https://rdrr.io/r/graphics/text.html">text</a></span><span class="op">(</span>labels<span class="op">=</span><span class="va">text</span><span class="op">[</span><span class="va">i</span><span class="op">]</span>,x<span class="op">=</span><span class="va">x</span><span class="op">[</span><span class="va">i</span><span class="op">]</span>,y<span class="op">=</span><span class="va">y</span><span class="op">[</span><span class="va">i</span><span class="op">]</span>,col<span class="op">=</span><span class="va">txt.col</span>,<span class="va">...</span><span class="op">)</span>
    <span class="op">}</span>
<span class="op">}</span>

<span class="va">txt</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/list.html">list</a></span><span class="op">(</span><span class="op">)</span>
<span class="va">txt</span><span class="op">$</span><span class="va">x</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/expression.html">expression</a></span><span class="op">(</span><span class="va">x</span><span class="op">[</span><span class="va">j</span><span class="op">]</span><span class="op">)</span>
<span class="va">txt</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/eval.html">eval</a></span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/base/parse.html">parse</a></span><span class="op">(</span>text<span class="op">=</span><span class="fu"><a href="https://rdrr.io/r/base/paste.html">paste0</a></span><span class="op">(</span><span class="st">"expression("</span>,<span class="fu"><a href="https://rdrr.io/r/base/paste.html">paste0</a></span><span class="op">(</span><span class="st">"y["</span>,<span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op">(</span><span class="fl">1</span><span class="op">:</span><span class="fl">3</span>,<span class="st">"k"</span>,<span class="st">"q"</span><span class="op">)</span>,<span class="st">"]"</span>,collapse<span class="op">=</span><span class="st">","</span><span class="op">)</span>,<span class="st">")"</span><span class="op">)</span><span class="op">)</span><span class="op">)</span>
<span class="va">txt</span><span class="op">$</span><span class="va">beta</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/eval.html">eval</a></span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/base/parse.html">parse</a></span><span class="op">(</span>text<span class="op">=</span><span class="fu"><a href="https://rdrr.io/r/base/paste.html">paste0</a></span><span class="op">(</span><span class="st">"expression("</span>,<span class="fu"><a href="https://rdrr.io/r/base/paste.html">paste0</a></span><span class="op">(</span><span class="st">"beta[j"</span>,<span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op">(</span><span class="fl">1</span><span class="op">:</span><span class="fl">3</span>,<span class="st">"k"</span>,<span class="st">"q"</span><span class="op">)</span>,<span class="st">"]"</span>,collapse<span class="op">=</span><span class="st">","</span><span class="op">)</span>,<span class="st">")"</span><span class="op">)</span><span class="op">)</span><span class="op">)</span>
<span class="va">txt</span><span class="op">$</span><span class="va">omega</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/eval.html">eval</a></span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/base/parse.html">parse</a></span><span class="op">(</span>text<span class="op">=</span><span class="fu"><a href="https://rdrr.io/r/base/paste.html">paste0</a></span><span class="op">(</span><span class="st">"expression("</span>,<span class="fu"><a href="https://rdrr.io/r/base/paste.html">paste0</a></span><span class="op">(</span><span class="st">"omega[\""</span>,<span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op">(</span><span class="fl">1</span><span class="op">:</span><span class="fl">3</span>,<span class="st">"k"</span>,<span class="st">"q"</span><span class="op">)</span>,<span class="st">"k\"]"</span>,collapse<span class="op">=</span><span class="st">","</span><span class="op">)</span>,<span class="st">")"</span><span class="op">)</span><span class="op">)</span><span class="op">)</span>
<span class="va">txt</span><span class="op">$</span><span class="va">dots</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/expression.html">expression</a></span><span class="op">(</span><span class="va">cdots</span><span class="op">)</span>

<span class="va">pos</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/list.html">list</a></span><span class="op">(</span><span class="op">)</span>
<span class="va">pos</span><span class="op">$</span><span class="va">x</span> <span class="op">&lt;-</span> <span class="fl">4</span>
<span class="va">pos</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/c.html">c</a></span><span class="op">(</span><span class="fl">1</span>,<span class="fl">2</span>,<span class="fl">3</span>,<span class="fl">5</span>,<span class="fl">7</span><span class="op">)</span>
<span class="va">pos</span><span class="op">$</span><span class="va">beta</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/stats/median.html">median</a></span><span class="op">(</span><span class="va">pos</span><span class="op">$</span><span class="va">x</span><span class="op">)</span><span class="op">+</span><span class="op">(</span><span class="va">pos</span><span class="op">$</span><span class="va">y</span><span class="op">-</span><span class="fu"><a href="https://rdrr.io/r/stats/median.html">median</a></span><span class="op">(</span><span class="va">pos</span><span class="op">$</span><span class="va">x</span><span class="op">)</span><span class="op">)</span><span class="op">/</span><span class="fl">2</span>
<span class="va">pos</span><span class="op">$</span><span class="va">omega</span> <span class="op">&lt;-</span> <span class="fl">5</span><span class="op">+</span><span class="op">(</span><span class="va">pos</span><span class="op">$</span><span class="va">y</span><span class="op">-</span><span class="fl">5</span><span class="op">)</span><span class="op">/</span><span class="fl">2</span>

<span class="va">a</span> <span class="op">&lt;-</span> <span class="va">b</span> <span class="op">&lt;-</span> <span class="fl">0.3</span>
<span class="fu">graphics</span><span class="fu">::</span><span class="fu"><a href="https://rdrr.io/r/graphics/frame.html">plot.new</a></span><span class="op">(</span><span class="op">)</span>
<span class="fu">graphics</span><span class="fu">::</span><span class="fu"><a href="https://rdrr.io/r/graphics/par.html">par</a></span><span class="op">(</span>mar<span class="op">=</span><span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op">(</span><span class="fl">0</span>,<span class="fl">0</span>,<span class="fl">0</span>,<span class="fl">0</span><span class="op">)</span><span class="op">)</span>
<span class="fu">graphics</span><span class="fu">::</span><span class="fu"><a href="https://rdrr.io/r/graphics/plot.window.html">plot.window</a></span><span class="op">(</span>xlim<span class="op">=</span><span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op">(</span><span class="fl">0.5</span>,<span class="fl">7.5</span><span class="op">)</span>,ylim<span class="op">=</span><span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op">(</span><span class="fl">0.5</span>,<span class="fl">5.5</span><span class="op">)</span><span class="op">)</span>
Armin Rauschenberger's avatar
Armin Rauschenberger committed
168
169

<span class="co"># beta</span>
Armin Rauschenberger's avatar
Armin Rauschenberger committed
170
171
<span class="fu"><a href="https://rdrr.io/r/graphics/segments.html">segments</a></span><span class="op">(</span>x0<span class="op">=</span><span class="fl">4</span>,y0<span class="op">=</span><span class="fl">5</span><span class="op">-</span><span class="va">a</span>,x1<span class="op">=</span><span class="va">pos</span><span class="op">$</span><span class="va">y</span>,y1<span class="op">=</span><span class="fl">3</span><span class="op">+</span><span class="va">a</span>,lwd<span class="op">=</span><span class="fl">2</span>,col<span class="op">=</span><span class="st">"blue"</span><span class="op">)</span>
<span class="fu">ellipse</span><span class="op">(</span>x<span class="op">=</span><span class="va">pos</span><span class="op">$</span><span class="va">beta</span>,y<span class="op">=</span><span class="fl">4</span>,text<span class="op">=</span><span class="va">txt</span><span class="op">$</span><span class="va">beta</span>,a<span class="op">=</span><span class="fl">0.21</span>,b<span class="op">=</span><span class="fl">0.21</span>,cex<span class="op">=</span><span class="fl">1.2</span>,col<span class="op">=</span><span class="st">"white"</span>,border<span class="op">=</span><span class="st">"white"</span>,txt.col<span class="op">=</span><span class="st">"blue"</span><span class="op">)</span>
Armin Rauschenberger's avatar
Armin Rauschenberger committed
172
173

<span class="co"># omega</span>
Armin Rauschenberger's avatar
Armin Rauschenberger committed
174
175
176
<span class="fu"><a href="https://rdrr.io/r/graphics/segments.html">segments</a></span><span class="op">(</span>x0<span class="op">=</span><span class="fu"><a href="https://rdrr.io/r/base/rep.html">rep</a></span><span class="op">(</span><span class="va">pos</span><span class="op">$</span><span class="va">y</span>,each<span class="op">=</span><span class="fl">4</span><span class="op">)</span>,y0<span class="op">=</span><span class="fl">3</span><span class="op">-</span><span class="va">a</span>,x1<span class="op">=</span><span class="fu"><a href="https://rdrr.io/r/base/rep.html">rep</a></span><span class="op">(</span><span class="va">pos</span><span class="op">$</span><span class="va">y</span>,times<span class="op">=</span><span class="fl">4</span><span class="op">)</span>,y1<span class="op">=</span><span class="fl">1</span><span class="op">+</span><span class="va">a</span>,lwd<span class="op">=</span><span class="fl">2</span>,col<span class="op">=</span><span class="st">"grey"</span><span class="op">)</span>
<span class="fu"><a href="https://rdrr.io/r/graphics/segments.html">segments</a></span><span class="op">(</span>x0<span class="op">=</span><span class="va">pos</span><span class="op">$</span><span class="va">y</span>,y0<span class="op">=</span><span class="fl">3</span><span class="op">-</span><span class="va">a</span>,y1<span class="op">=</span><span class="fl">1</span><span class="op">+</span><span class="va">a</span>,x1<span class="op">=</span><span class="fl">5</span>,lwd<span class="op">=</span><span class="fl">2</span>,col<span class="op">=</span><span class="st">"red"</span><span class="op">)</span>
<span class="fu">ellipse</span><span class="op">(</span>x<span class="op">=</span><span class="va">pos</span><span class="op">$</span><span class="va">omega</span>,y<span class="op">=</span><span class="fl">2</span>,text<span class="op">=</span><span class="va">txt</span><span class="op">$</span><span class="va">omega</span>,a<span class="op">=</span><span class="fl">0.25</span>,b<span class="op">=</span><span class="fl">0.18</span>,cex<span class="op">=</span><span class="fl">1.2</span>,col<span class="op">=</span><span class="st">"white"</span>,border<span class="op">=</span><span class="st">"white"</span>,txt.col<span class="op">=</span><span class="st">"red"</span><span class="op">)</span>
Armin Rauschenberger's avatar
Armin Rauschenberger committed
177
178

<span class="co"># x and y</span>
Armin Rauschenberger's avatar
Armin Rauschenberger committed
179
180
181
182
183
184
185
186
<span class="fu">ellipse</span><span class="op">(</span>x<span class="op">=</span><span class="va">pos</span><span class="op">$</span><span class="va">x</span>,y<span class="op">=</span><span class="fl">5</span>,text<span class="op">=</span><span class="va">txt</span><span class="op">$</span><span class="va">x</span>,a<span class="op">=</span><span class="va">a</span>,b<span class="op">=</span><span class="va">b</span>,cex<span class="op">=</span><span class="fl">1.2</span><span class="op">)</span>
<span class="fu"><a href="https://rdrr.io/r/graphics/text.html">text</a></span><span class="op">(</span>x<span class="op">=</span><span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op">(</span><span class="fl">3</span>,<span class="fl">5</span><span class="op">)</span>,y<span class="op">=</span><span class="fl">5</span>,labels<span class="op">=</span><span class="va">txt</span><span class="op">$</span><span class="va">dots</span>,cex<span class="op">=</span><span class="fl">1.2</span><span class="op">)</span>
<span class="fu">ellipse</span><span class="op">(</span>x<span class="op">=</span><span class="va">pos</span><span class="op">$</span><span class="va">y</span>,y<span class="op">=</span><span class="fl">3</span>,text<span class="op">=</span><span class="va">txt</span><span class="op">$</span><span class="va">y</span>,a<span class="op">=</span><span class="va">a</span>,b<span class="op">=</span><span class="va">b</span>,cex<span class="op">=</span><span class="fl">1.2</span><span class="op">)</span>
<span class="fu"><a href="https://rdrr.io/r/graphics/text.html">text</a></span><span class="op">(</span>x<span class="op">=</span><span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op">(</span><span class="fl">4</span>,<span class="fl">6</span><span class="op">)</span>,y<span class="op">=</span><span class="fl">3</span>,labels<span class="op">=</span><span class="va">txt</span><span class="op">$</span><span class="va">dots</span>,cex<span class="op">=</span><span class="fl">1.2</span><span class="op">)</span>
<span class="fu">ellipse</span><span class="op">(</span>x<span class="op">=</span><span class="va">pos</span><span class="op">$</span><span class="va">y</span>,y<span class="op">=</span><span class="fl">1</span>,text<span class="op">=</span><span class="va">txt</span><span class="op">$</span><span class="va">y</span>,a<span class="op">=</span><span class="va">a</span>,b<span class="op">=</span><span class="va">b</span>,cex<span class="op">=</span><span class="fl">1.2</span><span class="op">)</span>
<span class="fu"><a href="https://rdrr.io/r/graphics/text.html">text</a></span><span class="op">(</span>x<span class="op">=</span><span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op">(</span><span class="fl">4</span>,<span class="fl">6</span><span class="op">)</span>,y<span class="op">=</span><span class="fl">1</span>,labels<span class="op">=</span><span class="va">txt</span><span class="op">$</span><span class="va">dots</span>,cex<span class="op">=</span><span class="fl">1.2</span><span class="op">)</span>

<span class="fu">grDevices</span><span class="fu">::</span><span class="fu"><a href="https://rdrr.io/r/grDevices/dev.html">dev.off</a></span><span class="op">(</span><span class="op">)</span></code></pre></div>
Armin Rauschenberger's avatar
Armin Rauschenberger committed
187
188
189
<div id="simulation" class="section level1">
<h1 class="hasAnchor">
<a href="#simulation" class="anchor"></a>Simulation</h1>
Armin Rauschenberger's avatar
Armin Rauschenberger committed
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
<div class="sourceCode" id="cb3"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="co">#&lt;&lt;start&gt;&gt;</span>

<span class="va">grid</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/list.html">list</a></span><span class="op">(</span><span class="op">)</span>
<span class="va">grid</span><span class="op">$</span><span class="va">rho_x</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op">(</span><span class="fl">0.00</span>,<span class="fl">0.10</span>,<span class="fl">0.30</span><span class="op">)</span>
<span class="va">grid</span><span class="op">$</span><span class="va">rho_b</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op">(</span><span class="fl">0.00</span>,<span class="fl">0.50</span>,<span class="fl">0.90</span><span class="op">)</span>
<span class="va">delta</span> <span class="op">&lt;-</span> <span class="fl">0.8</span>
<span class="va">grid</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/expand.grid.html">expand.grid</a></span><span class="op">(</span><span class="va">grid</span><span class="op">)</span>
<span class="va">grid</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/cbind.html">rbind</a></span><span class="op">(</span><span class="va">grid</span>,<span class="va">grid</span>,<span class="va">grid</span><span class="op">)</span>
<span class="va">grid</span><span class="op">$</span><span class="va">p</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="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op">(</span><span class="fl">10</span>,<span class="fl">500</span>,<span class="fl">500</span><span class="op">)</span>,each<span class="op">=</span><span class="fu"><a href="https://rdrr.io/r/base/nrow.html">nrow</a></span><span class="op">(</span><span class="va">grid</span><span class="op">)</span><span class="op">/</span><span class="fl">3</span><span class="op">)</span>
<span class="va">grid</span><span class="op">$</span><span class="va">nzero</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="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op">(</span><span class="fl">5</span>,<span class="fl">5</span>,<span class="fl">100</span><span class="op">)</span>,each<span class="op">=</span><span class="fu"><a href="https://rdrr.io/r/base/nrow.html">nrow</a></span><span class="op">(</span><span class="va">grid</span><span class="op">)</span><span class="op">/</span><span class="fl">3</span><span class="op">)</span>
<span class="va">grid</span> <span class="op">&lt;-</span> <span class="va">grid</span><span class="op">[</span><span class="fu"><a href="https://rdrr.io/r/base/rep.html">rep</a></span><span class="op">(</span><span class="fl">1</span><span class="op">:</span><span class="fu"><a href="https://rdrr.io/r/base/nrow.html">nrow</a></span><span class="op">(</span><span class="va">grid</span><span class="op">)</span>,times<span class="op">=</span><span class="fl">10</span><span class="op">)</span>,<span class="op">]</span>

<span class="va">n0</span> <span class="op">&lt;-</span> <span class="fl">100</span>; <span class="va">n1</span> <span class="op">&lt;-</span> <span class="fl">10000</span>
<span class="va">n</span> <span class="op">&lt;-</span> <span class="va">n0</span> <span class="op">+</span> <span class="va">n1</span>
<span class="va">q</span> <span class="op">&lt;-</span> <span class="fl">3</span>
<span class="va">foldid.ext</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="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op">(</span><span class="fl">0</span>,<span class="fl">1</span><span class="op">)</span>,times<span class="op">=</span><span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op">(</span><span class="va">n0</span>,<span class="va">n1</span><span class="op">)</span><span class="op">)</span>

<span class="va">loss</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/list.html">list</a></span><span class="op">(</span><span class="op">)</span>; <span class="va">cor</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/numeric.html">numeric</a></span><span class="op">(</span><span class="op">)</span>
<span class="kw">for</span><span class="op">(</span><span class="va">i</span> <span class="kw">in</span> <span class="fu"><a href="https://rdrr.io/r/base/seq.html">seq_len</a></span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/base/nrow.html">nrow</a></span><span class="op">(</span><span class="va">grid</span><span class="op">)</span><span class="op">)</span><span class="op">)</span><span class="op">{</span>
  <span class="va">p</span> <span class="op">&lt;-</span> <span class="va">grid</span><span class="op">$</span><span class="va">p</span><span class="op">[</span><span class="va">i</span><span class="op">]</span>
  <span class="fu"><a href="https://rdrr.io/r/base/Random.html">set.seed</a></span><span class="op">(</span><span class="va">i</span><span class="op">)</span>
  <span class="fu"><a href="https://rdrr.io/r/base/cat.html">cat</a></span><span class="op">(</span><span class="st">"i ="</span>,<span class="va">i</span>,<span class="st">"\n"</span><span class="op">)</span>
  
Armin Rauschenberger's avatar
Armin Rauschenberger committed
214
  <span class="co">#--- features ---</span>
Armin Rauschenberger's avatar
Armin Rauschenberger committed
215
216
217
218
219
  <span class="va">mean</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">sigma</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/matrix.html">matrix</a></span><span class="op">(</span><span class="va">grid</span><span class="op">$</span><span class="va">rho_x</span><span class="op">[</span><span class="va">i</span><span class="op">]</span>,nrow<span class="op">=</span><span class="va">p</span>,ncol<span class="op">=</span><span class="va">p</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">sigma</span><span class="op">)</span> <span class="op">&lt;-</span> <span class="fl">1</span>
  <span class="va">X</span> <span class="op">&lt;-</span> <span class="fu">mvtnorm</span><span class="fu">::</span><span class="fu"><a href="https://rdrr.io/pkg/mvtnorm/man/Mvnorm.html">rmvnorm</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>,sigma<span class="op">=</span><span class="va">sigma</span><span class="op">)</span>
  
Armin Rauschenberger's avatar
Armin Rauschenberger committed
220
  <span class="co">#--- effects --- (multivariate Gaussian)</span>
Armin Rauschenberger's avatar
Armin Rauschenberger committed
221
222
223
224
225
226
  <span class="va">mean</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">q</span><span class="op">)</span>
  <span class="va">sigma</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/matrix.html">matrix</a></span><span class="op">(</span>data<span class="op">=</span><span class="va">grid</span><span class="op">$</span><span class="va">rho_b</span><span class="op">[</span><span class="va">i</span><span class="op">]</span>,nrow<span class="op">=</span><span class="va">q</span>,ncol<span class="op">=</span><span class="va">q</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">sigma</span><span class="op">)</span> <span class="op">&lt;-</span> <span class="fl">1</span>
  <span class="va">beta</span> <span class="op">&lt;-</span> <span class="fu">mvtnorm</span><span class="fu">::</span><span class="fu"><a href="https://rdrr.io/pkg/mvtnorm/man/Mvnorm.html">rmvnorm</a></span><span class="op">(</span>n<span class="op">=</span><span class="va">p</span>,mean<span class="op">=</span><span class="va">mean</span>,sigma<span class="op">=</span><span class="va">sigma</span><span class="op">)</span>
  <span class="va">beta</span> <span class="op">&lt;-</span> <span class="fl">1</span><span class="op">*</span><span class="fu"><a href="https://rdrr.io/r/base/apply.html">apply</a></span><span class="op">(</span><span class="va">beta</span>,<span class="fl">2</span>,<span class="kw">function</span><span class="op">(</span><span class="va">x</span><span class="op">)</span> <span class="va">x</span><span class="op">&gt;</span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/base/sort.html">sort</a></span><span class="op">(</span><span class="va">x</span>,decreasing<span class="op">=</span><span class="cn">TRUE</span><span class="op">)</span><span class="op">[</span><span class="va">grid</span><span class="op">$</span><span class="va">nzero</span><span class="op">[</span><span class="va">i</span><span class="op">]</span><span class="op">]</span><span class="op">)</span><span class="op">)</span>
  
Armin Rauschenberger's avatar
Armin Rauschenberger committed
227
228
229
  <span class="co">#-- effects --- (multivariate binomial)</span>
  <span class="co">#sigma &lt;- matrix(grid$rho_b[i],nrow=q,ncol=q); diag(sigma) &lt;- 1</span>
  <span class="co">#beta &lt;- bindata::rmvbin(n=p,margprob=rep(grid$prop[i],times=q),bincorr=sigma)</span>
Armin Rauschenberger's avatar
Armin Rauschenberger committed
230
  
Armin Rauschenberger's avatar
Armin Rauschenberger committed
231
  <span class="co">#--- outcomes ---</span>
Armin Rauschenberger's avatar
Armin Rauschenberger committed
232
233
234
235
  <span class="va">signal</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/scale.html">scale</a></span><span class="op">(</span><span class="va">X</span><span class="op">%*%</span><span class="va">beta</span><span class="op">)</span>
  <span class="va">signal</span><span class="op">[</span><span class="fu"><a href="https://rdrr.io/r/base/NA.html">is.na</a></span><span class="op">(</span><span class="va">signal</span><span class="op">)</span><span class="op">]</span> <span class="op">&lt;-</span> <span class="fl">0</span>
  <span class="va">noise</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/matrix.html">matrix</a></span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/stats/Normal.html">rnorm</a></span><span class="op">(</span><span class="va">n</span><span class="op">*</span><span class="va">q</span><span class="op">)</span>,nrow<span class="op">=</span><span class="va">n</span>,ncol<span class="op">=</span><span class="va">q</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/MathFun.html">sqrt</a></span><span class="op">(</span><span class="va">delta</span><span class="op">)</span><span class="op">*</span><span class="va">signal</span> <span class="op">+</span> <span class="fu"><a href="https://rdrr.io/r/base/MathFun.html">sqrt</a></span><span class="op">(</span><span class="fl">1</span><span class="op">-</span><span class="va">delta</span><span class="op">)</span><span class="op">*</span><span class="va">noise</span>
Armin Rauschenberger's avatar
Armin Rauschenberger committed
236
  <span class="co"># binomial: Y &lt;- round(exp(Y)/(1+exp(Y)))</span>
Armin Rauschenberger's avatar
Armin Rauschenberger committed
237
238
239
240
  <span class="va">cors</span> <span class="op">&lt;-</span> <span class="fu">stats</span><span class="fu">::</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>
  <span class="fu"><a href="https://rdrr.io/r/base/diag.html">diag</a></span><span class="op">(</span><span class="va">cors</span><span class="op">)</span> <span class="op">&lt;-</span> <span class="cn">NA</span>
  <span class="va">cor</span><span class="op">[</span><span class="va">i</span><span class="op">]</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/mean.html">mean</a></span><span class="op">(</span><span class="va">cors</span>,na.rm<span class="op">=</span><span class="cn">TRUE</span><span class="op">)</span>
  
Armin Rauschenberger's avatar
Armin Rauschenberger committed
241
  <span class="co">#--- holdout ---</span>
Armin Rauschenberger's avatar
Armin Rauschenberger committed
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
  <span class="va">alpha.base</span> <span class="op">&lt;-</span> <span class="fl">1</span><span class="op">*</span><span class="op">(</span><span class="va">grid</span><span class="op">$</span><span class="va">nzero</span><span class="op">[</span><span class="va">i</span><span class="op">]</span> <span class="op">&lt;=</span> <span class="fl">10</span><span class="op">)</span> <span class="co"># sparse vs dense</span>
  <span class="va">compare</span> <span class="op">&lt;-</span> <span class="cn">TRUE</span>
  <span class="va">loss</span><span class="op">[[</span><span class="va">i</span><span class="op">]</span><span class="op">]</span> <span class="op">&lt;-</span> <span class="kw"><a href="https://rdrr.io/r/base/conditions.html">tryCatch</a></span><span class="op">(</span>expr<span class="op">=</span><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="st">"gaussian"</span>,compare<span class="op">=</span><span class="va">compare</span>,foldid.ext<span class="op">=</span><span class="va">foldid.ext</span>,alpha.base<span class="op">=</span><span class="va">alpha.base</span>,alpha.meta<span class="op">=</span><span class="fl">1</span>,times<span class="op">=</span><span class="cn">TRUE</span><span class="op">)</span>,error<span class="op">=</span><span class="kw">function</span><span class="op">(</span><span class="va">x</span><span class="op">)</span> <span class="cn">NA</span><span class="op">)</span>
<span class="op">}</span>
<span class="fu"><a href="https://rdrr.io/r/base/save.html">save</a></span><span class="op">(</span><span class="va">grid</span>,<span class="va">loss</span>,<span class="va">cor</span>,file<span class="op">=</span><span class="st">"results/simulation.RData"</span><span class="op">)</span>
<span class="fu"><a href="https://rdrr.io/r/base/writeLines.html">writeLines</a></span><span class="op">(</span>text<span class="op">=</span><span class="fu"><a href="https://rdrr.io/r/utils/capture.output.html">capture.output</a></span><span class="op">(</span><span class="fu">utils</span><span class="fu">::</span><span class="fu"><a href="https://rdrr.io/r/utils/sessionInfo.html">sessionInfo</a></span><span class="op">(</span><span class="op">)</span>,<span class="fu"><a href="https://rdrr.io/r/base/cat.html">cat</a></span><span class="op">(</span><span class="st">"\n"</span><span class="op">)</span>,<span class="fu">sessioninfo</span><span class="fu">::</span><span class="fu"><a href="https://rdrr.io/pkg/sessioninfo/man/session_info.html">session_info</a></span><span class="op">(</span><span class="op">)</span><span class="op">)</span>,con<span class="op">=</span><span class="st">"results/info_sim.txt"</span><span class="op">)</span></code></pre></div>
<div class="sourceCode" id="cb4"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="co">#&lt;&lt;start&gt;&gt;</span>
<span class="fu"><a href="https://rdrr.io/r/base/load.html">load</a></span><span class="op">(</span><span class="st">"results/simulation.RData"</span><span class="op">)</span>

<span class="va">cond</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/lapply.html">lapply</a></span><span class="op">(</span><span class="va">loss</span>,<span class="va">length</span><span class="op">)</span><span class="op">==</span><span class="fl">2</span>
<span class="kw">if</span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/base/any.html">any</a></span><span class="op">(</span><span class="op">!</span><span class="va">cond</span><span class="op">)</span><span class="op">)</span><span class="op">{</span>
  <span class="kw"><a href="https://rdrr.io/r/base/warning.html">warning</a></span><span class="op">(</span><span class="st">"At least one error."</span>,call.<span class="op">=</span><span class="cn">FALSE</span><span class="op">)</span>
  <span class="va">grid</span> <span class="op">&lt;-</span> <span class="va">grid</span><span class="op">[</span><span class="va">cond</span>,<span class="op">]</span>; <span class="va">loss</span> <span class="op">&lt;-</span> <span class="va">loss</span><span class="op">[</span><span class="va">cond</span><span class="op">]</span>
<span class="op">}</span>
Armin Rauschenberger's avatar
Armin Rauschenberger committed
257
258

<span class="co">#--- computation time ---</span>
Armin Rauschenberger's avatar
Armin Rauschenberger committed
259
<span class="va">time</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/lapply.html">sapply</a></span><span class="op">(</span><span class="va">loss</span>,<span class="kw">function</span><span class="op">(</span><span class="va">x</span><span class="op">)</span> <span class="fu"><a href="https://rdrr.io/r/base/unlist.html">unlist</a></span><span class="op">(</span><span class="va">x</span><span class="op">$</span><span class="va">time</span><span class="op">)</span><span class="op">)</span>
Armin Rauschenberger's avatar
Armin Rauschenberger committed
260
<span class="co">#round(sort(colMeans(apply(time,1,function(x) x/time["meta",]))),digits=1)</span>
Armin Rauschenberger's avatar
Armin Rauschenberger committed
261
<span class="fu"><a href="https://rdrr.io/r/base/sort.html">sort</a></span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/base/Round.html">round</a></span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/base/colSums.html">rowMeans</a></span><span class="op">(</span><span class="va">time</span><span class="op">)</span>,digits<span class="op">=</span><span class="fl">1</span><span class="op">)</span><span class="op">)</span>
Armin Rauschenberger's avatar
Armin Rauschenberger committed
262
263

<span class="co">#--- average ---</span>
Armin Rauschenberger's avatar
Armin Rauschenberger committed
264
265
266
267
<span class="va">loss</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/lapply.html">lapply</a></span><span class="op">(</span><span class="va">loss</span>,<span class="kw">function</span><span class="op">(</span><span class="va">x</span><span class="op">)</span> <span class="va">x</span><span class="op">$</span><span class="va">loss</span><span class="op">)</span>
<span class="va">prop</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/lapply.html">sapply</a></span><span class="op">(</span><span class="va">loss</span><span class="op">[</span><span class="va">cond</span><span class="op">]</span>,<span class="kw">function</span><span class="op">(</span><span class="va">x</span><span class="op">)</span> <span class="fu"><a href="https://rdrr.io/r/base/colSums.html">rowMeans</a></span><span class="op">(</span><span class="fl">100</span><span class="op">*</span><span class="va">x</span><span class="op">/</span><span class="fu"><a href="https://rdrr.io/r/base/matrix.html">matrix</a></span><span class="op">(</span><span class="va">x</span><span class="op">[</span><span class="st">"none"</span>,<span class="op">]</span>,nrow<span class="op">=</span><span class="fu"><a href="https://rdrr.io/r/base/nrow.html">nrow</a></span><span class="op">(</span><span class="va">x</span><span class="op">)</span>,ncol<span class="op">=</span><span class="fu"><a href="https://rdrr.io/r/base/nrow.html">ncol</a></span><span class="op">(</span><span class="va">x</span><span class="op">)</span>,byrow<span class="op">=</span><span class="cn">TRUE</span><span class="op">)</span><span class="op">)</span><span class="op">[</span><span class="op">-</span><span class="fu"><a href="https://rdrr.io/r/base/nrow.html">nrow</a></span><span class="op">(</span><span class="va">x</span><span class="op">)</span><span class="op">]</span><span class="op">)</span>
<span class="va">mode</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/ifelse.html">ifelse</a></span><span class="op">(</span><span class="va">grid</span><span class="op">$</span><span class="va">p</span><span class="op">==</span><span class="fl">10</span>,<span class="st">"ld"</span>,<span class="fu"><a href="https://rdrr.io/r/base/ifelse.html">ifelse</a></span><span class="op">(</span><span class="va">grid</span><span class="op">$</span><span class="va">nzero</span><span class="op">==</span><span class="fl">5</span>,<span class="st">"hd-s"</span>,<span class="st">"hd-d"</span><span class="op">)</span><span class="op">)</span>
<span class="va">set</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/numeric.html">as.numeric</a></span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/base/lapply.html">sapply</a></span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/base/colnames.html">rownames</a></span><span class="op">(</span><span class="va">grid</span><span class="op">)</span>,<span class="kw">function</span><span class="op">(</span><span class="va">x</span><span class="op">)</span> <span class="fu"><a href="https://rdrr.io/r/base/strsplit.html">strsplit</a></span><span class="op">(</span><span class="va">x</span>,split<span class="op">=</span><span class="st">"\\."</span><span class="op">)</span><span class="op">[[</span><span class="fl">1</span><span class="op">]</span><span class="op">]</span><span class="op">[[</span><span class="fl">1</span><span class="op">]</span><span class="op">]</span><span class="op">)</span><span class="op">)</span>
Armin Rauschenberger's avatar
Armin Rauschenberger committed
268
269

<span class="co">#--- mean rank ---</span>
Armin Rauschenberger's avatar
Armin Rauschenberger committed
270
271
272
273
<span class="va">mult</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/colnames.html">rownames</a></span><span class="op">(</span><span class="va">prop</span><span class="op">)</span><span class="op">!=</span><span class="st">"base"</span>
<span class="fu"><a href="https://rdrr.io/r/base/sort.html">sort</a></span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/base/Round.html">round</a></span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/base/colSums.html">rowMeans</a></span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/base/apply.html">apply</a></span><span class="op">(</span><span class="va">prop</span><span class="op">[</span><span class="va">mult</span>,<span class="va">mode</span><span class="op">==</span><span class="st">"ld"</span><span class="op">]</span>,<span class="fl">2</span>,<span class="va">rank</span><span class="op">)</span><span class="op">)</span>,digits<span class="op">=</span><span class="fl">1</span><span class="op">)</span><span class="op">)</span>
<span class="fu"><a href="https://rdrr.io/r/base/sort.html">sort</a></span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/base/Round.html">round</a></span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/base/colSums.html">rowMeans</a></span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/base/apply.html">apply</a></span><span class="op">(</span><span class="va">prop</span><span class="op">[</span><span class="va">mult</span>,<span class="va">mode</span><span class="op">==</span><span class="st">"hd-s"</span><span class="op">]</span>,<span class="fl">2</span>,<span class="va">rank</span><span class="op">)</span><span class="op">)</span>,digits<span class="op">=</span><span class="fl">1</span><span class="op">)</span><span class="op">)</span>
<span class="fu"><a href="https://rdrr.io/r/base/sort.html">sort</a></span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/base/Round.html">round</a></span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/base/colSums.html">rowMeans</a></span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/base/apply.html">apply</a></span><span class="op">(</span><span class="va">prop</span><span class="op">[</span><span class="va">mult</span>,<span class="va">mode</span><span class="op">==</span><span class="st">"hd-d"</span><span class="op">]</span>,<span class="fl">2</span>,<span class="va">rank</span><span class="op">)</span><span class="op">)</span>,digits<span class="op">=</span><span class="fl">1</span><span class="op">)</span><span class="op">)</span>
Armin Rauschenberger's avatar
Armin Rauschenberger committed
274
275

<span class="co">#--- testing ---</span>
Armin Rauschenberger's avatar
Armin Rauschenberger committed
276
<span class="fu"><a href="https://rdrr.io/r/base/apply.html">apply</a></span><span class="op">(</span><span class="va">prop</span><span class="op">[</span><span class="va">mult</span>,<span class="op">]</span>,<span class="fl">1</span>,<span class="kw">function</span><span class="op">(</span><span class="va">x</span><span class="op">)</span> <span class="fu"><a href="https://rdrr.io/r/base/sum.html">sum</a></span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/base/tapply.html">tapply</a></span><span class="op">(</span>X<span class="op">=</span><span class="va">x</span><span class="op">-</span><span class="va">prop</span><span class="op">[</span><span class="st">"base"</span>,<span class="op">]</span>,INDEX<span class="op">=</span><span class="va">set</span>,FUN<span class="op">=</span><span class="kw">function</span><span class="op">(</span><span class="va">x</span><span class="op">)</span> <span class="fu"><a href="https://rdrr.io/r/stats/wilcox.test.html">wilcox.test</a></span><span class="op">(</span><span class="va">x</span>,alternative<span class="op">=</span><span class="st">"less"</span><span class="op">)</span><span class="op">$</span><span class="va">p.value</span><span class="op">&lt;</span><span class="fl">0.05</span><span class="op">)</span>,na.rm<span class="op">=</span><span class="cn">TRUE</span><span class="op">)</span><span class="op">)</span>
Armin Rauschenberger's avatar
Armin Rauschenberger committed
277

Armin Rauschenberger's avatar
Armin Rauschenberger committed
278
279
280
281
282
<span class="fu"><a href="https://rdrr.io/r/base/colSums.html">colSums</a></span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/base/tapply.html">tapply</a></span><span class="op">(</span>X<span class="op">=</span><span class="va">prop</span><span class="op">[</span><span class="st">"meta"</span>,<span class="op">]</span><span class="op">-</span><span class="va">prop</span><span class="op">[</span><span class="st">"base"</span>,<span class="op">]</span>,INDEX<span class="op">=</span><span class="fu"><a href="https://rdrr.io/r/base/list.html">list</a></span><span class="op">(</span>set<span class="op">=</span><span class="va">set</span>,mode<span class="op">=</span><span class="va">mode</span><span class="op">)</span>,FUN<span class="op">=</span><span class="kw">function</span><span class="op">(</span><span class="va">x</span><span class="op">)</span> <span class="fu"><a href="https://rdrr.io/r/stats/wilcox.test.html">wilcox.test</a></span><span class="op">(</span><span class="va">x</span>,alternative<span class="op">=</span><span class="st">"less"</span><span class="op">)</span><span class="op">$</span><span class="va">p.value</span><span class="op">&lt;</span><span class="fl">0.05</span><span class="op">)</span>,na.rm<span class="op">=</span><span class="cn">TRUE</span><span class="op">)</span>
<span class="fu"><a href="https://rdrr.io/r/base/colSums.html">colSums</a></span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/base/tapply.html">tapply</a></span><span class="op">(</span>X<span class="op">=</span><span class="va">prop</span><span class="op">[</span><span class="st">"spls"</span>,<span class="op">]</span><span class="op">-</span><span class="va">prop</span><span class="op">[</span><span class="st">"base"</span>,<span class="op">]</span>,INDEX<span class="op">=</span><span class="fu"><a href="https://rdrr.io/r/base/list.html">list</a></span><span class="op">(</span>set<span class="op">=</span><span class="va">set</span>,mode<span class="op">=</span><span class="va">mode</span><span class="op">)</span>,FUN<span class="op">=</span><span class="kw">function</span><span class="op">(</span><span class="va">x</span><span class="op">)</span> <span class="fu"><a href="https://rdrr.io/r/stats/wilcox.test.html">wilcox.test</a></span><span class="op">(</span><span class="va">x</span>,alternative<span class="op">=</span><span class="st">"less"</span><span class="op">)</span><span class="op">$</span><span class="va">p.value</span><span class="op">&lt;</span><span class="fl">0.05</span><span class="op">)</span>,na.rm<span class="op">=</span><span class="cn">TRUE</span><span class="op">)</span></code></pre></div>
<div class="sourceCode" id="cb5"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="va">beta</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/lapply.html">sapply</a></span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/base/unique.html">unique</a></span><span class="op">(</span><span class="va">set</span><span class="op">)</span>,<span class="kw">function</span><span class="op">(</span><span class="va">i</span><span class="op">)</span> <span class="fu"><a href="https://rdrr.io/r/base/colSums.html">rowMeans</a></span><span class="op">(</span><span class="va">prop</span><span class="op">[</span>,<span class="va">set</span><span class="op">==</span><span class="va">i</span><span class="op">]</span><span class="op">)</span><span class="op">)</span>
<span class="va">cor</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/lapply.html">sapply</a></span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/base/unique.html">unique</a></span><span class="op">(</span><span class="va">set</span><span class="op">)</span>,<span class="kw">function</span><span class="op">(</span><span class="va">i</span><span class="op">)</span> <span class="fu"><a href="https://rdrr.io/r/base/mean.html">mean</a></span><span class="op">(</span><span class="va">cor</span><span class="op">[</span><span class="va">set</span><span class="op">==</span><span class="va">i</span><span class="op">]</span><span class="op">)</span><span class="op">)</span>
Armin Rauschenberger's avatar
Armin Rauschenberger committed
283

Armin Rauschenberger's avatar
Armin Rauschenberger committed
284
285
<span class="fu"><a href="https://rdrr.io/r/base/colnames.html">rownames</a></span><span class="op">(</span><span class="va">beta</span><span class="op">)</span><span class="op">[</span><span class="fu"><a href="https://rdrr.io/r/base/colnames.html">rownames</a></span><span class="op">(</span><span class="va">beta</span><span class="op">)</span><span class="op">==</span><span class="st">"mnorm"</span><span class="op">]</span> <span class="op">&lt;-</span> <span class="st">"mvn"</span>
<span class="va">sign</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/apply.html">apply</a></span><span class="op">(</span><span class="va">beta</span>,<span class="fl">2</span>,<span class="kw">function</span><span class="op">(</span><span class="va">x</span><span class="op">)</span> <span class="fu"><a href="https://rdrr.io/r/base/sign.html">sign</a></span><span class="op">(</span><span class="va">x</span><span class="op">[</span><span class="st">"base"</span><span class="op">]</span><span class="op">-</span><span class="va">x</span><span class="op">)</span><span class="op">)</span>
Armin Rauschenberger's avatar
Armin Rauschenberger committed
286
<span class="co">#min &lt;- apply(beta,2,function(x) which.min(x)) # incorrect (old)</span>
Armin Rauschenberger's avatar
Armin Rauschenberger committed
287
288
289
290
291
292
293
294
295
296
297
298
299
300
<span class="va">min</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/apply.html">apply</a></span><span class="op">(</span><span class="va">beta</span>,<span class="fl">2</span>,<span class="kw">function</span><span class="op">(</span><span class="va">x</span><span class="op">)</span> <span class="fu"><a href="https://rdrr.io/r/base/which.html">which</a></span><span class="op">(</span><span class="va">x</span><span class="op">==</span><span class="fu"><a href="https://rdrr.io/r/base/Extremes.html">min</a></span><span class="op">(</span><span class="va">x</span><span class="op">)</span><span class="op">)</span><span class="op">)</span> <span class="co"># correct (new)</span>
<span class="va">beta</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/format.html">format</a></span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/base/Round.html">round</a></span><span class="op">(</span><span class="va">beta</span>,digits<span class="op">=</span><span class="fl">1</span><span class="op">)</span>,trim<span class="op">=</span><span class="cn">TRUE</span><span class="op">)</span>
<span class="va">beta</span><span class="op">[</span><span class="va">sign</span><span class="op">&lt;=</span><span class="fl">0</span><span class="op">]</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/paste.html">paste0</a></span><span class="op">(</span><span class="st">"\\textcolor{gray}{"</span>,<span class="va">beta</span><span class="op">[</span><span class="va">sign</span><span class="op">&lt;=</span><span class="fl">0</span><span class="op">]</span>,<span class="st">"}"</span><span class="op">)</span>
<span class="va">index</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/cbind.html">cbind</a></span><span class="op">(</span><span class="va">min</span>,<span class="fl">1</span><span class="op">:</span><span class="fu"><a href="https://rdrr.io/r/base/nrow.html">ncol</a></span><span class="op">(</span><span class="va">beta</span><span class="op">)</span><span class="op">)</span>
<span class="va">beta</span><span class="op">[</span><span class="va">index</span><span class="op">]</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/paste.html">paste0</a></span><span class="op">(</span><span class="st">"\\underline{"</span>,<span class="va">beta</span><span class="op">[</span><span class="va">index</span><span class="op">]</span>,<span class="st">"}"</span><span class="op">)</span>
<span class="va">unique</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/unique.html">unique</a></span><span class="op">(</span><span class="va">grid</span><span class="op">)</span>
<span class="va">info</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/format.html">format</a></span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/base/Round.html">round</a></span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/base/cbind.html">cbind</a></span><span class="op">(</span><span class="st">"$\\rho_x$"</span><span class="op">=</span><span class="va">unique</span><span class="op">$</span><span class="va">rho_x</span>,<span class="st">"$\\rho_b$"</span><span class="op">=</span><span class="va">unique</span><span class="op">$</span><span class="va">rho_b</span>,<span class="st">"$\\rho_y$"</span><span class="op">=</span><span class="va">cor</span><span class="op">)</span>,digits<span class="op">=</span><span class="fl">1</span><span class="op">)</span><span class="op">)</span>
<span class="va">temp</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/paste.html">paste0</a></span><span class="op">(</span><span class="st">"\\cran{"</span>,<span class="fu"><a href="https://rdrr.io/r/base/lapply.html">sapply</a></span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/base/colnames.html">rownames</a></span><span class="op">(</span><span class="va">beta</span><span class="op">)</span>,<span class="kw">function</span><span class="op">(</span><span class="va">x</span><span class="op">)</span> <span class="kw"><a href="https://rdrr.io/r/base/switch.html">switch</a></span><span class="op">(</span><span class="va">x</span>,base<span class="op">=</span><span class="st">"glmnet"</span>,meta<span class="op">=</span><span class="st">"joinet"</span>,mvn<span class="op">=</span><span class="st">"glmnet"</span>,mars<span class="op">=</span><span class="st">"earth"</span>,spls<span class="op">=</span><span class="st">"spls"</span>,mrce<span class="op">=</span><span class="st">"MRCE"</span>,map<span class="op">=</span><span class="st">"remMap"</span>,mrf<span class="op">=</span><span class="st">"MultivariateRandomForest"</span>,sier<span class="op">=</span><span class="st">"SiER"</span>,mcen<span class="op">=</span><span class="st">"mcen"</span>,gpm<span class="op">=</span><span class="st">"GPM"</span>,rmtl<span class="op">=</span><span class="st">"RMTL"</span>,mtps<span class="op">=</span><span class="st">"MTPS"</span>,<span class="cn">NULL</span><span class="op">)</span><span class="op">)</span>,<span class="st">"}"</span><span class="op">)</span>
<span class="va">temp</span><span class="op">[</span><span class="fl">1</span><span class="op">]</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/paste.html">paste0</a></span><span class="op">(</span><span class="va">temp</span><span class="op">[</span><span class="fl">1</span><span class="op">]</span>,<span class="st">"$^1$"</span><span class="op">)</span>
<span class="va">temp</span><span class="op">[</span><span class="fl">3</span><span class="op">]</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/paste.html">paste0</a></span><span class="op">(</span><span class="va">temp</span><span class="op">[</span><span class="fl">3</span><span class="op">]</span>,<span class="st">"$^2$"</span><span class="op">)</span>
<span class="va">temp</span><span class="op">[</span><span class="fl">8</span><span class="op">]</span> <span class="op">&lt;-</span> <span class="st">"\\href{https://CRAN.R-project.org/package=MultivariateRandomForest}{\\texttt{MRF}}$^3$"</span>
<span class="fu"><a href="https://rdrr.io/r/base/colnames.html">rownames</a></span><span class="op">(</span><span class="va">beta</span><span class="op">)</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/paste.html">paste0</a></span><span class="op">(</span><span class="st">"\\begin{sideways}"</span>,<span class="va">temp</span>,<span class="st">"\\end{sideways}"</span><span class="op">)</span>
<span class="va">xtable</span> <span class="op">&lt;-</span> <span class="fu">xtable</span><span class="fu">::</span><span class="fu"><a href="https://rdrr.io/pkg/xtable/man/xtable.html">xtable</a></span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/base/cbind.html">cbind</a></span><span class="op">(</span><span class="va">info</span>,<span class="fu"><a href="https://rdrr.io/r/base/t.html">t</a></span><span class="op">(</span><span class="va">beta</span><span class="op">)</span><span class="op">)</span>,align<span class="op">=</span><span class="fu"><a href="https://rdrr.io/r/base/paste.html">paste0</a></span><span class="op">(</span><span class="st">"rccc"</span>,<span class="fu"><a href="https://rdrr.io/r/base/paste.html">paste0</a></span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/base/rep.html">rep</a></span><span class="op">(</span><span class="st">"c"</span>,times<span class="op">=</span><span class="fu"><a href="https://rdrr.io/r/base/nrow.html">nrow</a></span><span class="op">(</span><span class="va">beta</span><span class="op">)</span><span class="op">)</span>,collapse<span class="op">=</span><span class="st">""</span><span class="op">)</span>,collapse<span class="op">=</span><span class="st">""</span><span class="op">)</span>,caption<span class="op">=</span><span class="st">"Mean loss of different models (as percentage of empty model) in low-dimensional (top), sparse high-dimensional (centre), and dense high-dimensional (bottom) settings. The first three columns indicate the correlation between inputs ($\\rho_x$), the correlation between effects ($\\rho_b$), and the resulting mean correlation between outputs ($\\rho_y$). For each setting, the colour black indicates which models are more predictive than univariate regression, and the underline indicates the most predictive model. $\\hfill$ \\footnotesize$^1$univariate and $^2$multivariate linear regression with \\cran{glmnet}, $^3$\\cran{MultivariateRandomForest}\\normalsize\\label{table_SIM}"</span><span class="op">)</span>
<span class="fu">xtable</span><span class="fu">::</span><span class="fu"><a href="https://rdrr.io/pkg/xtable/man/print.xtable.html">print.xtable</a></span><span class="op">(</span><span class="va">xtable</span>,comment<span class="op">=</span><span class="cn">FALSE</span>,floating<span class="op">=</span><span class="cn">TRUE</span>,sanitize.text.function<span class="op">=</span><span class="va">identity</span>,hline.after<span class="op">=</span><span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op">(</span><span class="fl">0</span>,<span class="fl">9</span>,<span class="fl">18</span>,<span class="fu"><a href="https://rdrr.io/r/base/nrow.html">ncol</a></span><span class="op">(</span><span class="va">beta</span><span class="op">)</span><span class="op">)</span>,include.rownames<span class="op">=</span><span class="cn">FALSE</span>,size<span class="op">=</span><span class="st">"\\footnotesize"</span>,caption.placement<span class="op">=</span><span class="st">"top"</span><span class="op">)</span></code></pre></div>
Armin Rauschenberger's avatar
Armin Rauschenberger committed
301
302
303
304
</div>
<div id="application" class="section level1">
<h1 class="hasAnchor">
<a href="#application" class="anchor"></a>Application</h1>
Armin Rauschenberger's avatar
Armin Rauschenberger committed
305
306
307
308
309
310
311
312
313
314
315
316
317
<div class="sourceCode" id="cb6"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="co"># clinical features</span>
<span class="va">X</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/utils/read.table.html">read.csv</a></span><span class="op">(</span><span class="st">"data/PPMI_Baseline_Data_02Jul2018.csv"</span>,row.names<span class="op">=</span><span class="st">"PATNO"</span>,na.strings<span class="op">=</span><span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op">(</span><span class="st">"."</span>,<span class="st">""</span><span class="op">)</span><span class="op">)</span>
<span class="fu"><a href="https://rdrr.io/r/base/colnames.html">colnames</a></span><span class="op">(</span><span class="va">X</span><span class="op">)</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/chartr.html">tolower</a></span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/base/colnames.html">colnames</a></span><span class="op">(</span><span class="va">X</span><span class="op">)</span><span class="op">)</span>
<span class="va">X</span> <span class="op">&lt;-</span> <span class="va">X</span><span class="op">[</span><span class="va">X</span><span class="op">$</span><span class="va">apprdx</span><span class="op">==</span><span class="fl">1</span>,<span class="op">]</span> <span class="co"># Parkinson's disease</span>
<span class="va">X</span><span class="op">[</span><span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op">(</span><span class="st">"site"</span>,<span class="st">"apprdx"</span>,<span class="st">"event_id"</span>,<span class="st">"symptom5_comment"</span><span class="op">)</span><span class="op">]</span> <span class="op">&lt;-</span> <span class="cn">NULL</span>
<span class="kw">for</span><span class="op">(</span><span class="va">i</span> <span class="kw">in</span> <span class="fu"><a href="https://rdrr.io/r/base/seq.html">seq_len</a></span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/base/nrow.html">ncol</a></span><span class="op">(</span><span class="va">X</span><span class="op">)</span><span class="op">)</span><span class="op">)</span><span class="op">{</span>
  <span class="kw">if</span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/base/factor.html">is.factor</a></span><span class="op">(</span><span class="va">X</span><span class="op">[[</span><span class="va">i</span><span class="op">]</span><span class="op">]</span><span class="op">)</span><span class="op">)</span><span class="op">{</span><span class="fu"><a href="https://rdrr.io/r/base/levels.html">levels</a></span><span class="op">(</span><span class="va">X</span><span class="op">[[</span><span class="va">i</span><span class="op">]</span><span class="op">]</span><span class="op">)</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/paste.html">paste0</a></span><span class="op">(</span><span class="st">"-"</span>,<span class="fu"><a href="https://rdrr.io/r/base/levels.html">levels</a></span><span class="op">(</span><span class="va">X</span><span class="op">[[</span><span class="va">i</span><span class="op">]</span><span class="op">]</span><span class="op">)</span><span class="op">)</span><span class="op">}</span>
<span class="op">}</span>
<span class="fl">100</span><span class="op">*</span><span class="fu"><a href="https://rdrr.io/r/base/mean.html">mean</a></span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/base/NA.html">is.na</a></span><span class="op">(</span><span class="va">X</span><span class="op">)</span><span class="op">)</span> <span class="co"># proportion missingness</span>
<span class="va">x</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/lapply.html">lapply</a></span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/base/seq.html">seq_len</a></span><span class="op">(</span><span class="fl">1</span><span class="op">)</span>,<span class="kw">function</span><span class="op">(</span><span class="va">x</span><span class="op">)</span> <span class="fu">missRanger</span><span class="fu">::</span><span class="fu"><a href="https://rdrr.io/pkg/missRanger/man/missRanger.html">missRanger</a></span><span class="op">(</span>data<span class="op">=</span><span class="va">X</span>,pmm.k<span class="op">=</span><span class="fl">3</span>,
        num.trees<span class="op">=</span><span class="fl">100</span>,verbose<span class="op">=</span><span class="fl">0</span>,seed<span class="op">=</span><span class="fl">1</span><span class="op">)</span><span class="op">)</span>
<span class="va">x</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/lapply.html">lapply</a></span><span class="op">(</span><span class="va">x</span>,<span class="kw">function</span><span class="op">(</span><span class="va">x</span><span class="op">)</span> <span class="fu"><a href="https://rdrr.io/r/stats/model.matrix.html">model.matrix</a></span><span class="op">(</span><span class="op">~</span><span class="va">.</span><span class="op">-</span><span class="fl">1</span>,data<span class="op">=</span><span class="va">x</span><span class="op">)</span><span class="op">)</span>
Armin Rauschenberger's avatar
Armin Rauschenberger committed
318
319

<span class="co"># genomic features</span>
Armin Rauschenberger's avatar
Armin Rauschenberger committed
320
321
322
323
324
<span class="fu"><a href="https://rdrr.io/r/base/load.html">load</a></span><span class="op">(</span><span class="st">"data/ppmi_rnaseq_bl_pd_hc-2019-01-11.Rdata"</span>,verbose<span class="op">=</span><span class="cn">TRUE</span><span class="op">)</span>
<span class="va">counts</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/t.html">t</a></span><span class="op">(</span><span class="va">ppmi_rnaseq_bl_pdhc</span><span class="op">)</span>
<span class="fu"><a href="https://rdrr.io/r/base/mean.html">mean</a></span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/base/grep.html">grepl</a></span><span class="op">(</span>pattern<span class="op">=</span><span class="st">"ENSG0000|ENSGR0000"</span>,x<span class="op">=</span><span class="fu"><a href="https://rdrr.io/r/base/colnames.html">colnames</a></span><span class="op">(</span><span class="va">counts</span><span class="op">)</span><span class="op">)</span><span class="op">)</span>
<span class="va">cond</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/apply.html">apply</a></span><span class="op">(</span><span class="va">counts</span>,<span class="fl">2</span>,<span class="kw">function</span><span class="op">(</span><span class="va">x</span><span class="op">)</span> <span class="fu"><a href="https://rdrr.io/r/stats/sd.html">sd</a></span><span class="op">(</span><span class="va">x</span><span class="op">)</span><span class="op">&gt;</span><span class="fl">0</span><span class="op">)</span> <span class="op">&amp;</span> <span class="op">!</span><span class="fu"><a href="https://rdrr.io/r/base/grep.html">grepl</a></span><span class="op">(</span>pattern<span class="op">=</span><span class="st">"ENSG0000|ENSGR0000"</span>,x<span class="op">=</span><span class="fu"><a href="https://rdrr.io/r/base/colnames.html">colnames</a></span><span class="op">(</span><span class="va">counts</span><span class="op">)</span><span class="op">)</span>
<span class="va">Z</span> <span class="op">&lt;-</span> <span class="fu">palasso</span><span class="fu">:::</span><span class="fu"><a href="https://rdrr.io/pkg/palasso/man/other.html">.prepare</a></span><span class="op">(</span><span class="va">counts</span><span class="op">[</span>,<span class="va">cond</span><span class="op">]</span>,filter<span class="op">=</span><span class="fl">10</span>,cutoff<span class="op">=</span><span class="st">"knee"</span><span class="op">)</span><span class="op">$</span><span class="va">X</span>
Armin Rauschenberger's avatar
Armin Rauschenberger committed
325
326

<span class="co"># outcome</span>
Armin Rauschenberger's avatar
Armin Rauschenberger committed
327
328
329
330
<span class="va">Y</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/utils/read.table.html">read.csv</a></span><span class="op">(</span><span class="st">"data/PPMI_Year_1-3_Data_02Jul2018.csv"</span>,na.strings<span class="op">=</span><span class="st">"."</span><span class="op">)</span>
<span class="va">Y</span> <span class="op">&lt;-</span> <span class="va">Y</span><span class="op">[</span><span class="va">Y</span><span class="op">$</span><span class="va">APPRDX</span><span class="op">==</span><span class="fl">1</span> <span class="op">&amp;</span> <span class="va">Y</span><span class="op">$</span><span class="va">EVENT_ID</span> <span class="op">%in%</span> <span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op">(</span><span class="st">"V04"</span>,<span class="st">"V06"</span>,<span class="st">"V08"</span><span class="op">)</span>,<span class="op">]</span>
<span class="fu"><a href="https://rdrr.io/r/base/colnames.html">colnames</a></span><span class="op">(</span><span class="va">Y</span><span class="op">)</span><span class="op">[</span><span class="fu"><a href="https://rdrr.io/r/base/colnames.html">colnames</a></span><span class="op">(</span><span class="va">Y</span><span class="op">)</span><span class="op">==</span><span class="st">"updrs_totscore"</span><span class="op">]</span> <span class="op">&lt;-</span> <span class="st">"updrs"</span>
<span class="va">vars</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op">(</span><span class="st">"moca"</span>,<span class="st">"quip"</span>,<span class="st">"updrs"</span>,<span class="st">"gds"</span>,<span class="st">"scopa"</span>,<span class="st">"ess"</span>,<span class="st">"bjlot"</span>,<span class="st">"rem"</span><span class="op">)</span>
Armin Rauschenberger's avatar
Armin Rauschenberger committed
331
<span class="co"># too few levels: "NP1HALL","NP1DPRS"</span>
Armin Rauschenberger's avatar
Armin Rauschenberger committed
332
333
334
<span class="va">Y</span> <span class="op">&lt;-</span> <span class="va">Y</span><span class="op">[</span>,<span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op">(</span><span class="st">"EVENT_ID"</span>,<span class="st">"PATNO"</span>,<span class="va">vars</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/stats/reshape.html">reshape</a></span><span class="op">(</span><span class="va">Y</span>,idvar<span class="op">=</span><span class="st">"PATNO"</span>,timevar<span class="op">=</span><span class="st">"EVENT_ID"</span>,direction<span class="op">=</span><span class="st">"wide"</span><span class="op">)</span>
<span class="fu"><a href="https://rdrr.io/r/base/colnames.html">rownames</a></span><span class="op">(</span><span class="va">Y</span><span class="op">)</span> <span class="op">&lt;-</span> <span class="va">Y</span><span class="op">$</span><span class="va">PATNO</span>; <span class="va">Y</span><span class="op">$</span><span class="va">PATNO</span> <span class="op">&lt;-</span> <span class="cn">NULL</span>
Armin Rauschenberger's avatar
Armin Rauschenberger committed
335
336

<span class="co"># overlap</span>
Armin Rauschenberger's avatar
Armin Rauschenberger committed
337
338
339
340
341
342
343
344
345
<span class="va">names</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/funprog.html">Reduce</a></span><span class="op">(</span><span class="va">intersect</span>,<span class="fu"><a href="https://rdrr.io/r/base/list.html">list</a></span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/base/colnames.html">rownames</a></span><span class="op">(</span><span class="va">X</span><span class="op">)</span>,<span class="fu"><a href="https://rdrr.io/r/base/colnames.html">rownames</a></span><span class="op">(</span><span class="va">Y</span><span class="op">)</span>,<span class="fu"><a href="https://rdrr.io/r/base/colnames.html">rownames</a></span><span class="op">(</span><span class="va">Z</span><span class="op">)</span><span class="op">)</span><span class="op">)</span>
<span class="va">Z</span> <span class="op">&lt;-</span> <span class="va">Z</span><span class="op">[</span><span class="va">names</span>,<span class="op">]</span>
<span class="va">Y</span> <span class="op">&lt;-</span> <span class="va">Y</span><span class="op">[</span><span class="va">names</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">sapply</a></span><span class="op">(</span><span class="va">vars</span>,<span class="kw">function</span><span class="op">(</span><span class="va">x</span><span class="op">)</span> <span class="va">Y</span><span class="op">[</span>,<span class="fu"><a href="https://rdrr.io/r/base/grep.html">grepl</a></span><span class="op">(</span>pattern<span class="op">=</span><span class="va">x</span>,x<span class="op">=</span><span class="fu"><a href="https://rdrr.io/r/base/colnames.html">colnames</a></span><span class="op">(</span><span class="va">Y</span><span class="op">)</span><span class="op">)</span><span class="op">]</span>,simplify<span class="op">=</span><span class="cn">FALSE</span><span class="op">)</span>
<span class="kw">for</span><span class="op">(</span><span class="va">i</span> <span class="kw">in</span> <span class="fu"><a href="https://rdrr.io/r/base/seq.html">seq_along</a></span><span class="op">(</span><span class="va">Y</span><span class="op">)</span><span class="op">)</span><span class="op">{</span>
  <span class="fu"><a href="https://rdrr.io/r/base/colnames.html">colnames</a></span><span class="op">(</span><span class="va">Y</span><span class="op">[[</span><span class="va">i</span><span class="op">]</span><span class="op">]</span><span class="op">)</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op">(</span><span class="st">"V04"</span>,<span class="st">"V06"</span>,<span class="st">"V08"</span><span class="op">)</span>
<span class="op">}</span>
<span class="va">x</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/lapply.html">lapply</a></span><span class="op">(</span><span class="va">x</span>,<span class="kw">function</span><span class="op">(</span><span class="va">x</span><span class="op">)</span> <span class="va">x</span><span class="op">[</span><span class="va">names</span>,<span class="op">]</span><span class="op">)</span>; <span class="fu"><a href="https://rdrr.io/r/base/rm.html">rm</a></span><span class="op">(</span><span class="va">names</span><span class="op">)</span>
<span class="va">X</span> <span class="op">&lt;-</span> <span class="va">x</span><span class="op">[[</span><span class="fl">1</span><span class="op">]</span><span class="op">]</span>; <span class="fu"><a href="https://rdrr.io/r/base/rm.html">rm</a></span><span class="op">(</span><span class="va">x</span><span class="op">)</span> <span class="co"># impute multiple times!</span>
Armin Rauschenberger's avatar
Armin Rauschenberger committed
346
347

<span class="co"># inversion for positive correlation</span>
Armin Rauschenberger's avatar
Armin Rauschenberger committed
348
349
350
<span class="va">Y</span><span class="op">$</span><span class="va">moca</span> <span class="op">&lt;-</span> <span class="op">-</span><span class="va">Y</span><span class="op">$</span><span class="va">moca</span> <span class="co"># "wrong" sign</span>
<span class="va">Y</span><span class="op">$</span><span class="va">bjlot</span> <span class="op">&lt;-</span> <span class="op">-</span><span class="va">Y</span><span class="op">$</span><span class="va">bjlot</span> <span class="co"># "wrong" sign</span>
<span class="fu"><a href="https://rdrr.io/r/base/lapply.html">sapply</a></span><span class="op">(</span><span class="va">Y</span>,<span class="kw">function</span><span class="op">(</span><span class="va">x</span><span class="op">)</span> <span class="fu"><a href="https://rdrr.io/r/base/range.html">range</a></span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/base/unlist.html">unlist</a></span><span class="op">(</span><span class="va">x</span><span class="op">)</span>,na.rm<span class="op">=</span><span class="cn">TRUE</span><span class="op">)</span><span class="op">)</span>
Armin Rauschenberger's avatar
Armin Rauschenberger committed
351

Armin Rauschenberger's avatar
Armin Rauschenberger committed
352
353
354
355
<span class="fu"><a href="https://rdrr.io/r/base/save.html">save</a></span><span class="op">(</span><span class="va">Y</span>,<span class="va">X</span>,<span class="va">Z</span>,file<span class="op">=</span><span class="st">"results/data.RData"</span><span class="op">)</span>
<span class="fu"><a href="https://rdrr.io/r/base/writeLines.html">writeLines</a></span><span class="op">(</span>text<span class="op">=</span><span class="fu"><a href="https://rdrr.io/r/utils/capture.output.html">capture.output</a></span><span class="op">(</span><span class="fu">utils</span><span class="fu">::</span><span class="fu"><a href="https://rdrr.io/r/utils/sessionInfo.html">sessionInfo</a></span><span class="op">(</span><span class="op">)</span>,<span class="fu"><a href="https://rdrr.io/r/base/cat.html">cat</a></span><span class="op">(</span><span class="st">"\n"</span><span class="op">)</span>,<span class="fu">sessioninfo</span><span class="fu">::</span><span class="fu"><a href="https://rdrr.io/pkg/sessioninfo/man/session_info.html">session_info</a></span><span class="op">(</span><span class="op">)</span><span class="op">)</span>,con<span class="op">=</span><span class="st">"results/info_dat.txt"</span><span class="op">)</span></code></pre></div>
<div class="sourceCode" id="cb7"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="fu"><a href="https://rdrr.io/r/base/load.html">load</a></span><span class="op">(</span><span class="st">"results/data.RData"</span>,verbose<span class="op">=</span><span class="cn">TRUE</span><span class="op">)</span>
Armin Rauschenberger's avatar
Armin Rauschenberger committed
356

Armin Rauschenberger's avatar
Armin Rauschenberger committed
357
<span class="co">#grDevices::pdf(file="manuscript/figure_COR.pdf",width=6,height=3)</span>
Armin Rauschenberger's avatar
Armin Rauschenberger committed
358
359
360
<span class="fu">grDevices</span><span class="fu">::</span><span class="fu"><a href="https://rdrr.io/r/grDevices/postscript.html">postscript</a></span><span class="op">(</span>file<span class="op">=</span><span class="st">"manuscript/figure_COR.eps"</span>,width<span class="op">=</span><span class="fl">6</span>,height<span class="op">=</span><span class="fl">3</span><span class="op">)</span>
<span class="fu">graphics</span><span class="fu">::</span><span class="fu"><a href="https://rdrr.io/r/graphics/par.html">par</a></span><span class="op">(</span>mar<span class="op">=</span><span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op">(</span><span class="fl">0.5</span>,<span class="fl">3</span>,<span class="fl">2</span>,<span class="fl">0.5</span><span class="op">)</span><span class="op">)</span>
<span class="fu">graphics</span><span class="fu">::</span><span class="fu"><a href="https://rdrr.io/r/graphics/layout.html">layout</a></span><span class="op">(</span>mat<span class="op">=</span><span class="fu"><a href="https://rdrr.io/r/base/matrix.html">matrix</a></span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op">(</span><span class="fl">1</span>,<span class="fl">2</span><span class="op">)</span>,nrow<span class="op">=</span><span class="fl">1</span>,ncol<span class="op">=</span><span class="fl">2</span><span class="op">)</span>,width<span class="op">=</span><span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op">(</span><span class="fl">0.2</span>,<span class="fl">0.8</span><span class="op">)</span><span class="op">)</span>
Armin Rauschenberger's avatar
Armin Rauschenberger committed
361
362

<span class="co"># correlation between years</span>
Armin Rauschenberger's avatar
Armin Rauschenberger committed
363
364
365
366
367
368
<span class="va">cor</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/cbind.html">cbind</a></span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/base/lapply.html">sapply</a></span><span class="op">(</span><span class="va">Y</span>,<span class="kw">function</span><span class="op">(</span><span class="va">x</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">x</span><span class="op">[</span>,<span class="fl">1</span><span class="op">]</span>,<span class="va">x</span><span class="op">[</span>,<span class="fl">2</span><span class="op">]</span>,use<span class="op">=</span><span class="st">"complete.obs"</span>,method<span class="op">=</span><span class="st">"spearman"</span><span class="op">)</span><span class="op">)</span>,
<span class="fu"><a href="https://rdrr.io/r/base/lapply.html">sapply</a></span><span class="op">(</span><span class="va">Y</span>,<span class="kw">function</span><span class="op">(</span><span class="va">x</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">x</span><span class="op">[</span>,<span class="fl">2</span><span class="op">]</span>,<span class="va">x</span><span class="op">[</span>,<span class="fl">3</span><span class="op">]</span>,use<span class="op">=</span><span class="st">"complete.obs"</span>,method<span class="op">=</span><span class="st">"spearman"</span><span class="op">)</span><span class="op">)</span>,
<span class="fu"><a href="https://rdrr.io/r/base/lapply.html">sapply</a></span><span class="op">(</span><span class="va">Y</span>,<span class="kw">function</span><span class="op">(</span><span class="va">x</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">x</span><span class="op">[</span>,<span class="fl">1</span><span class="op">]</span>,<span class="va">x</span><span class="op">[</span>,<span class="fl">3</span><span class="op">]</span>,use<span class="op">=</span><span class="st">"complete.obs"</span>,method<span class="op">=</span><span class="st">"spearman"</span><span class="op">)</span><span class="op">)</span><span class="op">)</span>
<span class="fu"><a href="https://rdrr.io/r/base/colnames.html">colnames</a></span><span class="op">(</span><span class="va">cor</span><span class="op">)</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op">(</span><span class="st">"1-2"</span>,<span class="st">"2-3"</span>,<span class="st">"1-3"</span><span class="op">)</span>
<span class="va">cor</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/colSums.html">rowMeans</a></span><span class="op">(</span><span class="va">cor</span><span class="op">)</span>
<span class="fu">joinet</span><span class="fu">:::</span><span class="fu">plot.matrix</span><span class="op">(</span><span class="va">cor</span>,range<span class="op">=</span><span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op">(</span><span class="op">-</span><span class="fl">3</span>,<span class="fl">3</span><span class="op">)</span>,margin<span class="op">=</span><span class="fl">1</span>,cex<span class="op">=</span><span class="fl">0.7</span><span class="op">)</span>
Armin Rauschenberger's avatar
Armin Rauschenberger committed
369
370

<span class="co"># correlation between variables</span>
Armin Rauschenberger's avatar
Armin Rauschenberger committed
371
372
373
374
375
<span class="va">cor</span> <span class="op">&lt;-</span> <span class="fl">1</span><span class="op">/</span><span class="fl">3</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="fu"><a href="https://rdrr.io/r/base/lapply.html">sapply</a></span><span class="op">(</span><span class="va">Y</span>,<span class="kw">function</span><span class="op">(</span><span class="va">x</span><span class="op">)</span> <span class="va">x</span><span class="op">[</span>,<span class="fl">1</span><span class="op">]</span><span class="op">)</span>,use<span class="op">=</span><span class="st">"complete.obs"</span>,method<span class="op">=</span><span class="st">"spearman"</span><span class="op">)</span><span class="op">+</span>
<span class="fl">1</span><span class="op">/</span><span class="fl">3</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="fu"><a href="https://rdrr.io/r/base/lapply.html">sapply</a></span><span class="op">(</span><span class="va">Y</span>,<span class="kw">function</span><span class="op">(</span><span class="va">x</span><span class="op">)</span> <span class="va">x</span><span class="op">[</span>,<span class="fl">2</span><span class="op">]</span><span class="op">)</span>,use<span class="op">=</span><span class="st">"complete.obs"</span>,method<span class="op">=</span><span class="st">"spearman"</span><span class="op">)</span><span class="op">+</span>
<span class="fl">1</span><span class="op">/</span><span class="fl">3</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="fu"><a href="https://rdrr.io/r/base/lapply.html">sapply</a></span><span class="op">(</span><span class="va">Y</span>,<span class="kw">function</span><span class="op">(</span><span class="va">x</span><span class="op">)</span> <span class="va">x</span><span class="op">[</span>,<span class="fl">3</span><span class="op">]</span><span class="op">)</span>,use<span class="op">=</span><span class="st">"complete.obs"</span>,method<span class="op">=</span><span class="st">"spearman"</span><span class="op">)</span>
<span class="fu">joinet</span><span class="fu">:::</span><span class="fu">plot.matrix</span><span class="op">(</span><span class="va">cor</span>,range<span class="op">=</span><span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op">(</span><span class="op">-</span><span class="fl">3</span>,<span class="fl">3</span><span class="op">)</span>,margin<span class="op">=</span><span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op">(</span><span class="fl">1</span>,<span class="fl">2</span><span class="op">)</span>,cex<span class="op">=</span><span class="fl">0.7</span><span class="op">)</span>
<span class="fu">grDevices</span><span class="fu">::</span><span class="fu"><a href="https://rdrr.io/r/grDevices/dev.html">dev.off</a></span><span class="op">(</span><span class="op">)</span>
Armin Rauschenberger's avatar
Armin Rauschenberger committed
376
377

<span class="co"># other information</span>
Armin Rauschenberger's avatar
Armin Rauschenberger committed
378
379
380
381
382
<span class="fu"><a href="https://rdrr.io/r/base/lapply.html">sapply</a></span><span class="op">(</span><span class="va">Y</span>,<span class="va">colMeans</span>,na.rm<span class="op">=</span><span class="cn">TRUE</span><span class="op">)</span> <span class="co"># increasing values</span>
<span class="fu"><a href="https://rdrr.io/r/base/lapply.html">sapply</a></span><span class="op">(</span><span class="va">Y</span>,<span class="kw">function</span><span class="op">(</span><span class="va">x</span><span class="op">)</span> <span class="fu"><a href="https://rdrr.io/r/base/apply.html">apply</a></span><span class="op">(</span><span class="va">x</span>,<span class="fl">2</span>,<span class="va">sd</span>,na.rm<span class="op">=</span><span class="cn">TRUE</span><span class="op">)</span><span class="op">)</span> <span class="co"># increasing variance</span>
<span class="fu"><a href="https://rdrr.io/r/base/lapply.html">sapply</a></span><span class="op">(</span><span class="va">Y</span>,<span class="kw">function</span><span class="op">(</span><span class="va">x</span><span class="op">)</span> <span class="fu"><a href="https://rdrr.io/r/base/colSums.html">colSums</a></span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/base/NA.html">is.na</a></span><span class="op">(</span><span class="va">x</span><span class="op">)</span><span class="op">)</span><span class="op">)</span> <span class="co"># increasing numbers of NAs</span></code></pre></div>
<div class="sourceCode" id="cb8"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="co">#&lt;&lt;start&gt;&gt;</span>
Armin Rauschenberger's avatar
Armin Rauschenberger committed
383

Armin Rauschenberger's avatar
Armin Rauschenberger committed
384
385
<span class="fu"><a href="https://rdrr.io/r/base/Random.html">set.seed</a></span><span class="op">(</span><span class="fl">1</span><span class="op">)</span>
<span class="fu"><a href="https://rdrr.io/r/base/load.html">load</a></span><span class="op">(</span><span class="st">"results/data.RData"</span>,verbose<span class="op">=</span><span class="cn">TRUE</span><span class="op">)</span>
Armin Rauschenberger's avatar
Armin Rauschenberger committed
386

Armin Rauschenberger's avatar
Armin Rauschenberger committed
387
388
389
390
<span class="fu"><a href="https://rdrr.io/r/base/Random.html">set.seed</a></span><span class="op">(</span><span class="fl">1</span><span class="op">)</span>
<span class="va">foldid.ext</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">1</span><span class="op">:</span><span class="fl">5</span>,length.out<span class="op">=</span><span class="fu"><a href="https://rdrr.io/r/base/nrow.html">nrow</a></span><span class="op">(</span><span class="va">Y</span><span class="op">$</span><span class="va">moca</span><span class="op">)</span><span class="op">)</span>
<span class="va">foldid.int</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="fu"><a href="https://rdrr.io/r/base/rep.html">rep</a></span><span class="op">(</span><span class="fl">1</span><span class="op">:</span><span class="fl">10</span>,each<span class="op">=</span><span class="fl">5</span><span class="op">)</span>,length.out<span class="op">=</span><span class="fu"><a href="https://rdrr.io/r/base/nrow.html">nrow</a></span><span class="op">(</span><span class="va">Y</span><span class="op">$</span><span class="va">moca</span><span class="op">)</span><span class="op">)</span>
<span class="fu"><a href="https://rdrr.io/r/base/table.html">table</a></span><span class="op">(</span><span class="va">foldid.ext</span>,<span class="va">foldid.int</span><span class="op">)</span>
Armin Rauschenberger's avatar
Armin Rauschenberger committed
391
392
393
394
395

<span class="co">#- - - - - - - - - - - - -</span>
<span class="co">#- - internal coaching - -</span>
<span class="co">#- - - - - - - - - - - - -</span>

Armin Rauschenberger's avatar
Armin Rauschenberger committed
396
397
398
399
400
401
402
403
404
405
406
407
408
409
<span class="va">table</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/list.html">list</a></span><span class="op">(</span><span class="op">)</span>
<span class="va">table</span><span class="op">$</span><span class="va">alpha</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op">(</span><span class="st">"lasso"</span>,<span class="st">"ridge"</span><span class="op">)</span>
<span class="va">table</span><span class="op">$</span><span class="va">data</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op">(</span><span class="st">"clinic"</span>,<span class="st">"omics"</span>,<span class="st">"both"</span><span class="op">)</span>
<span class="va">table</span><span class="op">$</span><span class="va">var</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/names.html">names</a></span><span class="op">(</span><span class="va">Y</span><span class="op">)</span>
<span class="va">table</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/rev.html">rev</a></span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/base/expand.grid.html">expand.grid</a></span><span class="op">(</span><span class="va">table</span>,stringsAsFactors<span class="op">=</span><span class="cn">FALSE</span><span class="op">)</span><span class="op">)</span>

<span class="va">loss</span> <span class="op">&lt;-</span> <span class="va">fit</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/list.html">list</a></span><span class="op">(</span><span class="op">)</span>
<span class="kw">for</span><span class="op">(</span><span class="va">i</span> <span class="kw">in</span> <span class="fu"><a href="https://rdrr.io/r/base/seq.html">seq_len</a></span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/base/nrow.html">nrow</a></span><span class="op">(</span><span class="va">table</span><span class="op">)</span><span class="op">)</span><span class="op">)</span><span class="op">{</span>
  <span class="fu"><a href="https://rdrr.io/r/base/cat.html">cat</a></span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/base/rep.html">rep</a></span><span class="op">(</span><span class="st">"*"</span>,times<span class="op">=</span><span class="fl">5</span><span class="op">)</span>,<span class="st">"setting"</span>,<span class="va">i</span>,<span class="fu"><a href="https://rdrr.io/r/base/rep.html">rep</a></span><span class="op">(</span><span class="st">"*"</span>,times<span class="op">=</span><span class="fl">5</span><span class="op">)</span>,<span class="st">"\n"</span><span class="op">)</span>
  <span class="va">y</span> <span class="op">&lt;-</span> <span class="va">Y</span><span class="op">[[</span><span class="va">table</span><span class="op">$</span><span class="va">var</span><span class="op">[</span><span class="va">i</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"><a href="https://rdrr.io/r/base/list.html">list</a></span><span class="op">(</span>clinic<span class="op">=</span><span class="va">X</span>,omics<span class="op">=</span><span class="va">Z</span>,both<span class="op">=</span><span class="fu"><a href="https://rdrr.io/r/base/cbind.html">cbind</a></span><span class="op">(</span><span class="va">X</span>,<span class="va">Z</span><span class="op">)</span><span class="op">)</span><span class="op">[[</span><span class="va">table</span><span class="op">$</span><span class="va">data</span><span class="op">[</span><span class="va">i</span><span class="op">]</span><span class="op">]</span><span class="op">]</span>
  <span class="va">alpha</span> <span class="op">&lt;-</span> <span class="fl">1</span><span class="op">*</span><span class="op">(</span><span class="va">table</span><span class="op">$</span><span class="va">alpha</span><span class="op">[</span><span class="va">i</span><span class="op">]</span><span class="op">==</span><span class="st">"lasso"</span><span class="op">)</span>
  <span class="va">loss</span><span class="op">[[</span><span class="va">i</span><span class="op">]</span><span class="op">]</span> <span class="op">&lt;-</span> <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>,alpha.base<span class="op">=</span><span class="va">alpha</span>,foldid.ext<span class="op">=</span><span class="va">foldid.ext</span>,
          foldid.int<span class="op">=</span><span class="va">foldid.int</span><span class="op">)</span> <span class="co"># add joinet::</span>
Armin Rauschenberger's avatar
Armin Rauschenberger committed
410
  <span class="co">#fit[[i]] &lt;- joinet(Y=y,X=x,alpha.base=alpha,foldid=foldid.int)</span>
Armin Rauschenberger's avatar
Armin Rauschenberger committed
411
<span class="op">}</span>
Armin Rauschenberger's avatar
Armin Rauschenberger committed
412

Armin Rauschenberger's avatar
Armin Rauschenberger committed
413
<span class="fu"><a href="https://rdrr.io/r/base/save.html">save</a></span><span class="op">(</span><span class="va">table</span>,<span class="va">loss</span>,file<span class="op">=</span><span class="st">"results/internal.RData"</span><span class="op">)</span>
Armin Rauschenberger's avatar
Armin Rauschenberger committed
414
415
416
417
418

<span class="co">#- - - - - - - - - - - - -</span>
<span class="co">#- - external coaching - -</span>
<span class="co">#- - - - - - - - - - - - -</span>

Armin Rauschenberger's avatar
Armin Rauschenberger committed
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
<span class="va">table</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/list.html">list</a></span><span class="op">(</span><span class="op">)</span>
<span class="va">temp</span> <span class="op">&lt;-</span> <span class="fu">utils</span><span class="fu">::</span><span class="fu"><a href="https://rdrr.io/r/utils/combn.html">combn</a></span><span class="op">(</span>x<span class="op">=</span><span class="fu"><a href="https://rdrr.io/r/base/names.html">names</a></span><span class="op">(</span><span class="va">Y</span><span class="op">)</span>,m<span class="op">=</span><span class="fl">2</span><span class="op">)</span>
<span class="va">table</span><span class="op">$</span><span class="va">comb</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/paste.html">paste0</a></span><span class="op">(</span><span class="va">temp</span><span class="op">[</span><span class="fl">1</span>,<span class="op">]</span>,<span class="st">"-"</span>,<span class="va">temp</span><span class="op">[</span><span class="fl">2</span>,<span class="op">]</span><span class="op">)</span>
<span class="va">table</span><span class="op">$</span><span class="va">step</span> <span class="op">&lt;-</span>  <span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op">(</span><span class="st">"V04"</span>,<span class="st">"V06"</span>,<span class="st">"V08"</span><span class="op">)</span>
<span class="va">table</span><span class="op">$</span><span class="va">alpha</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op">(</span><span class="st">"lasso"</span>,<span class="st">"ridge"</span><span class="op">)</span>
<span class="va">table</span><span class="op">$</span><span class="va">data</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op">(</span><span class="st">"clinic"</span>,<span class="st">"omics"</span>,<span class="st">"both"</span><span class="op">)</span>
<span class="va">table</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/rev.html">rev</a></span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/base/expand.grid.html">expand.grid</a></span><span class="op">(</span><span class="va">table</span>,stringsAsFactors<span class="op">=</span><span class="cn">FALSE</span><span class="op">)</span><span class="op">)</span>
<span class="va">temp</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/strsplit.html">strsplit</a></span><span class="op">(</span><span class="va">table</span><span class="op">$</span><span class="va">comb</span>,split<span class="op">=</span><span class="st">"-"</span><span class="op">)</span>; <span class="va">table</span><span class="op">$</span><span class="va">comb</span> <span class="op">&lt;-</span> <span class="cn">NULL</span>
<span class="va">table</span><span class="op">$</span><span class="va">var1</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/lapply.html">sapply</a></span><span class="op">(</span><span class="va">temp</span>,<span class="kw">function</span><span class="op">(</span><span class="va">x</span><span class="op">)</span> <span class="va">x</span><span class="op">[[</span><span class="fl">1</span><span class="op">]</span><span class="op">]</span><span class="op">)</span>
<span class="va">table</span><span class="op">$</span><span class="va">var2</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/lapply.html">sapply</a></span><span class="op">(</span><span class="va">temp</span>,<span class="kw">function</span><span class="op">(</span><span class="va">x</span><span class="op">)</span> <span class="va">x</span><span class="op">[[</span><span class="fl">2</span><span class="op">]</span><span class="op">]</span><span class="op">)</span>

<span class="va">loss</span> <span class="op">&lt;-</span> <span class="va">fit</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/list.html">list</a></span><span class="op">(</span><span class="op">)</span>
<span class="kw">for</span><span class="op">(</span><span class="va">i</span> <span class="kw">in</span> <span class="fu"><a href="https://rdrr.io/r/base/seq.html">seq_len</a></span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/base/nrow.html">nrow</a></span><span class="op">(</span><span class="va">table</span><span class="op">)</span><span class="op">)</span><span class="op">)</span><span class="op">{</span>
  <span class="fu"><a href="https://rdrr.io/r/base/cat.html">cat</a></span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/base/rep.html">rep</a></span><span class="op">(</span><span class="st">"*"</span>,times<span class="op">=</span><span class="fl">5</span><span class="op">)</span>,<span class="st">"setting"</span>,<span class="va">i</span>,<span class="fu"><a href="https://rdrr.io/r/base/rep.html">rep</a></span><span class="op">(</span><span class="st">"*"</span>,times<span class="op">=</span><span class="fl">5</span><span class="op">)</span>,<span class="st">"\n"</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/cbind.html">cbind</a></span><span class="op">(</span><span class="va">Y</span><span class="op">[[</span><span class="va">table</span><span class="op">$</span><span class="va">var1</span><span class="op">[</span><span class="va">i</span><span class="op">]</span><span class="op">]</span><span class="op">]</span><span class="op">[</span>,<span class="va">table</span><span class="op">$</span><span class="va">step</span><span class="op">[</span><span class="va">i</span><span class="op">]</span><span class="op">]</span>,
             <span class="va">Y</span><span class="op">[[</span><span class="va">table</span><span class="op">$</span><span class="va">var2</span><span class="op">[</span><span class="va">i</span><span class="op">]</span><span class="op">]</span><span class="op">]</span><span class="op">[</span>,<span class="va">table</span><span class="op">$</span><span class="va">step</span><span class="op">[</span><span class="va">i</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"><a href="https://rdrr.io/r/base/list.html">list</a></span><span class="op">(</span>clinic<span class="op">=</span><span class="va">X</span>,omics<span class="op">=</span><span class="va">Z</span>,both<span class="op">=</span><span class="fu"><a href="https://rdrr.io/r/base/cbind.html">cbind</a></span><span class="op">(</span><span class="va">X</span>,<span class="va">Z</span><span class="op">)</span><span class="op">)</span><span class="op">[[</span><span class="va">table</span><span class="op">$</span><span class="va">data</span><span class="op">[</span><span class="va">i</span><span class="op">]</span><span class="op">]</span><span class="op">]</span>
  <span class="va">alpha</span> <span class="op">&lt;-</span> <span class="fl">1</span><span class="op">*</span><span class="op">(</span><span class="va">table</span><span class="op">$</span><span class="va">alpha</span><span class="op">[</span><span class="va">i</span><span class="op">]</span><span class="op">==</span><span class="st">"lasso"</span><span class="op">)</span>
  <span class="va">loss</span><span class="op">[[</span><span class="va">i</span><span class="op">]</span><span class="op">]</span> <span class="op">&lt;-</span> <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>,alpha.base<span class="op">=</span><span class="va">alpha</span>,
                foldid.ext<span class="op">=</span><span class="va">foldid.ext</span>,foldid.int<span class="op">=</span><span class="va">foldid.int</span><span class="op">)</span> <span class="co"># add joinet::</span>
Armin Rauschenberger's avatar
Armin Rauschenberger committed
439
  <span class="co">#fit[[i]] &lt;- joinet(Y=y,X=x,alpha.base=alpha,foldid=foldid.int)</span>
Armin Rauschenberger's avatar
Armin Rauschenberger committed
440
<span class="op">}</span>
Armin Rauschenberger's avatar
Armin Rauschenberger committed
441

Armin Rauschenberger's avatar
Armin Rauschenberger committed
442
443
444
445
<span class="fu"><a href="https://rdrr.io/r/base/save.html">save</a></span><span class="op">(</span><span class="va">table</span>,<span class="va">loss</span>,file<span class="op">=</span><span class="st">"results/external.RData"</span><span class="op">)</span>
<span class="fu"><a href="https://rdrr.io/r/base/writeLines.html">writeLines</a></span><span class="op">(</span>text<span class="op">=</span><span class="fu"><a href="https://rdrr.io/r/utils/capture.output.html">capture.output</a></span><span class="op">(</span><span class="fu">utils</span><span class="fu">::</span><span class="fu"><a href="https://rdrr.io/r/utils/sessionInfo.html">sessionInfo</a></span><span class="op">(</span><span class="op">)</span>,<span class="fu"><a href="https://rdrr.io/r/base/cat.html">cat</a></span><span class="op">(</span><span class="st">"\n"</span><span class="op">)</span>,<span class="fu">sessioninfo</span><span class="fu">::</span><span class="fu"><a href="https://rdrr.io/pkg/sessioninfo/man/session_info.html">session_info</a></span><span class="op">(</span><span class="op">)</span><span class="op">)</span>,con<span class="op">=</span><span class="st">"results/info_app.txt"</span><span class="op">)</span></code></pre></div>
<div class="sourceCode" id="cb9"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="fu"><a href="https://rdrr.io/r/base/load.html">load</a></span><span class="op">(</span><span class="st">"results/internal.RData"</span><span class="op">)</span>
Armin Rauschenberger's avatar
Armin Rauschenberger committed
446
447

<span class="co"># standardised loss</span>
Armin Rauschenberger's avatar
Armin Rauschenberger committed
448
449
450
451
452
453
454
<span class="va">vars</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/unique.html">unique</a></span><span class="op">(</span><span class="va">table</span><span class="op">$</span><span class="va">var</span><span class="op">)</span>
<span class="va">former</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/t.html">t</a></span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/base/lapply.html">sapply</a></span><span class="op">(</span><span class="va">loss</span>,<span class="kw">function</span><span class="op">(</span><span class="va">x</span><span class="op">)</span> <span class="va">x</span><span class="op">[</span><span class="st">"base"</span>,<span class="op">]</span><span class="op">)</span><span class="op">)</span>
<span class="va">min</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/lapply.html">sapply</a></span><span class="op">(</span><span class="va">vars</span>,<span class="kw">function</span><span class="op">(</span><span class="va">x</span><span class="op">)</span> <span class="fu"><a href="https://rdrr.io/r/base/Extremes.html">min</a></span><span class="op">(</span><span class="va">former</span><span class="op">[</span><span class="va">table</span><span class="op">$</span><span class="va">var</span><span class="op">==</span><span class="va">x</span>,<span class="op">]</span><span class="op">)</span><span class="op">)</span>
<span class="va">max</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/lapply.html">sapply</a></span><span class="op">(</span><span class="va">vars</span>,<span class="kw">function</span><span class="op">(</span><span class="va">x</span><span class="op">)</span> <span class="fu"><a href="https://rdrr.io/r/base/Extremes.html">max</a></span><span class="op">(</span><span class="va">former</span><span class="op">[</span><span class="va">table</span><span class="op">$</span><span class="va">var</span><span class="op">==</span><span class="va">x</span>,<span class="op">]</span><span class="op">)</span><span class="op">)</span>
<span class="va">index</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/match.html">match</a></span><span class="op">(</span>x<span class="op">=</span><span class="va">table</span><span class="op">$</span><span class="va">var</span>,table<span class="op">=</span><span class="va">vars</span><span class="op">)</span>
<span class="va">former</span> <span class="op">&lt;-</span> <span class="op">(</span><span class="va">former</span><span class="op">-</span><span class="va">min</span><span class="op">[</span><span class="va">index</span><span class="op">]</span><span class="op">)</span><span class="op">/</span><span class="op">(</span><span class="va">max</span><span class="op">[</span><span class="va">index</span><span class="op">]</span><span class="op">-</span><span class="va">min</span><span class="op">[</span><span class="va">index</span><span class="op">]</span><span class="op">)</span>
<span class="fu"><a href="https://rdrr.io/r/base/dimnames.html">dimnames</a></span><span class="op">(</span><span class="va">former</span><span class="op">)</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/list.html">list</a></span><span class="op">(</span><span class="va">table</span><span class="op">$</span><span class="va">var</span>,<span class="fu"><a href="https://rdrr.io/r/base/seq.html">seq_len</a></span><span class="op">(</span><span class="fl">3</span><span class="op">)</span><span class="op">)</span>
Armin Rauschenberger's avatar
Armin Rauschenberger committed
455
456

<span class="co"># percentage change</span>
Armin Rauschenberger's avatar
Armin Rauschenberger committed
457
458
<span class="va">change</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/t.html">t</a></span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/base/lapply.html">sapply</a></span><span class="op">(</span><span class="va">loss</span>,<span class="kw">function</span><span class="op">(</span><span class="va">x</span><span class="op">)</span> <span class="fl">100</span><span class="op">*</span><span class="op">(</span><span class="va">x</span><span class="op">[</span><span class="st">"meta"</span>,<span class="op">]</span><span class="op">-</span><span class="va">x</span><span class="op">[</span><span class="st">"base"</span>,<span class="op">]</span><span class="op">)</span><span class="op">/</span><span class="va">x</span><span class="op">[</span><span class="st">"base"</span>,<span class="op">]</span><span class="op">)</span><span class="op">)</span>
<span class="fu"><a href="https://rdrr.io/r/base/dimnames.html">dimnames</a></span><span class="op">(</span><span class="va">change</span><span class="op">)</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/list.html">list</a></span><span class="op">(</span><span class="va">table</span><span class="op">$</span><span class="va">var</span>,<span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op">(</span><span class="st">"1st"</span>,<span class="st">"2nd"</span>,<span class="st">"3rd"</span><span class="op">)</span><span class="op">)</span>
Armin Rauschenberger's avatar
Armin Rauschenberger committed
459
460

<span class="co"># overview</span>
Armin Rauschenberger's avatar
Armin Rauschenberger committed
461
<span class="co">#grDevices::pdf(file="manuscript/figure_INT.pdf",width=6,height=3,pointsize=12)</span>
Armin Rauschenberger's avatar
Armin Rauschenberger committed
462
463
464
465
466
467
<span class="fu">grDevices</span><span class="fu">::</span><span class="fu"><a href="https://rdrr.io/r/grDevices/postscript.html">postscript</a></span><span class="op">(</span>file<span class="op">=</span><span class="st">"manuscript/figure_INT.eps"</span>,width<span class="op">=</span><span class="fl">6</span>,height<span class="op">=</span><span class="fl">3</span>,pointsize<span class="op">=</span><span class="fl">12</span><span class="op">)</span>
<span class="fu">graphics</span><span class="fu">::</span><span class="fu"><a href="https://rdrr.io/r/graphics/par.html">par</a></span><span class="op">(</span>mfrow<span class="op">=</span><span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op">(</span><span class="fl">2</span>,<span class="fl">3</span><span class="op">)</span>,mar<span class="op">=</span><span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op">(</span><span class="fl">0.1</span>,<span class="fl">3</span>,<span class="fl">2</span>,<span class="fl">0.1</span><span class="op">)</span>,oma<span class="op">=</span><span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op">(</span><span class="fl">0</span>,<span class="fl">1.1</span>,<span class="fl">1</span>,<span class="fl">0</span><span class="op">)</span><span class="op">)</span>
<span class="kw">for</span><span class="op">(</span><span class="va">alpha</span> <span class="kw">in</span> <span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op">(</span><span class="st">"lasso"</span>,<span class="st">"ridge"</span><span class="op">)</span><span class="op">)</span><span class="op">{</span>
  <span class="kw">for</span><span class="op">(</span><span class="va">data</span> <span class="kw">in</span> <span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op">(</span><span class="st">"clinic"</span>,<span class="st">"omics"</span>,<span class="st">"both"</span><span class="op">)</span><span class="op">)</span><span class="op">{</span>
    <span class="va">cond</span> <span class="op">&lt;-</span> <span class="va">table</span><span class="op">$</span><span class="va">alpha</span><span class="op">==</span><span class="va">alpha</span> <span class="op">&amp;</span> <span class="va">table</span><span class="op">$</span><span class="va">data</span><span class="op">==</span><span class="va">data</span>
    <span class="fu">joinet</span><span class="fu">:::</span><span class="fu">plot.matrix</span><span class="op">(</span>X<span class="op">=</span><span class="va">change</span><span class="op">[</span><span class="va">cond</span>,<span class="op">]</span>,range<span class="op">=</span><span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op">(</span><span class="op">-</span><span class="fl">50</span>,<span class="fl">50</span><span class="op">)</span>,cex<span class="op">=</span><span class="fl">0.7</span><span class="op">)</span>
Armin Rauschenberger's avatar
Armin Rauschenberger committed
468
    <span class="co">#graphics::title(main=paste0(alpha,"-",data),col.main="red",line=0) # check</span>
Armin Rauschenberger's avatar
Armin Rauschenberger committed
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
    <span class="kw">if</span><span class="op">(</span><span class="va">alpha</span><span class="op">==</span><span class="st">"lasso"</span><span class="op">)</span><span class="op">{</span><span class="fu">graphics</span><span class="fu">::</span><span class="fu"><a href="https://rdrr.io/r/graphics/mtext.html">mtext</a></span><span class="op">(</span>text<span class="op">=</span><span class="va">data</span>,side<span class="op">=</span><span class="fl">3</span>,line<span class="op">=</span><span class="fl">1.5</span>,cex<span class="op">=</span><span class="fl">0.8</span><span class="op">)</span><span class="op">}</span>
    <span class="kw">if</span><span class="op">(</span><span class="va">data</span><span class="op">==</span><span class="st">"clinic"</span><span class="op">)</span><span class="op">{</span><span class="fu">graphics</span><span class="fu">::</span><span class="fu"><a href="https://rdrr.io/r/graphics/mtext.html">mtext</a></span><span class="op">(</span>text<span class="op">=</span><span class="va">alpha</span>,side<span class="op">=</span><span class="fl">2</span>,line<span class="op">=</span><span class="fl">3</span>,cex<span class="op">=</span><span class="fl">0.8</span><span class="op">)</span><span class="op">}</span>
  <span class="op">}</span>
<span class="op">}</span>
<span class="fu">grDevices</span><span class="fu">::</span><span class="fu"><a href="https://rdrr.io/r/grDevices/dev.html">dev.off</a></span><span class="op">(</span><span class="op">)</span>

<span class="va">TEMP</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/tapply.html">tapply</a></span><span class="op">(</span>X<span class="op">=</span><span class="fu"><a href="https://rdrr.io/r/base/colSums.html">rowMeans</a></span><span class="op">(</span><span class="va">change</span><span class="op">)</span>,INDEX<span class="op">=</span><span class="va">table</span><span class="op">$</span><span class="va">var</span>,FUN<span class="op">=</span><span class="va">mean</span><span class="op">)</span><span class="op">[</span><span class="va">vars</span><span class="op">]</span>
<span class="fu"><a href="https://rdrr.io/r/base/mean.html">mean</a></span><span class="op">(</span><span class="va">change</span><span class="op">&lt;</span><span class="fl">0</span><span class="op">)</span>
<span class="fu"><a href="https://rdrr.io/r/base/Round.html">round</a></span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/base/tapply.html">tapply</a></span><span class="op">(</span>X<span class="op">=</span><span class="fu"><a href="https://rdrr.io/r/base/colSums.html">rowMeans</a></span><span class="op">(</span><span class="va">change</span><span class="op">)</span>,INDEX<span class="op">=</span><span class="va">table</span><span class="op">$</span><span class="va">data</span>,FUN<span class="op">=</span><span class="va">mean</span><span class="op">)</span>,digits<span class="op">=</span><span class="fl">2</span><span class="op">)</span>
<span class="fu"><a href="https://rdrr.io/r/base/Round.html">round</a></span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/base/tapply.html">tapply</a></span><span class="op">(</span>X<span class="op">=</span><span class="fu"><a href="https://rdrr.io/r/base/colSums.html">rowMeans</a></span><span class="op">(</span><span class="va">change</span><span class="op">)</span>,INDEX<span class="op">=</span><span class="va">table</span><span class="op">$</span><span class="va">alpha</span>,FUN<span class="op">=</span><span class="va">mean</span><span class="op">)</span>,digits<span class="op">=</span><span class="fl">2</span><span class="op">)</span>
<span class="fu"><a href="https://rdrr.io/r/base/Round.html">round</a></span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/base/colSums.html">colMeans</a></span><span class="op">(</span><span class="va">change</span><span class="op">)</span>,digits<span class="op">=</span><span class="fl">2</span><span class="op">)</span></code></pre></div>
<div class="sourceCode" id="cb10"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="fu"><a href="https://rdrr.io/r/base/load.html">load</a></span><span class="op">(</span><span class="st">"results/external.RData"</span><span class="op">)</span>

<span class="va">data</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op">(</span><span class="st">"clinic"</span>,<span class="st">"omics"</span>,<span class="st">"both"</span><span class="op">)</span>
<span class="va">alpha</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op">(</span><span class="st">"lasso"</span>,<span class="st">"ridge"</span><span class="op">)</span>
<span class="va">step</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op">(</span><span class="st">"V04"</span>,<span class="st">"V06"</span>,<span class="st">"V08"</span><span class="op">)</span>
Armin Rauschenberger's avatar
Armin Rauschenberger committed
486
487

<span class="co"># percentage change</span>
Armin Rauschenberger's avatar
Armin Rauschenberger committed
488
<span class="va">change</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/t.html">t</a></span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/base/lapply.html">sapply</a></span><span class="op">(</span><span class="va">loss</span>,<span class="kw">function</span><span class="op">(</span><span class="va">x</span><span class="op">)</span> <span class="fl">100</span><span class="op">*</span><span class="op">(</span><span class="va">x</span><span class="op">[</span><span class="st">"meta"</span>,<span class="op">]</span><span class="op">-</span><span class="va">x</span><span class="op">[</span><span class="st">"base"</span>,<span class="op">]</span><span class="op">)</span><span class="op">/</span><span class="va">x</span><span class="op">[</span><span class="st">"base"</span>,<span class="op">]</span><span class="op">)</span><span class="op">)</span>
Armin Rauschenberger's avatar
Armin Rauschenberger committed
489
490

<span class="co"># overview</span>
Armin Rauschenberger's avatar
Armin Rauschenberger committed
491
492
493
<span class="va">vars</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/unique.html">unique</a></span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op">(</span><span class="va">table</span><span class="op">$</span><span class="va">var1</span>,<span class="va">table</span><span class="op">$</span><span class="va">var2</span><span class="op">)</span><span class="op">)</span>
<span class="va">temp</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/matrix.html">matrix</a></span><span class="op">(</span><span class="cn">NA</span>,nrow<span class="op">=</span><span class="fu"><a href="https://rdrr.io/r/base/length.html">length</a></span><span class="op">(</span><span class="va">vars</span><span class="op">)</span>,ncol<span class="op">=</span><span class="fu"><a href="https://rdrr.io/r/base/length.html">length</a></span><span class="op">(</span><span class="va">vars</span><span class="op">)</span>,dimnames<span class="op">=</span><span class="fu"><a href="https://rdrr.io/r/base/list.html">list</a></span><span class="op">(</span><span class="va">vars</span>,<span class="va">vars</span><span class="op">)</span><span class="op">)</span>
<span class="va">array</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/array.html">array</a></span><span class="op">(</span>data<span class="op">=</span><span class="fu"><a href="https://rdrr.io/r/base/list.html">list</a></span><span class="op">(</span><span class="va">temp</span><span class="op">)</span>,dim<span class="op">=</span><span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op">(</span><span class="fl">3</span>,<span class="fl">2</span>,<span class="fl">3</span><span class="op">)</span>,dimnames<span class="op">=</span><span class="fu"><a href="https://rdrr.io/r/base/list.html">list</a></span><span class="op">(</span><span class="va">data</span>,<span class="va">alpha</span>,<span class="va">step</span><span class="op">)</span><span class="op">)</span>
Armin Rauschenberger's avatar
Armin Rauschenberger committed
494
<span class="co">#grDevices::pdf(file="manuscript/figure_EXT.pdf",width=7.5,height=10,pointsize=14)</span>
Armin Rauschenberger's avatar
Armin Rauschenberger committed
495
496
497
498
499
500
501
502
503
<span class="fu">grDevices</span><span class="fu">::</span><span class="fu"><a href="https://rdrr.io/r/grDevices/postscript.html">postscript</a></span><span class="op">(</span>file<span class="op">=</span><span class="st">"manuscript/figure_EXT.eps"</span>,width<span class="op">=</span><span class="fl">7.5</span>,height<span class="op">=</span><span class="fl">10</span>,pointsize<span class="op">=</span><span class="fl">14</span><span class="op">)</span>
<span class="fu">graphics</span><span class="fu">::</span><span class="fu"><a href="https://rdrr.io/r/graphics/par.html">par</a></span><span class="op">(</span>mfrow<span class="op">=</span><span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op">(</span><span class="fl">6</span>,<span class="fl">3</span><span class="op">)</span>,mar<span class="op">=</span><span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op">(</span><span class="fl">0.1</span>,<span class="fl">2.5</span>,<span class="fl">2.5</span>,<span class="fl">0.1</span><span class="op">)</span>,oma<span class="op">=</span><span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op">(</span><span class="fl">0</span>,<span class="fl">1</span>,<span class="fl">2</span>,<span class="fl">0</span><span class="op">)</span><span class="op">)</span>
<span class="kw">for</span><span class="op">(</span><span class="va">i</span> <span class="kw">in</span> <span class="va">data</span><span class="op">)</span><span class="op">{</span>
  <span class="kw">for</span><span class="op">(</span><span class="va">j</span> <span class="kw">in</span> <span class="va">alpha</span><span class="op">)</span><span class="op">{</span>
    <span class="kw">for</span><span class="op">(</span><span class="va">k</span> <span class="kw">in</span> <span class="va">step</span><span class="op">)</span><span class="op">{</span>
      <span class="va">cond</span> <span class="op">&lt;-</span> <span class="va">table</span><span class="op">$</span><span class="va">data</span><span class="op">==</span><span class="va">i</span> <span class="op">&amp;</span> <span class="va">table</span><span class="op">$</span><span class="va">alpha</span><span class="op">==</span><span class="va">j</span> <span class="op">&amp;</span> <span class="va">table</span><span class="op">$</span><span class="va">step</span><span class="op">==</span><span class="va">k</span>
      <span class="va">array</span><span class="op">[</span><span class="va">i</span>,<span class="va">j</span>,<span class="va">k</span><span class="op">]</span><span class="op">[[</span><span class="fl">1</span><span class="op">]</span><span class="op">]</span><span class="op">[</span><span class="fu"><a href="https://rdrr.io/r/base/cbind.html">cbind</a></span><span class="op">(</span><span class="va">table</span><span class="op">$</span><span class="va">var1</span>,<span class="va">table</span><span class="op">$</span><span class="va">var2</span><span class="op">)</span><span class="op">[</span><span class="va">cond</span>,<span class="op">]</span><span class="op">]</span> <span class="op">&lt;-</span> <span class="va">change</span><span class="op">[</span><span class="va">cond</span>,<span class="fl">1</span><span class="op">]</span>
      <span class="va">array</span><span class="op">[</span><span class="va">i</span>,<span class="va">j</span>,<span class="va">k</span><span class="op">]</span><span class="op">[[</span><span class="fl">1</span><span class="op">]</span><span class="op">]</span><span class="op">[</span><span class="fu"><a href="https://rdrr.io/r/base/cbind.html">cbind</a></span><span class="op">(</span><span class="va">table</span><span class="op">$</span><span class="va">var2</span>,<span class="va">table</span><span class="op">$</span><span class="va">var1</span><span class="op">)</span><span class="op">[</span><span class="va">cond</span>,<span class="op">]</span><span class="op">]</span> <span class="op">&lt;-</span> <span class="va">change</span><span class="op">[</span><span class="va">cond</span>,<span class="fl">2</span><span class="op">]</span>
      <span class="fu">joinet</span><span class="fu">:::</span><span class="fu">plot.matrix</span><span class="op">(</span><span class="va">array</span><span class="op">[</span><span class="va">i</span>,<span class="va">j</span>,<span class="va">k</span><span class="op">]</span><span class="op">[[</span><span class="fl">1</span><span class="op">]</span><span class="op">]</span>,margin<span class="op">=</span><span class="fl">0</span>,las<span class="op">=</span><span class="fl">2</span>,range<span class="op">=</span><span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op">(</span><span class="op">-</span><span class="fl">20</span>,<span class="fl">20</span><span class="op">)</span>,cex<span class="op">=</span><span class="fl">0.6</span><span class="op">)</span>
Armin Rauschenberger's avatar
Armin Rauschenberger committed
504
      <span class="co">#graphics::title(main=paste0(i,"-",j,"-",k),col.main="red",line=0) # check</span>