Commit 80f568bf authored by Armin Rauschenberger's avatar Armin Rauschenberger

automation

parent 57cb6787
......@@ -3,7 +3,7 @@ Version: 0.0.1
Title: Stacked Elastic Net
Description: Implements stacked elastic net regression. The elastic net generalises ridge and lasso regularisation (Zou 2005, <doi:10.1111/j.1467-9868.2005.00503.x>). Instead of fixing or tuning the mixing parameter alpha, we combine multiple alpha by stacked generalisation (Wolpert 1992 <doi:10.1016/S0893-6080(05)80023-1>).
Depends: R (>= 3.0.0)
Imports: glmnet, survival, palasso, cornet, joinet
Imports: glmnet, survival, palasso, cornet, joinet, CVXR, Matrix
Suggests: knitr, testthat, MASS
Enhances: RColorBrewer
Authors@R: person("Armin","Rauschenberger",email="armin.rauschenberger@uni.lu",role=c("aut","cre"))
......
This diff is collapsed.
......@@ -152,8 +152,7 @@ positive integer, or <code>NULL</code></p></td>
<span class='no'>n</span> <span class='kw'>&lt;-</span> <span class='fl'>30</span>; <span class='no'>p</span> <span class='kw'>&lt;-</span> <span class='fl'>50</span>
<span class='no'>y</span> <span class='kw'>&lt;-</span> <span class='fu'><a href='https://rdrr.io/r/stats/Normal.html'>rnorm</a></span>(<span class='kw'>n</span><span class='kw'>=</span><span class='no'>n</span>)
<span class='no'>X</span> <span class='kw'>&lt;-</span> <span class='fu'><a href='https://rdrr.io/r/base/matrix.html'>matrix</a></span>(<span class='fu'><a href='https://rdrr.io/r/stats/Normal.html'>rnorm</a></span>(<span class='no'>n</span>*<span class='no'>p</span>),<span class='kw'>nrow</span><span class='kw'>=</span><span class='no'>n</span>,<span class='kw'>ncol</span><span class='kw'>=</span><span class='no'>p</span>)
<span class='no'>object</span> <span class='kw'>&lt;-</span> <span class='fu'><a href='starnet.html'>starnet</a></span>(<span class='kw'>y</span><span class='kw'>=</span><span class='no'>y</span>,<span class='kw'>X</span><span class='kw'>=</span><span class='no'>X</span>)
<span class='no'>coef</span> <span class='kw'>&lt;-</span> <span class='fu'><a href='https://rdrr.io/r/stats/coef.html'>coef</a></span>(<span class='no'>object</span>)</div></pre>
<span class='no'>object</span> <span class='kw'>&lt;-</span> <span class='fu'><a href='starnet.html'>starnet</a></span>(<span class='kw'>y</span><span class='kw'>=</span><span class='no'>y</span>,<span class='kw'>X</span><span class='kw'>=</span><span class='no'>X</span>)</div><div class='output co'>#&gt; <span class='message'>alpha1 0.87 </span></div><div class='output co'>#&gt; <span class='message'>0.082 _ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0</span></div><div class='input'><span class='no'>coef</span> <span class='kw'>&lt;-</span> <span class='fu'><a href='https://rdrr.io/r/stats/coef.html'>coef</a></span>(<span class='no'>object</span>)</div></pre>
</div>
<div class="col-md-3 hidden-xs hidden-sm" id="sidebar">
<h2>Contents</h2>
......
docs/reference/cv.starnet-1.png

8.85 KB | W: | H:

docs/reference/cv.starnet-1.png

8 KB | W: | H:

docs/reference/cv.starnet-1.png
docs/reference/cv.starnet-1.png
docs/reference/cv.starnet-1.png
docs/reference/cv.starnet-1.png
  • 2-up
  • Swipe
  • Onion skin
......@@ -124,8 +124,10 @@
</div>
<pre class="usage"><span class='fu'>cv.starnet</span>(<span class='no'>y</span>, <span class='no'>X</span>, <span class='kw'>family</span> <span class='kw'>=</span> <span class='st'>"gaussian"</span>, <span class='kw'>nalpha</span> <span class='kw'>=</span> <span class='fl'>21</span>, <span class='kw'>alpha</span> <span class='kw'>=</span> <span class='kw'>NULL</span>,
<span class='kw'>nfolds</span> <span class='kw'>=</span> <span class='fl'>5</span>, <span class='kw'>foldid</span> <span class='kw'>=</span> <span class='kw'>NULL</span>, <span class='kw'>type.measure</span> <span class='kw'>=</span> <span class='st'>"deviance"</span>,
<span class='kw'>alpha.meta</span> <span class='kw'>=</span> <span class='fl'>0</span>, <span class='kw'>grouped</span> <span class='kw'>=</span> <span class='fl'>TRUE</span>, <span class='kw'>nzero</span> <span class='kw'>=</span> <span class='kw'>NULL</span>, <span class='no'>...</span>)</pre>
<span class='kw'>nfolds.ext</span> <span class='kw'>=</span> <span class='fl'>10</span>, <span class='kw'>nfolds.int</span> <span class='kw'>=</span> <span class='fl'>10</span>, <span class='kw'>foldid.ext</span> <span class='kw'>=</span> <span class='kw'>NULL</span>,
<span class='kw'>foldid.int</span> <span class='kw'>=</span> <span class='kw'>NULL</span>, <span class='kw'>type.measure</span> <span class='kw'>=</span> <span class='st'>"deviance"</span>, <span class='kw'>alpha.meta</span> <span class='kw'>=</span> <span class='fl'>1</span>,
<span class='kw'>grouped</span> <span class='kw'>=</span> <span class='fl'>TRUE</span>, <span class='kw'>nzero</span> <span class='kw'>=</span> <span class='kw'>NULL</span>, <span class='kw'>intercept</span> <span class='kw'>=</span> <span class='kw'>NULL</span>,
<span class='kw'>upper.limit</span> <span class='kw'>=</span> <span class='kw'>NULL</span>, <span class='kw'>unit.sum</span> <span class='kw'>=</span> <span class='kw'>NULL</span>, <span class='no'>...</span>)</pre>
<h2 class="hasAnchor" id="arguments"><a class="anchor" href="#arguments"></a>Arguments</h2>
<table class="ref-arguments">
......@@ -156,14 +158,8 @@ vector of values between \(0\) (ridge) and \(1\) (lasso);
or <code>NULL</code> (equidistance)</p></td>
</tr>
<tr>
<th>nfolds</th>
<td><p>number of folds</p></td>
</tr>
<tr>
<th>foldid</th>
<td><p>fold identifiers<strong>:</strong>
vector with entries between \(1\) and <code>nfolds</code>;
or <code>NULL</code> (balance)</p></td>
<th>nfolds.ext, nfolds.int, foldid.ext, foldid.int</th>
<td><p>(number of) external/internal folds</p></td>
</tr>
<tr>
<th>type.measure</th>
......@@ -187,6 +183,18 @@ vector of values between \(0\) (ridge) and \(1\) (lasso),
scalar/vector including positive integer(s) or <code>NA</code>;
or <code>NULL</code> (no posthoc feature selection)</p></td>
</tr>
<tr>
<th>intercept</th>
<td><p>settings for meta-learner<strong>:</strong> logical</p></td>
</tr>
<tr>
<th>upper.limit</th>
<td><p>settings for meta-learner<strong>:</strong> logical</p></td>
</tr>
<tr>
<th>unit.sum</th>
<td><p>settings for meta-learner<strong>:</strong> logical</p></td>
</tr>
<tr>
<th>...</th>
<td><p>further arguments (not applicable)</p></td>
......@@ -199,7 +207,7 @@ or <code>NULL</code> (no posthoc feature selection)</p></td>
<span class='no'>n</span> <span class='kw'>&lt;-</span> <span class='fl'>50</span>; <span class='no'>p</span> <span class='kw'>&lt;-</span> <span class='fl'>20</span>
<span class='no'>X</span> <span class='kw'>&lt;-</span> <span class='fu'><a href='https://rdrr.io/r/base/matrix.html'>matrix</a></span>(<span class='fu'><a href='https://rdrr.io/r/stats/Normal.html'>rnorm</a></span>(<span class='no'>n</span>*<span class='no'>p</span>),<span class='kw'>nrow</span><span class='kw'>=</span><span class='no'>n</span>,<span class='kw'>ncol</span><span class='kw'>=</span><span class='no'>p</span>)
<span class='no'>y</span> <span class='kw'>&lt;-</span> <span class='fu'><a href='https://rdrr.io/r/stats/Normal.html'>rnorm</a></span>(<span class='kw'>n</span><span class='kw'>=</span><span class='no'>n</span>,<span class='kw'>mean</span><span class='kw'>=</span><span class='fu'><a href='https://rdrr.io/r/base/colSums.html'>rowSums</a></span>(<span class='no'>X</span>[,<span class='fl'>1</span>:<span class='fl'>20</span>]))
<span class='no'>loss</span> <span class='kw'>&lt;-</span> <span class='fu'>cv.starnet</span>(<span class='kw'>y</span><span class='kw'>=</span><span class='no'>y</span>,<span class='kw'>X</span><span class='kw'>=</span><span class='no'>X</span>)</div><div class='img'><img src='cv.starnet-1.png' alt='' width='700' height='433' /></div><div class='input'>
<span class='no'>loss</span> <span class='kw'>&lt;-</span> <span class='fu'>cv.starnet</span>(<span class='kw'>y</span><span class='kw'>=</span><span class='no'>y</span>,<span class='kw'>X</span><span class='kw'>=</span><span class='no'>X</span>)</div><div class='output co'>#&gt; <span class='message'>alpha1 2.6 </span></div><div class='output co'>#&gt; <span class='message'>0.044 _ 1.004 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.005</span></div><div class='output co'>#&gt; <span class='message'>alpha1 2.51 </span></div><div class='output co'>#&gt; <span class='message'>-0.112 _ 0 0.974 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0</span></div><div class='output co'>#&gt; <span class='message'>alpha1 2.56 </span></div><div class='output co'>#&gt; <span class='message'>0.006 _ 0.713 0.297 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0</span></div><div class='output co'>#&gt; <span class='message'>alpha1 1.89 </span></div><div class='output co'>#&gt; <span class='message'>-0.017 _ 0.052 0.928 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0</span></div><div class='output co'>#&gt; <span class='message'>alpha1 2 </span></div><div class='output co'>#&gt; <span class='message'>0.048 _ 1.052 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0</span></div><div class='output co'>#&gt; <span class='message'>alpha1 2.55 </span></div><div class='output co'>#&gt; <span class='message'>0.004 _ 0.017 0.958 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0</span></div><div class='output co'>#&gt; <span class='message'>alpha1 2.27 </span></div><div class='output co'>#&gt; <span class='message'>-0.07 _ 0 0.962 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0</span></div><div class='output co'>#&gt; <span class='message'>alpha1 2.24 </span></div><div class='output co'>#&gt; <span class='message'>0.024 _ 0 0.941 0.017 0.014 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0</span></div><div class='output co'>#&gt; <span class='message'>alpha1 2.05 </span></div><div class='output co'>#&gt; <span class='message'>-0.078 _ 0.47 0.523 0 0 0 0.021 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0</span></div><div class='output co'>#&gt; <span class='message'>alpha1 2.64 </span></div><div class='output co'>#&gt; <span class='message'>-0.069 _ 1.03 0 0 0 0 0 0 0.003 0 0 0 0 0 0 0 0 0 0 0 0 0</span></div><div class='img'><img src='cv.starnet-1.png' alt='' width='700' height='433' /></div><div class='input'>
</div></pre>
</div>
<div class="col-md-3 hidden-xs hidden-sm" id="sidebar">
......
......@@ -123,7 +123,7 @@
<p>Prints object of class <a href='starnet.html'>starnet</a>.</p>
</div>
<pre class="usage"><span class='fu'>.simulate</span>(<span class='no'>n</span>, <span class='no'>p</span>, <span class='no'>mode</span>)</pre>
<pre class="usage"><span class='fu'>.simulate</span>(<span class='no'>n</span>, <span class='no'>p</span>, <span class='no'>mode</span>, <span class='kw'>family</span> <span class='kw'>=</span> <span class='st'>"gaussian"</span>)</pre>
<h2 class="hasAnchor" id="arguments"><a class="anchor" href="#arguments"></a>Arguments</h2>
<table class="ref-arguments">
......@@ -142,6 +142,10 @@ positive integer</p></td>
<th>mode</th>
<td><p>character <code>"sparse"</code>, <code>"dense"</code> or <code>"blocks"</code></p></td>
</tr>
<tr>
<th>family</th>
<td><p><code>"gaussian"</code>, <code>"binomial"</code> or <code>"poisson"</code></p></td>
</tr>
</table>
......
......@@ -161,8 +161,7 @@ positive integer, or <code>NULL</code></p></td>
<span class='no'>n</span> <span class='kw'>&lt;-</span> <span class='fl'>30</span>; <span class='no'>p</span> <span class='kw'>&lt;-</span> <span class='fl'>50</span>
<span class='no'>y</span> <span class='kw'>&lt;-</span> <span class='fu'><a href='https://rdrr.io/r/stats/Normal.html'>rnorm</a></span>(<span class='kw'>n</span><span class='kw'>=</span><span class='no'>n</span>)
<span class='no'>X</span> <span class='kw'>&lt;-</span> <span class='fu'><a href='https://rdrr.io/r/base/matrix.html'>matrix</a></span>(<span class='fu'><a href='https://rdrr.io/r/stats/Normal.html'>rnorm</a></span>(<span class='no'>n</span>*<span class='no'>p</span>),<span class='kw'>nrow</span><span class='kw'>=</span><span class='no'>n</span>,<span class='kw'>ncol</span><span class='kw'>=</span><span class='no'>p</span>)
<span class='no'>object</span> <span class='kw'>&lt;-</span> <span class='fu'><a href='starnet.html'>starnet</a></span>(<span class='kw'>y</span><span class='kw'>=</span><span class='no'>y</span>,<span class='kw'>X</span><span class='kw'>=</span><span class='no'>X</span>)
<span class='no'>y_hat</span> <span class='kw'>&lt;-</span> <span class='fu'><a href='https://rdrr.io/r/stats/predict.html'>predict</a></span>(<span class='no'>object</span>,<span class='kw'>newx</span><span class='kw'>=</span><span class='no'>X</span>)</div></pre>
<span class='no'>object</span> <span class='kw'>&lt;-</span> <span class='fu'><a href='starnet.html'>starnet</a></span>(<span class='kw'>y</span><span class='kw'>=</span><span class='no'>y</span>,<span class='kw'>X</span><span class='kw'>=</span><span class='no'>X</span>)</div><div class='output co'>#&gt; <span class='message'>alpha1 0.87 </span></div><div class='output co'>#&gt; <span class='message'>0.082 _ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0</span></div><div class='input'><span class='no'>y_hat</span> <span class='kw'>&lt;-</span> <span class='fu'><a href='https://rdrr.io/r/stats/predict.html'>predict</a></span>(<span class='no'>object</span>,<span class='kw'>newx</span><span class='kw'>=</span><span class='no'>X</span>[<span class='fu'><a href='https://rdrr.io/r/base/c.html'>c</a></span>(<span class='fl'>1</span>),,<span class='kw'>drop</span><span class='kw'>=</span><span class='fl'>FALSE</span>])</div></pre>
</div>
<div class="col-md-3 hidden-xs hidden-sm" id="sidebar">
<h2>Contents</h2>
......
......@@ -145,8 +145,7 @@
<span class='no'>n</span> <span class='kw'>&lt;-</span> <span class='fl'>30</span>; <span class='no'>p</span> <span class='kw'>&lt;-</span> <span class='fl'>20</span>
<span class='no'>y</span> <span class='kw'>&lt;-</span> <span class='fu'><a href='https://rdrr.io/r/stats/Normal.html'>rnorm</a></span>(<span class='kw'>n</span><span class='kw'>=</span><span class='no'>n</span>)
<span class='no'>X</span> <span class='kw'>&lt;-</span> <span class='fu'><a href='https://rdrr.io/r/base/matrix.html'>matrix</a></span>(<span class='fu'><a href='https://rdrr.io/r/stats/Normal.html'>rnorm</a></span>(<span class='no'>n</span>*<span class='no'>p</span>),<span class='kw'>nrow</span><span class='kw'>=</span><span class='no'>n</span>,<span class='kw'>ncol</span><span class='kw'>=</span><span class='no'>p</span>)
<span class='no'>object</span> <span class='kw'>&lt;-</span> <span class='fu'><a href='starnet.html'>starnet</a></span>(<span class='kw'>y</span><span class='kw'>=</span><span class='no'>y</span>,<span class='kw'>X</span><span class='kw'>=</span><span class='no'>X</span>)
<span class='fu'><a href='https://rdrr.io/r/base/print.html'>print</a></span>(<span class='no'>object</span>)</div><div class='output co'>#&gt; stacked "gaussian" elastic net </div><div class='input'>
<span class='no'>object</span> <span class='kw'>&lt;-</span> <span class='fu'><a href='starnet.html'>starnet</a></span>(<span class='kw'>y</span><span class='kw'>=</span><span class='no'>y</span>,<span class='kw'>X</span><span class='kw'>=</span><span class='no'>X</span>)</div><div class='output co'>#&gt; <span class='message'>alpha1 0.92 </span></div><div class='output co'>#&gt; <span class='message'>0.082 _ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0</span></div><div class='input'><span class='fu'><a href='https://rdrr.io/r/base/print.html'>print</a></span>(<span class='no'>object</span>)</div><div class='output co'>#&gt; stacked "gaussian" elastic net </div><div class='input'>
</div></pre>
</div>
<div class="col-md-3 hidden-xs hidden-sm" id="sidebar">
......
docs/reference/starnet-package-1.png

8.92 KB | W: | H:

docs/reference/starnet-package-1.png

8.92 KB | W: | H:

docs/reference/starnet-package-1.png
docs/reference/starnet-package-1.png
docs/reference/starnet-package-1.png
docs/reference/starnet-package-1.png
  • 2-up
  • Swipe
  • Onion skin
......@@ -154,8 +154,7 @@ to open the vignette.</p>
<span class='co'># n samples, p features</span>
<span class='co'>#--- model fitting ---</span>
<span class='no'>object</span> <span class='kw'>&lt;-</span> <span class='fu'><a href='starnet.html'>starnet</a></span>(<span class='kw'>y</span><span class='kw'>=</span><span class='no'>y</span>,<span class='kw'>X</span><span class='kw'>=</span><span class='no'>X</span>)
<span class='co'># "base": one model for each alpha</span>
<span class='no'>object</span> <span class='kw'>&lt;-</span> <span class='fu'><a href='starnet.html'>starnet</a></span>(<span class='kw'>y</span><span class='kw'>=</span><span class='no'>y</span>,<span class='kw'>X</span><span class='kw'>=</span><span class='no'>X</span>)</div><div class='output co'>#&gt; <span class='message'>alpha1 1.23 </span></div><div class='output co'>#&gt; <span class='message'>-0.249 _ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0</span></div><div class='input'><span class='co'># "base": one model for each alpha</span>
<span class='co'># "meta": model for stacking them </span>
<span class='co'>#--- make predictions ---</span>
......@@ -169,7 +168,7 @@ to open the vignette.</p>
<span class='co'># vector "beta": slopes</span>
<span class='co'>#--- model comparison ---</span>
<span class='no'>loss</span> <span class='kw'>&lt;-</span> <span class='fu'><a href='cv.starnet.html'>cv.starnet</a></span>(<span class='kw'>y</span><span class='kw'>=</span><span class='no'>y</span>,<span class='kw'>X</span><span class='kw'>=</span><span class='no'>X</span>)</div><div class='img'><img src='starnet-package-1.png' alt='' width='700' height='433' /></div><div class='input'># cross-validated loss for different alpha,
<span class='no'>loss</span> <span class='kw'>&lt;-</span> <span class='fu'><a href='cv.starnet.html'>cv.starnet</a></span>(<span class='kw'>y</span><span class='kw'>=</span><span class='no'>y</span>,<span class='kw'>X</span><span class='kw'>=</span><span class='no'>X</span>)</div><div class='output co'>#&gt; <span class='message'>alpha1 1.25 </span></div><div class='output co'>#&gt; <span class='message'>-0.243 _ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0</span></div><div class='output co'>#&gt; <span class='message'>alpha1 1.03 </span></div><div class='output co'>#&gt; <span class='message'>-0.196 _ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0</span></div><div class='output co'>#&gt; <span class='message'>alpha1 1.22 </span></div><div class='output co'>#&gt; <span class='message'>-0.197 _ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0</span></div><div class='output co'>#&gt; <span class='message'>alpha1 0.95 </span></div><div class='output co'>#&gt; <span class='message'>-0.007 _ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.913</span></div><div class='output co'>#&gt; <span class='message'>alpha1 1.14 </span></div><div class='output co'>#&gt; <span class='message'>-0.328 _ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0</span></div><div class='output co'>#&gt; <span class='message'>alpha1 1.3 </span></div><div class='output co'>#&gt; <span class='message'>-0.266 _ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0</span></div><div class='output co'>#&gt; <span class='message'>alpha1 1.15 </span></div><div class='output co'>#&gt; <span class='message'>-0.19 _ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0</span></div><div class='output co'>#&gt; <span class='message'>alpha1 1.34 </span></div><div class='output co'>#&gt; <span class='message'>-0.252 _ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0</span></div><div class='output co'>#&gt; <span class='message'>alpha1 1.33 </span></div><div class='output co'>#&gt; <span class='message'>-0.236 _ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0</span></div><div class='output co'>#&gt; <span class='message'>alpha1 1.13 </span></div><div class='output co'>#&gt; <span class='message'>-0.264 _ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0</span></div><div class='img'><img src='starnet-package-1.png' alt='' width='700' height='433' /></div><div class='input'># cross-validated loss for different alpha,
# and for tuning and stacking
</div></pre>
......
......@@ -125,7 +125,8 @@
<pre class="usage"><span class='fu'>starnet</span>(<span class='no'>y</span>, <span class='no'>X</span>, <span class='kw'>family</span> <span class='kw'>=</span> <span class='st'>"gaussian"</span>, <span class='kw'>nalpha</span> <span class='kw'>=</span> <span class='fl'>21</span>, <span class='kw'>alpha</span> <span class='kw'>=</span> <span class='kw'>NULL</span>,
<span class='kw'>nfolds</span> <span class='kw'>=</span> <span class='fl'>10</span>, <span class='kw'>foldid</span> <span class='kw'>=</span> <span class='kw'>NULL</span>, <span class='kw'>type.measure</span> <span class='kw'>=</span> <span class='st'>"deviance"</span>,
<span class='kw'>alpha.meta</span> <span class='kw'>=</span> <span class='fl'>0</span>, <span class='kw'>grouped</span> <span class='kw'>=</span> <span class='fl'>TRUE</span>, <span class='no'>...</span>)</pre>
<span class='kw'>alpha.meta</span> <span class='kw'>=</span> <span class='fl'>1</span>, <span class='kw'>grouped</span> <span class='kw'>=</span> <span class='fl'>TRUE</span>, <span class='kw'>penalty.factor</span> <span class='kw'>=</span> <span class='kw'>NULL</span>,
<span class='kw'>intercept</span> <span class='kw'>=</span> <span class='kw'>NULL</span>, <span class='kw'>upper.limit</span> <span class='kw'>=</span> <span class='kw'>NULL</span>, <span class='kw'>unit.sum</span> <span class='kw'>=</span> <span class='kw'>NULL</span>, <span class='no'>...</span>)</pre>
<h2 class="hasAnchor" id="arguments"><a class="anchor" href="#arguments"></a>Arguments</h2>
<table class="ref-arguments">
......@@ -181,6 +182,14 @@ vector of values between \(0\) (ridge) and \(1\) (lasso),
<th>grouped</th>
<td><p>logical</p></td>
</tr>
<tr>
<th>penalty.factor</th>
<td><p>penalty factors for base-learners</p></td>
</tr>
<tr>
<th>intercept, upper.limit, unit.sum</th>
<td><p>settings for meta-learner<strong>:</strong> logical</p></td>
</tr>
<tr>
<th>...</th>
<td><p>further arguments passed to <code><a href='https://rdrr.io/pkg/glmnet/man/glmnet.html'>glmnet</a></code></p></td>
......@@ -203,7 +212,8 @@ We recommend to use <code>alpha.meta</code>\(=0\) (default) for stability.</p>
<span class='no'>n</span> <span class='kw'>&lt;-</span> <span class='fl'>30</span>; <span class='no'>p</span> <span class='kw'>&lt;-</span> <span class='fl'>50</span>
<span class='no'>y</span> <span class='kw'>&lt;-</span> <span class='fu'><a href='https://rdrr.io/r/stats/Normal.html'>rnorm</a></span>(<span class='kw'>n</span><span class='kw'>=</span><span class='no'>n</span>)
<span class='no'>X</span> <span class='kw'>&lt;-</span> <span class='fu'><a href='https://rdrr.io/r/base/matrix.html'>matrix</a></span>(<span class='fu'><a href='https://rdrr.io/r/stats/Normal.html'>rnorm</a></span>(<span class='no'>n</span>*<span class='no'>p</span>),<span class='kw'>nrow</span><span class='kw'>=</span><span class='no'>n</span>,<span class='kw'>ncol</span><span class='kw'>=</span><span class='no'>p</span>)
<span class='no'>object</span> <span class='kw'>&lt;-</span> <span class='kw pkg'>starnet</span><span class='kw ns'>::</span><span class='fu'><a href='https://rdrr.io/pkg/starnet/man/starnet.html'>starnet</a></span>(<span class='kw'>y</span><span class='kw'>=</span><span class='no'>y</span>,<span class='kw'>X</span><span class='kw'>=</span><span class='no'>X</span>,<span class='kw'>family</span><span class='kw'>=</span><span class='st'>"gaussian"</span>)</div></pre>
<span class='no'>object</span> <span class='kw'>&lt;-</span> <span class='kw pkg'>starnet</span><span class='kw ns'>::</span><span class='fu'><a href='https://rdrr.io/pkg/starnet/man/starnet.html'>starnet</a></span>(<span class='kw'>y</span><span class='kw'>=</span><span class='no'>y</span>,<span class='kw'>X</span><span class='kw'>=</span><span class='no'>X</span>,<span class='kw'>family</span><span class='kw'>=</span><span class='st'>"gaussian"</span>)</div><div class='output co'>#&gt; <span class='message'>alpha1 0.87 </span></div><div class='output co'>#&gt; <span class='message'>0.082 _ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0</span></div><div class='input'>
</div></pre>
</div>
<div class="col-md-3 hidden-xs hidden-sm" id="sidebar">
<h2>Contents</h2>
......
......@@ -147,8 +147,7 @@ i.e. the weights for the base learners.</p>
<span class='no'>n</span> <span class='kw'>&lt;-</span> <span class='fl'>30</span>; <span class='no'>p</span> <span class='kw'>&lt;-</span> <span class='fl'>50</span>
<span class='no'>y</span> <span class='kw'>&lt;-</span> <span class='fu'><a href='https://rdrr.io/r/stats/Normal.html'>rnorm</a></span>(<span class='kw'>n</span><span class='kw'>=</span><span class='no'>n</span>)
<span class='no'>X</span> <span class='kw'>&lt;-</span> <span class='fu'><a href='https://rdrr.io/r/base/matrix.html'>matrix</a></span>(<span class='fu'><a href='https://rdrr.io/r/stats/Normal.html'>rnorm</a></span>(<span class='no'>n</span>*<span class='no'>p</span>),<span class='kw'>nrow</span><span class='kw'>=</span><span class='no'>n</span>,<span class='kw'>ncol</span><span class='kw'>=</span><span class='no'>p</span>)
<span class='no'>object</span> <span class='kw'>&lt;-</span> <span class='fu'><a href='starnet.html'>starnet</a></span>(<span class='kw'>y</span><span class='kw'>=</span><span class='no'>y</span>,<span class='kw'>X</span><span class='kw'>=</span><span class='no'>X</span>)
<span class='fu'><a href='https://rdrr.io/r/stats/weights.html'>weights</a></span>(<span class='no'>object</span>)</div><div class='output co'>#&gt; (Intercept) V1 V2 V3 V4 V5
<span class='no'>object</span> <span class='kw'>&lt;-</span> <span class='fu'><a href='starnet.html'>starnet</a></span>(<span class='kw'>y</span><span class='kw'>=</span><span class='no'>y</span>,<span class='kw'>X</span><span class='kw'>=</span><span class='no'>X</span>)</div><div class='output co'>#&gt; <span class='message'>alpha1 0.87 </span></div><div class='output co'>#&gt; <span class='message'>0.082 _ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0</span></div><div class='input'><span class='fu'><a href='https://rdrr.io/r/stats/weights.html'>weights</a></span>(<span class='no'>object</span>)</div><div class='output co'>#&gt; (Intercept) V1 V2 V3 V4 V5
#&gt; 0.08245817 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000
#&gt; V6 V7 V8 V9 V10 V11
#&gt; 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000
......
......@@ -5,8 +5,10 @@
\title{Model comparison}
\usage{
cv.starnet(y, X, family = "gaussian", nalpha = 21, alpha = NULL,
nfolds = 5, foldid = NULL, type.measure = "deviance",
alpha.meta = 0, grouped = TRUE, nzero = NULL, ...)
nfolds.ext = 10, nfolds.int = 10, foldid.ext = NULL,
foldid.int = NULL, type.measure = "deviance", alpha.meta = 1,
grouped = TRUE, nzero = NULL, intercept = NULL,
upper.limit = NULL, unit.sum = NULL, ...)
}
\arguments{
\item{y}{numeric response\strong{:}
......@@ -24,11 +26,7 @@ and \eqn{p} columns (variables)}
vector of values between \eqn{0} (ridge) and \eqn{1} (lasso);
or \code{NULL} (equidistance)}
\item{nfolds}{number of folds}
\item{foldid}{fold identifiers\strong{:}
vector with entries between \eqn{1} and \code{nfolds};
or \code{NULL} (balance)}
\item{nfolds.ext, nfolds.int, foldid.ext, foldid.int}{(number of) external/internal folds}
\item{type.measure}{loss function\strong{:}
character "deviance", "class", "mse" or "mae"
......@@ -44,6 +42,12 @@ vector of values between \eqn{0} (ridge) and \eqn{1} (lasso),
scalar/vector including positive integer(s) or \code{NA};
or \code{NULL} (no posthoc feature selection)}
\item{intercept}{settings for meta-learner\strong{:} logical}
\item{upper.limit}{settings for meta-learner\strong{:} logical}
\item{unit.sum}{settings for meta-learner\strong{:} logical}
\item{...}{further arguments (not applicable)}
}
\description{
......
......@@ -4,7 +4,7 @@
\alias{.simulate}
\title{Simulation}
\usage{
.simulate(n, p, mode)
.simulate(n, p, mode, family = "gaussian")
}
\arguments{
\item{n}{sample size\strong{:}
......@@ -14,6 +14,8 @@ positive integer}
positive integer}
\item{mode}{character \code{"sparse"}, \code{"dense"} or \code{"blocks"}}
\item{family}{\code{"gaussian"}, \code{"binomial"} or \code{"poisson"}}
}
\description{
Prints object of class \link[starnet]{starnet}.
......
......@@ -30,6 +30,6 @@ n <- 30; p <- 50
y <- rnorm(n=n)
X <- matrix(rnorm(n*p),nrow=n,ncol=p)
object <- starnet(y=y,X=X)
y_hat <- predict(object,newx=X)
y_hat <- predict(object,newx=X[c(1),,drop=FALSE])
}
......@@ -6,7 +6,8 @@
\usage{
starnet(y, X, family = "gaussian", nalpha = 21, alpha = NULL,
nfolds = 10, foldid = NULL, type.measure = "deviance",
alpha.meta = 0, grouped = TRUE, ...)
alpha.meta = 1, grouped = TRUE, penalty.factor = NULL,
intercept = NULL, upper.limit = NULL, unit.sum = NULL, ...)
}
\arguments{
\item{y}{numeric response\strong{:}
......@@ -40,6 +41,10 @@ vector of values between \eqn{0} (ridge) and \eqn{1} (lasso),
\item{grouped}{logical}
\item{penalty.factor}{penalty factors for base-learners}
\item{intercept, upper.limit, unit.sum}{settings for meta-learner\strong{:} logical}
\item{...}{further arguments passed to \code{\link[glmnet]{glmnet}}}
}
\description{
......@@ -59,7 +64,7 @@ object <- starnet::starnet(y=y,X=X,family="gaussian")
}
\references{
A Rauschenberger, E Glaab, and MA van de Wiel (2019)
A Rauschenberger, E Glaab, and MA van de Wiel (2020)
"Improved elastic net regression through stacked generalisation"
\emph{Manuscript in preparation.}
}
......@@ -7,25 +7,17 @@ for(family in c("gaussian","binomial","poisson")){
event=rbinom(n=n,size=1,prob=0.2))
list$X <- matrix(rnorm(n*p),nrow=n,ncol=p)
} else {
#list <- starnet:::.simulate(n=20,p=50,rho=0.5,pi=0.5,
# family=family,factor=0.5)
list <- starnet:::.simulate(n=n,p=p,mode="sparse")
if(family=="binomial"){
list$y <- stats::rbinom(n=n,size=1,prob=1/(1+exp(-list$y)))
}
if(family=="poisson"){
list$y <- stats::rpois(n=n,lambda=exp(list$y))
}
list <- .simulate(n=n,p=p,mode="sparse",family=family)
}
foldid <- palasso:::.folds(y=list$y,nfolds=5)
glmnet <- glmnet::cv.glmnet(y=list$y,x=list$X,family=family,foldid=foldid,alpha=0.5)
starnet <- starnet::starnet(y=list$y,X=list$X,family=family,foldid=foldid)
object <- starnet(y=list$y,X=list$X,family=family,foldid=foldid)
#--- Equality glmnet and starnet ---
reprod <- starnet$base$alpha0.5
reprod <- object$base$alpha0.5
testthat::test_that("lambda: glmnet = starnet",{
a <- glmnet$lambda
......@@ -65,14 +57,14 @@ for(family in c("gaussian","binomial","poisson")){
#--- Equivalence stacking and pooling ---
testthat::test_that("stacking = pooling",{
pred <- starnet:::predict.starnet(object=starnet,newx=list$X,type="response")
pred <- predict.starnet(object=object,newx=list$X,type="response")
a <- pred$stack
coef <- starnet:::coef.starnet(object=starnet)
coef <- coef.starnet(object=object)
b <- joinet:::.mean.function(coef$alpha + list$X %*% coef$beta,family=family)
pred <- starnet:::predict.starnet(object=starnet,newx=list$X,type="link")
weights <- starnet:::weights.starnet(object=starnet)
pred <- predict.starnet(object=object,newx=list$X,type="link")
weights <- weights.starnet(object=object)
sub <- pred[,grepl(pattern="alpha",x=colnames(pred))]
c <- joinet:::.mean.function(weights[1] + as.matrix(sub) %*% weights[-1],family=family)
......@@ -83,6 +75,36 @@ for(family in c("gaussian","binomial","poisson")){
}
#--- testing the convex combination ---
for(family in c("gaussian","binomial")){
n <- 100; p <- 5
list <- .simulate(n=n,p=p,mode="sparse")
if(family=="binomial"){
list$y <- stats::rbinom(n=n,size=1,prob=1/(1+exp(-list$y)))
} else if(family=="poisson"){
list$y <- stats::rpois(n=n,lambda=exp(list$y))
}
glm0 <- .glm(y=list$y,X=list$X,family=family)
if(family=="gaussian"){
glm1 <- stats::glm(y~X,family=gaussian,data=list)
} else if(family=="binomial"){
glm1 <- stats::glm(y~X,family=binomial,data=list)
} else if(family=="poisson") {
glm1 <- stats::glm(y~X,family=poisson,data=list)
}
testthat::test_that("same coefficients",{
change <- (c(glm0$alpha,glm0$beta)-glm1$coefficients)/glm1$coefficients
testthat::expect_true(all(change<0.001))
})
}
#--- testing the loss function ---
set.seed(1)
......@@ -153,7 +175,7 @@ for(family in c("gaussian","binomial","poisson","cox","mgaussian","multinomial")
# Implement loss function for "cox-grouped"!
# See notes below! See palasso implementation!
a <- glmnet::cv.glmnet(y=y,x=X,alpha=alpha,lambda=c(lambda,0.5*lambda),foldid=foldid,family=family,type.measure=type.measure,grouped=grouped)$cvm[1]
b <- starnet:::.loss(y=y,x=y_hat,family=family,type.measure=type.measure,foldid=foldid,grouped=grouped)
b <- .loss(y=y,x=y_hat,family=family,type.measure=type.measure,foldid=foldid,grouped=grouped)
testthat::test_that("same loss",{
testthat::expect_true(abs(a-b)<1e-03)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment