Commit ed6ea472 authored by Armin Rauschenberger's avatar Armin Rauschenberger

automation

parent 11334fc8
......@@ -50,7 +50,10 @@
#'
#' @param intercept,upper.limit,unit.sum
#' settings for meta-learner\strong{:} logical,
#' or \code{NULL} (default depends on \code{alpha.meta})
#' or \code{NULL}
#' (\code{intercept=!is.na(alpha.meta)},
#' \code{upper.limit=TRUE},
#' \code{unit.sum=is.na(alpha.meta)})
#'
#' @param penalty.factor
#' differential shrinkage\strong{:}
......@@ -84,19 +87,23 @@ starnet <- function(y,X,family="gaussian",nalpha=21,alpha=NULL,nfolds=10,foldid=
# family <- "gaussian"; nalpha <- 21; alpha <- NULL; nfolds <- 10; foldid <- NULL; type.measure <- "deviance"; alpha.meta <- 0; penalty.factor <- NULL; intercept <- TRUE; upper.limit=TRUE; unit.sum=FALSE
#--- default ---
if(all(is.null(intercept),is.null(upper.limit),is.null(unit.sum))){
if(is.na(alpha.meta)){
intercept <- FALSE
upper.limit <- unit.sum <- TRUE
} else if(alpha.meta==1){
intercept <- TRUE
upper.limit <- unit.sum <- FALSE
} else if(alpha.meta==0){
intercept <- upper.limit <- TRUE
unit.sum <- FALSE
}
}
#if(all(is.null(intercept),is.null(upper.limit),is.null(unit.sum))){
# if(is.na(alpha.meta)){
# intercept <- FALSE
# upper.limit <- unit.sum <- TRUE
# } else if(alpha.meta==1){
# intercept <- TRUE
# upper.limit <- unit.sum <- FALSE
# } else if(alpha.meta==0){
# intercept <- upper.limit <- TRUE
# unit.sum <- FALSE
# }
#}
if(is.null(intercept)){intercept <- !is.na(alpha.meta)}
if(is.null(upper.limit)){upper.limit <- TRUE}
if(is.null(unit.sum)){unit.sum <- is.na(alpha.meta)}
#--- checks ---
cornet:::.check(x=y,type="vector")
cornet:::.check(x=X,type="matrix")
......@@ -596,10 +603,11 @@ cv.starnet <- function(y,X,family="gaussian",nalpha=21,alpha=NULL,nfolds.ext=10,
X[,p] <- sqrt(0.1)*X[,p] + sqrt(0.9)*Z[,2]
} else if(mode=="dense"){
X[,1:250] <- sqrt(0.9)*X[,1:250] + sqrt(0.1)*Z[,1]
X[,(p-250):p] <- sqrt(0.9)*X[,(p-250):p] + sqrt(0.1)*Z[,2]
X[,(p-250+1):p] <- sqrt(0.9)*X[,(p-250+1):p] + sqrt(0.1)*Z[,2]
} else if(mode=="blocks"){
# was 25 instead of 20
X[,1:25] <- sqrt(0.5)*X[,1:25] + sqrt(0.5)*Z[,1]
X[,(p-25):p] <- sqrt(0.5)*X[,(p-25):p] + sqrt(0.5)*Z[,2]
X[,(p-25+1):p] <- sqrt(0.5)*X[,(p-25+1):p] + sqrt(0.5)*Z[,2]
}
return(list(y=y,X=X))
}
......
......@@ -94,7 +94,7 @@
<p>or the latest development version from <a href="https://github.com/rauschenberger/starnet">GitHub</a>:</p>
<div class="sourceCode" id="cb2"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb2-1" title="1"><span class="co">#install.packages("devtools")</span></a>
<a class="sourceLine" id="cb2-2" title="2">devtools<span class="op">::</span><span class="kw"><a href="https://rdrr.io/pkg/devtools/man/remote-reexports.html">install_github</a></span>(<span class="st">"rauschenberger/starnet"</span>)</a></code></pre></div>
<p>A Rauschenberger, E Glaab, and MA van de Wiel (2019). “Improved elastic net regression through stacked generalisation”. <em>Manuscript in preparation.</em></p>
<p>A Rauschenberger, E Glaab, and MA van de Wiel (2020). “Predictive and interpretable models via the stacked elastic net”. <em>Manuscript in preparation.</em></p>
</div>
</div>
......
docs/reference/cv.starnet-1.png

8.53 KB | W: | H:

docs/reference/cv.starnet-1.png

8.53 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
......@@ -190,17 +190,26 @@ or <code>NULL</code> (no posthoc feature selection)</p></td>
<tr>
<th>intercept</th>
<td><p>settings for meta-learner<strong>:</strong> logical,
or <code>NULL</code> (default depends on <code>alpha.meta</code>)</p></td>
or <code>NULL</code>
(<code>intercept=!is.na(alpha.meta)</code>,
<code>upper.limit=TRUE</code>,
<code>unit.sum=is.na(alpha.meta)</code>)</p></td>
</tr>
<tr>
<th>upper.limit</th>
<td><p>settings for meta-learner<strong>:</strong> logical,
or <code>NULL</code> (default depends on <code>alpha.meta</code>)</p></td>
or <code>NULL</code>
(<code>intercept=!is.na(alpha.meta)</code>,
<code>upper.limit=TRUE</code>,
<code>unit.sum=is.na(alpha.meta)</code>)</p></td>
</tr>
<tr>
<th>unit.sum</th>
<td><p>settings for meta-learner<strong>:</strong> logical,
or <code>NULL</code> (default depends on <code>alpha.meta</code>)</p></td>
or <code>NULL</code>
(<code>intercept=!is.na(alpha.meta)</code>,
<code>upper.limit=TRUE</code>,
<code>unit.sum=is.na(alpha.meta)</code>)</p></td>
</tr>
<tr>
<th>...</th>
......@@ -214,7 +223,7 @@ or <code>NULL</code> (default depends on <code>alpha.meta</code>)</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='output co'>#&gt; <span class='message'>alpha1 2.63 </span></div><div class='output co'>#&gt; <span class='message'>0.003 _ 1.018 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.71 </span></div><div class='output co'>#&gt; <span class='message'>-0.022 _ 0.122 0.852 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.45 </span></div><div class='output co'>#&gt; <span class='message'>-0.031 _ 0.98 0.041 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.86 </span></div><div class='output co'>#&gt; <span class='message'>-0.084 _ 0.586 0.395 0 0 0 0 0 0 0 0 0 0.007 0 0 0 0 0 0 0 0 0</span></div><div class='output co'>#&gt; <span class='message'>alpha1 2.95 </span></div><div class='output co'>#&gt; <span class='message'>-0.131 _ 1.037 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.8 </span></div><div class='output co'>#&gt; <span class='message'>-0.111 _ 1.016 0.005 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.75 </span></div><div class='output co'>#&gt; <span class='message'>-0.05 _ 0.488 0.479 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.15 </span></div><div class='output co'>#&gt; <span class='message'>-0.031 _ 0 0.986 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.48 </span></div><div class='output co'>#&gt; <span class='message'>-0.08 _ 0.332 0.651 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.5 </span></div><div class='output co'>#&gt; <span class='message'>-0.039 _ 0.704 0.309 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='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.63 </span></div><div class='output co'>#&gt; <span class='message'>0.003 _ 1 0.017 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.71 </span></div><div class='output co'>#&gt; <span class='message'>-0.022 _ 0.122 0.852 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.45 </span></div><div class='output co'>#&gt; <span class='message'>-0.03 _ 0.98 0.043 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.86 </span></div><div class='output co'>#&gt; <span class='message'>-0.082 _ 0.587 0.398 0 0 0 0 0 0 0 0 0 0.007 0 0 0 0 0 0 0 0 0</span></div><div class='output co'>#&gt; <span class='message'>alpha1 2.95 </span></div><div class='output co'>#&gt; <span class='message'>-0.133 _ 1 0.032 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.8 </span></div><div class='output co'>#&gt; <span class='message'>-0.111 _ 1 0.023 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.75 </span></div><div class='output co'>#&gt; <span class='message'>-0.05 _ 0.488 0.479 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.15 </span></div><div class='output co'>#&gt; <span class='message'>-0.031 _ 0 0.986 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.48 </span></div><div class='output co'>#&gt; <span class='message'>-0.08 _ 0.332 0.651 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.5 </span></div><div class='output co'>#&gt; <span class='message'>-0.038 _ 0.704 0.31 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='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">
......
docs/reference/starnet-package-1.png

8.91 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
......@@ -168,7 +168,7 @@ Predictive and interpretable models via the stacked elastic net".
<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='output co'>#&gt; <span class='message'>alpha1 1.19 </span></div><div class='output co'>#&gt; <span class='message'>-0.12 _ 0 0 0 0 0 0 0 0.069 0 0 0.371 0 0 0 0 0 0 0 0 0 0</span></div><div class='output co'>#&gt; <span class='message'>alpha1 1.07 </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.23 </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.96 </span></div><div class='output co'>#&gt; <span class='message'>-0.021 _ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1.029</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.21 </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 1.005</span></div><div class='output co'>#&gt; <span class='message'>alpha1 1.13 </span></div><div class='output co'>#&gt; <span class='message'>-0.112 _ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.08 0.275 0 0.066 0 0</span></div><div class='output co'>#&gt; <span class='message'>alpha1 1.14 </span></div><div class='output co'>#&gt; <span class='message'>-0.07 _ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.604 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.131 _ 0 0 0 0 0 0 0.465 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,
<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.19 </span></div><div class='output co'>#&gt; <span class='message'>-0.12 _ 0 0 0 0 0 0 0 0.069 0 0 0.371 0 0 0 0 0 0 0 0 0 0</span></div><div class='output co'>#&gt; <span class='message'>alpha1 1.07 </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.23 </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.96 </span></div><div class='output co'>#&gt; <span class='message'>-0.023 _ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.021 1</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.2 </span></div><div class='output co'>#&gt; <span class='message'>-0.009 _ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.997</span></div><div class='output co'>#&gt; <span class='message'>alpha1 1.13 </span></div><div class='output co'>#&gt; <span class='message'>-0.112 _ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.08 0.275 0 0.066 0 0</span></div><div class='output co'>#&gt; <span class='message'>alpha1 1.14 </span></div><div class='output co'>#&gt; <span class='message'>-0.07 _ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.604 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.131 _ 0 0 0 0 0 0 0.465 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>
......
......@@ -190,7 +190,10 @@ or <code>NULL</code> (all \(1\))</p></td>
<tr>
<th>intercept, upper.limit, unit.sum</th>
<td><p>settings for meta-learner<strong>:</strong> logical,
or <code>NULL</code> (default depends on <code>alpha.meta</code>)</p></td>
or <code>NULL</code>
(<code>intercept=!is.na(alpha.meta)</code>,
<code>upper.limit=TRUE</code>,
<code>unit.sum=is.na(alpha.meta)</code>)</p></td>
</tr>
<tr>
<th>...</th>
......@@ -200,10 +203,9 @@ or <code>NULL</code> (default depends on <code>alpha.meta</code>)</p></td>
<h2 class="hasAnchor" id="details"><a class="anchor" href="#details"></a>Details</h2>
<p>For posthoc feature selection, set the
<p>Posthoc feature selection<strong>:</strong> consider
argument <code>nzero</code> in functions
<code><a href='https://rdrr.io/r/stats/coef.html'>coef</a></code> and <code><a href='https://rdrr.io/r/stats/predict.html'>predict</a></code>
to the maximum number of non-zero coefficients.</p>
<code><a href='https://rdrr.io/r/stats/coef.html'>coef</a></code> and <code><a href='https://rdrr.io/r/stats/predict.html'>predict</a></code>.</p>
<h2 class="hasAnchor" id="references"><a class="anchor" href="#references"></a>References</h2>
<p>A Rauschenberger, E Glaab, and MA van de Wiel (2020).
......
......@@ -49,13 +49,22 @@ scalar/vector including positive integer(s) or \code{NA};
or \code{NULL} (no posthoc feature selection)}
\item{intercept}{settings for meta-learner\strong{:} logical,
or \code{NULL} (default depends on \code{alpha.meta})}
or \code{NULL}
(\code{intercept=!is.na(alpha.meta)},
\code{upper.limit=TRUE},
\code{unit.sum=is.na(alpha.meta)})}
\item{upper.limit}{settings for meta-learner\strong{:} logical,
or \code{NULL} (default depends on \code{alpha.meta})}
or \code{NULL}
(\code{intercept=!is.na(alpha.meta)},
\code{upper.limit=TRUE},
\code{unit.sum=is.na(alpha.meta)})}
\item{unit.sum}{settings for meta-learner\strong{:} logical,
or \code{NULL} (default depends on \code{alpha.meta})}
or \code{NULL}
(\code{intercept=!is.na(alpha.meta)},
\code{upper.limit=TRUE},
\code{unit.sum=is.na(alpha.meta)})}
\item{...}{further arguments (not applicable)}
}
......
......@@ -47,7 +47,10 @@ between \eqn{0} (include) and \eqn{Inf} (exclude),
or \code{NULL} (all \eqn{1})}
\item{intercept, upper.limit, unit.sum}{settings for meta-learner\strong{:} logical,
or \code{NULL} (default depends on \code{alpha.meta})}
or \code{NULL}
(\code{intercept=!is.na(alpha.meta)},
\code{upper.limit=TRUE},
\code{unit.sum=is.na(alpha.meta)})}
\item{...}{further arguments passed to \code{\link[glmnet]{glmnet}}}
}
......@@ -55,10 +58,9 @@ or \code{NULL} (default depends on \code{alpha.meta})}
Implements stacked elastic net regression.
}
\details{
For posthoc feature selection, set the
Posthoc feature selection\strong{:} consider
argument \code{nzero} in functions
\code{\link{coef}} and \code{\link{predict}}
to the maximum number of non-zero coefficients.
\code{\link{coef}} and \code{\link{predict}}.
}
\examples{
set.seed(1)
......
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