Commit 11277c2a authored by Armin Rauschenberger's avatar Armin Rauschenberger
Browse files

extension

parent 0b889801
This package was submitted to CRAN on 2021-03-09.
Once it is accepted, delete this file and tag the release (commit 0b88980).
Package: joinet
Version: 0.0.7
Version: 0.0.8
Title: Multivariate Elastic Net Regression
Description: Implements high-dimensional multivariate regression by stacked generalisation (Wolpert 1992 <doi:10.1016/S0893-6080(05)80023-1>). For positively correlated outcomes, a single multivariate regression is typically more predictive than multiple univariate regressions. Includes functions for model fitting, extracting coefficients, outcome prediction, and performance measurement. If required, install MRCE or remMap from GitHub (<https://github.com/cran/MRCE>, <https://github.com/cran/remMap>).
Depends: R (>= 3.0.0)
......
## joinet 0.0.8 (2021-06-16)
* extension (with weights, without constraints)
## joinet 0.0.6 (2020-11-18)
* conditional execution
......
File added
......@@ -17,8 +17,7 @@
#' @param Y
#' outputs\strong{:}
#' numeric matrix with \eqn{n} rows (samples)
#' and \eqn{q} columns (variables),
#' with positive correlation (see details)
#' and \eqn{q} columns (variables)
#'
#' @param X
#' inputs\strong{:}
......@@ -49,21 +48,40 @@
#' numeric between \eqn{0} (ridge) and \eqn{1} (lasso)
#'
#' @param alpha.meta
#' elastic net mixing parameter for meta learner\strong{:}
#' elastic net mixing parameter for meta learners\strong{:}
#' numeric between \eqn{0} (ridge) and \eqn{1} (lasso)
#'
#' @param constraint
#' non-negativity constraints\strong{:}
#' logical (see details)
#'
#' @param weight
#' inclusion/exclusion of variables\strong{:}
#' logical matrix with \eqn{q} rows and \eqn{p} columns,
#' or \code{NULL} (see details)
#'
#' @param ...
#' further arguments passed to \code{\link[glmnet]{glmnet}}
#'
#' @references
#' Armin Rauschenberger, Enrico Glaab (2020)
#' Armin Rauschenberger, Enrico Glaab (2021)
#' "Predicting correlated outcomes from molecular data"
#' \emph{Manuscript in preparation}.
#'
#' @details
#' \strong{correlation:}
#' The \eqn{q} outcomes should be positively correlated.
#' Avoid negative correlations by changing the sign of the variable.
#' \strong{non-negativity constraints:}
#' If it is reasonable to assume that the outcomes
#' are \emph{positively} correlated
#' (potentially after changing the sign of some outcomes)
#' we recommend to set \code{constraint=TRUE}.
#' Then non-negativity constraints are imposed on the meta learner.
#'
#' \strong{inclusion/exclusion of variables:}
#' The entry in the \eqn{j}th column and the \eqn{k}th row
#' indicates whether the \eqn{j}th feature may be used for
#' modelling the \eqn{k}th outcome
#' (where \eqn{0} means \code{FALSE} and
#' \eqn{1} means \code{TRUE}).
#'
#' \strong{elastic net:}
#' \code{alpha.base} controls input-output effects,
......@@ -99,10 +117,11 @@
#' \dontrun{
#' browseVignettes("joinet") # further examples}
#'
joinet <- function(Y,X,family="gaussian",nfolds=10,foldid=NULL,type.measure="deviance",alpha.base=1,alpha.meta=1,...){
joinet <- function(Y,X,family="gaussian",nfolds=10,foldid=NULL,type.measure="deviance",alpha.base=1,alpha.meta=1,constraint=TRUE,weight=NULL,...){
# IMPLEMENT CODE FOR CONSTRAINT AND WEIGHT!
#--- temporary ---
# family <- "gaussian"; nfolds <- 10; foldid <- NULL; type.measure <- "deviance"
# family <- "gaussian"; nfolds <- 10; foldid <- NULL; type.measure <- "deviance"; alpha.base <- alpha.meta <- 1; constraint <- TRUE; weight <- NULL
#--- checks ---
Y <- as.matrix(Y)
......@@ -110,16 +129,16 @@ joinet <- function(Y,X,family="gaussian",nfolds=10,foldid=NULL,type.measure="dev
cornet:::.check(x=Y,type="matrix",miss=TRUE)
### trial start ###
for(i in 1:(ncol(Y)-1)){
for(j in i:ncol(Y)){
cor <- stats::cor.test(Y[,i],Y[,j],use="pairwise.complete.obs")
if(cor$statistic<0 & cor$p.value<0.05){
warning(paste("Columns",i,"and",j,"are negatively correlated."))
if(constraint){
for(i in 1:(ncol(Y)-1)){
for(j in i:ncol(Y)){
cor <- stats::cor.test(Y[,i],Y[,j],use="pairwise.complete.obs")
if(cor$statistic<0 & cor$p.value<0.05){
warning(paste("Columns",i,"and",j,"are negatively correlated. Consider using constraint=FALSE."),call.=FALSE)
}
}
}
}
### trial end ###
#if(any(stats::cor(Y,use="pairwise.complete.obs")<0,na.rm=TRUE)){warning("Negative correlation!",call.=FALSE)}
cornet:::.check(x=X,type="matrix")
......@@ -130,6 +149,7 @@ joinet <- function(Y,X,family="gaussian",nfolds=10,foldid=NULL,type.measure="dev
cornet:::.check(x=type.measure,type="string",values=c("deviance","class","mse","mae")) # not auc (min/max confusion)
cornet:::.check(x=alpha.base,type="scalar",min=0,max=1)
cornet:::.check(x=alpha.meta,type="scalar",min=0,max=1)
cornet:::.check(x=weight,type="matrix",min=0,max=1,null=TRUE)
if(!is.null(c(list(...)$lower.limits,list(...)$upper.limits))){
stop("Reserved arguments \"lower.limits\" and \"upper.limits\".",call.=FALSE)
}
......@@ -139,6 +159,12 @@ joinet <- function(Y,X,family="gaussian",nfolds=10,foldid=NULL,type.measure="dev
q <- ncol(Y)
p <- ncol(X)
if(is.null(weight)){
pf <- matrix(1,nrow=q,ncol=p)
} else {
pf <- 1/weight
}
#--- family ---
if(length(family)==1){
family <- rep(family,times=q)
......@@ -160,7 +186,7 @@ joinet <- function(Y,X,family="gaussian",nfolds=10,foldid=NULL,type.measure="dev
for(i in seq_len(q)){
cond <- !is.na(Y[,i])
#if(sum(cond)==0){nlambda[i] <- 0; next}
base[[i]]$glmnet.fit <- glmnet::glmnet(y=Y[cond,i],x=X[cond,],family=family[i],alpha=alpha.base,...) # ellipsis
base[[i]]$glmnet.fit <- glmnet::glmnet(y=Y[cond,i],x=X[cond,],family=family[i],alpha=alpha.base,penalty.factor=pf[i,],...) # ellipsis
base[[i]]$lambda <- base[[i]]$glmnet.fit$lambda
nlambda[i] <- length(base[[i]]$glmnet.fit$lambda)
}
......@@ -180,7 +206,7 @@ joinet <- function(Y,X,family="gaussian",nfolds=10,foldid=NULL,type.measure="dev
for(i in seq_len(q)){
cond <- !is.na(Y0[,i])
#if(sum(cond)==0){next}
object <- glmnet::glmnet(y=Y0[cond,i],x=X0[cond,],family=family[i],alpha=alpha.base,...) # ellipsis
object <- glmnet::glmnet(y=Y0[cond,i],x=X0[cond,],family=family[i],alpha=alpha.base,penalty.factor=pf[i,],...) # ellipsis
temp <- stats::predict(object=object,newx=X1,type="link",
s=base[[i]]$glmnet.fit$lambda)
link[[i]][foldid==k,seq_len(ncol(temp))] <- temp
......@@ -208,7 +234,7 @@ joinet <- function(Y,X,family="gaussian",nfolds=10,foldid=NULL,type.measure="dev
for(i in seq_len(q)){
cond <- !is.na(Y[,i])
meta[[i]] <- glmnet::cv.glmnet(y=Y[cond,i],x=hat[cond,],
lower.limits=0, # important: 0
lower.limits=ifelse(constraint,0,-Inf), # important: 0 (was lower.limits=0)
upper.limits=Inf, # important: Inf
foldid=foldid[cond],
family=family[i],
......
......@@ -40,7 +40,7 @@ devtools::install_github("rauschenberger/joinet")
## Reference
Armin Rauschenberger and Enrico Glaab (2020). "Predicting correlated outcomes from molecular data". *Manuscript in preparation.*
Armin Rauschenberger and Enrico Glaab (2021). "Predicting correlated outcomes from molecular data". *Manuscript in preparation.*
[![CRAN version](https://www.r-pkg.org/badges/version/joinet)](https://CRAN.R-project.org/package=joinet)
[![CRAN RStudio mirror downloads](https://cranlogs.r-pkg.org/badges/joinet)](https://CRAN.R-project.org/package=joinet)
......
......@@ -71,7 +71,7 @@
</button>
<span class="navbar-brand">
<a class="navbar-link" href="index.html">joinet</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">0.0.7</span>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">0.0.8</span>
</span>
</div>
......@@ -96,13 +96,13 @@
<ul class="nav navbar-nav navbar-right">
<li>
<a href="https://github.com/rauschenberger/joinet">
<span class="fa fa-github"></span>
<span class="fas fa-github"></span>
</a>
</li>
<li>
<a href="https://cran.r-project.org/package=joinet">
<span class="fa fa-download"></span>
<span class="fas fa-download"></span>
</a>
</li>
......@@ -142,7 +142,7 @@ Content not found. Please use links in the navbar.
</div>
<div class="pkgdown">
<p>Site built with <a href="https://pkgdown.r-lib.org/">pkgdown</a> 1.5.1.</p>
<p>Site built with <a href="https://pkgdown.r-lib.org/">pkgdown</a> 1.6.1.</p>
</div>
</footer>
......
......@@ -31,7 +31,7 @@
</button>
<span class="navbar-brand">
<a class="navbar-link" href="../index.html">joinet</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">0.0.7</span>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">0.0.8</span>
</span>
</div>
......@@ -56,13 +56,13 @@
<ul class="nav navbar-nav navbar-right">
<li>
<a href="https://github.com/rauschenberger/joinet">
<span class="fa fa-github"></span>
<span class="fas fa-github"></span>
</a>
</li>
<li>
<a href="https://cran.r-project.org/package=joinet">
<span class="fa fa-download"></span>
<span class="fas fa-download"></span>
</a>
</li>
......@@ -76,7 +76,7 @@
</header><div class="row">
</header><script src="article_files/header-attrs-2.8/header-attrs.js"></script><div class="row">
<div class="col-md-9 contents">
<div class="page-header toc-ignore">
<h1 data-toc-skip>Multivariate Elastic Net Regression</h1>
......@@ -93,7 +93,7 @@
<div id="reference" class="section level2">
<h2 class="hasAnchor">
<a href="#reference" class="anchor"></a>Reference</h2>
<p>Armin Rauschenberger and Enrico Glaab (2020). “Predicting correlated outcomes from molecular data”. <em>Manuscript in preparation.</em></p>
<p>Armin Rauschenberger and Enrico Glaab (2021). “Predicting correlated outcomes from molecular data”. <em>Manuscript in preparation.</em></p>
</div>
</div>
......@@ -112,7 +112,7 @@
</div>
<div class="pkgdown">
<p>Site built with <a href="https://pkgdown.r-lib.org/">pkgdown</a> 1.5.1.</p>
<p>Site built with <a href="https://pkgdown.r-lib.org/">pkgdown</a> 1.6.1.</p>
</div>
</footer>
......
// Pandoc 2.9 adds attributes on both header and div. We remove the former (to
// be compatible with the behavior of Pandoc < 2.8).
document.addEventListener('DOMContentLoaded', function(e) {
var hs = document.querySelectorAll("div.section[class*='level'] > :first-child");
var i, h, a;
for (i = 0; i < hs.length; i++) {
h = hs[i];
if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6
a = h.attributes;
while (a.length > 0) h.removeAttribute(a[0].name);
}
});
......@@ -71,7 +71,7 @@
</button>
<span class="navbar-brand">
<a class="navbar-link" href="../index.html">joinet</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">0.0.7</span>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">0.0.8</span>
</span>
</div>
......@@ -96,13 +96,13 @@
<ul class="nav navbar-nav navbar-right">
<li>
<a href="https://github.com/rauschenberger/joinet">
<span class="fa fa-github"></span>
<span class="fas fa-github"></span>
</a>
</li>
<li>
<a href="https://cran.r-project.org/package=joinet">
<span class="fa fa-download"></span>
<span class="fas fa-download"></span>
</a>
</li>
......@@ -145,7 +145,7 @@
</div>
<div class="pkgdown">
<p>Site built with <a href="https://pkgdown.r-lib.org/">pkgdown</a> 1.5.1.</p>
<p>Site built with <a href="https://pkgdown.r-lib.org/">pkgdown</a> 1.6.1.</p>
</div>
</footer>
......
......@@ -31,7 +31,7 @@
</button>
<span class="navbar-brand">
<a class="navbar-link" href="../index.html">joinet</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">0.0.7</span>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">0.0.8</span>
</span>
</div>
......@@ -56,13 +56,13 @@
<ul class="nav navbar-nav navbar-right">
<li>
<a href="https://github.com/rauschenberger/joinet">
<span class="fa fa-github"></span>
<span class="fas fa-github"></span>
</a>
</li>
<li>
<a href="https://cran.r-project.org/package=joinet">
<span class="fa fa-download"></span>
<span class="fas fa-download"></span>
</a>
</li>
......@@ -76,7 +76,7 @@
</header><div class="row">
</header><script src="joinet_files/header-attrs-2.8/header-attrs.js"></script><div class="row">
<div class="col-md-9 contents">
<div class="page-header toc-ignore">
<h1 data-toc-skip>Multivariate Elastic Net Regression</h1>
......@@ -93,72 +93,83 @@
<h2 class="hasAnchor">
<a href="#installation" class="anchor"></a>Installation</h2>
<p>Install the current release from <a href="https://CRAN.R-project.org/package=joinet">CRAN</a>:</p>
<div class="sourceCode" id="cb1"><html><body><pre class="r"><span class="fu"><a href="https://rdrr.io/r/utils/install.packages.html">install.packages</a></span>(<span class="st">"joinet"</span>)</pre></body></html></div>
<div class="sourceCode" id="cb1"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="fu"><a href="https://rdrr.io/r/utils/install.packages.html">install.packages</a></span><span class="op">(</span><span class="st">"joinet"</span><span class="op">)</span></code></pre></div>
<p>Or install the latest development version from <a href="https://github.com/rauschenberger/joinet">GitHub</a>:</p>
<div class="sourceCode" id="cb2"><html><body><pre class="r"><span class="co">#install.packages("devtools")</span>
<span class="kw pkg">devtools</span><span class="kw ns">::</span><span class="fu"><a href="https://devtools.r-lib.org//reference/remote-reexports.html">install_github</a></span>(<span class="st">"rauschenberger/joinet"</span>)</pre></body></html></div>
<div class="sourceCode" id="cb2"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="co">#install.packages("devtools")</span>
<span class="fu">devtools</span><span class="fu">::</span><span class="fu"><a href="https://devtools.r-lib.org//reference/remote-reexports.html">install_github</a></span><span class="op">(</span><span class="st">"rauschenberger/joinet"</span><span class="op">)</span></code></pre></div>
</div>
<div id="initialisation" class="section level2">
<h2 class="hasAnchor">
<a href="#initialisation" class="anchor"></a>Initialisation</h2>
<p>Load and attach the package:</p>
<div class="sourceCode" id="cb3"><html><body><pre class="r"><span class="fu"><a href="https://rdrr.io/r/base/library.html">library</a></span>(<span class="no">joinet</span>)</pre></body></html></div>
<div class="sourceCode" id="cb3"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="kw"><a href="https://rdrr.io/r/base/library.html">library</a></span><span class="op">(</span><span class="va"><a href="https://github.com/rauschenberger/joinet">joinet</a></span><span class="op">)</span></code></pre></div>
<p>And access the <a href="https://rauschenberger.github.io/joinet/">documentation</a>:</p>
<div class="sourceCode" id="cb4"><html><body><pre class="r">?<span class="no">joinet</span>
<span class="fu"><a href="https://rdrr.io/r/utils/help.html">help</a></span>(<span class="no">joinet</span>)
<span class="fu"><a href="https://rdrr.io/r/utils/browseVignettes.html">browseVignettes</a></span>(<span class="st">"joinet"</span>)</pre></body></html></div>
<div class="sourceCode" id="cb4"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="op">?</span><span class="va">joinet</span>
<span class="fu"><a href="https://rdrr.io/r/utils/help.html">help</a></span><span class="op">(</span><span class="va">joinet</span><span class="op">)</span>
<span class="fu"><a href="https://rdrr.io/r/utils/browseVignettes.html">browseVignettes</a></span><span class="op">(</span><span class="st">"joinet"</span><span class="op">)</span></code></pre></div>
</div>
<div id="simulation" class="section level2">
<h2 class="hasAnchor">
<a href="#simulation" class="anchor"></a>Simulation</h2>
<p>For <code>n</code> samples, we simulate <code>p</code> inputs (features, covariates) and <code>q</code> outputs (outcomes, responses). We assume high-dimensional inputs (<code>p</code> <span class="math inline">\(\gg\)</span> <code>n</code>) and low-dimensional outputs (<code>q</code> <span class="math inline">\(\ll\)</span> <code>n</code>).</p>
<div class="sourceCode" id="cb5"><html><body><pre class="r"><span class="no">n</span> <span class="kw">&lt;-</span> <span class="fl">100</span>
<span class="no">q</span> <span class="kw">&lt;-</span> <span class="fl">2</span>
<span class="no">p</span> <span class="kw">&lt;-</span> <span class="fl">500</span></pre></body></html></div>
<div class="sourceCode" id="cb5"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="va">n</span> <span class="op">&lt;-</span> <span class="fl">100</span>
<span class="va">q</span> <span class="op">&lt;-</span> <span class="fl">2</span>
<span class="va">p</span> <span class="op">&lt;-</span> <span class="fl">500</span></code></pre></div>
<p>We simulate the <code>p</code> inputs from a multivariate normal distribution. For the mean, we use the <code>p</code>-dimensional vector <code>mu</code>, where all elements equal zero. For the covariance, we use the <code>p</code> <span class="math inline">\(\times\)</span> <code>p</code> matrix <code>Sigma</code>, where the entry in row <span class="math inline">\(i\)</span> and column <span class="math inline">\(j\)</span> equals <code>rho</code><span class="math inline">\(^{|i-j|}\)</span>. The parameter <code>rho</code> determines the strength of the correlation among the inputs, with small <code>rho</code> leading weak correlations, and large <code>rho</code> leading to strong correlations (0 &lt; <code>rho</code> &lt; 1). The input matrix <code>X</code> has <code>n</code> rows and <code>p</code> columns.</p>
<div class="sourceCode" id="cb6"><html><body><pre class="r"><span class="no">mu</span> <span class="kw">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/rep.html">rep</a></span>(<span class="fl">0</span>,<span class="kw">times</span><span class="kw">=</span><span class="no">p</span>)
<span class="no">rho</span> <span class="kw">&lt;-</span> <span class="fl">0.90</span>
<span class="no">Sigma</span> <span class="kw">&lt;-</span> <span class="no">rho</span>^<span class="fu"><a href="https://rdrr.io/r/base/MathFun.html">abs</a></span>(<span class="fu"><a href="https://rdrr.io/r/base/col.html">col</a></span>(<span class="fu"><a href="https://rdrr.io/r/base/diag.html">diag</a></span>(<span class="no">p</span>))-<span class="fu"><a href="https://rdrr.io/r/base/row.html">row</a></span>(<span class="fu"><a href="https://rdrr.io/r/base/diag.html">diag</a></span>(<span class="no">p</span>)))
<span class="no">X</span> <span class="kw">&lt;-</span> <span class="kw pkg">MASS</span><span class="kw ns">::</span><span class="fu"><a href="https://rdrr.io/pkg/MASS/man/mvrnorm.html">mvrnorm</a></span>(<span class="kw">n</span><span class="kw">=</span><span class="no">n</span>,<span class="kw">mu</span><span class="kw">=</span><span class="no">mu</span>,<span class="kw">Sigma</span><span class="kw">=</span><span class="no">Sigma</span>)</pre></body></html></div>
<div class="sourceCode" id="cb6"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="va">mu</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/rep.html">rep</a></span><span class="op">(</span><span class="fl">0</span>,times<span class="op">=</span><span class="va">p</span><span class="op">)</span>
<span class="va">rho</span> <span class="op">&lt;-</span> <span class="fl">0.90</span>
<span class="va">Sigma</span> <span class="op">&lt;-</span> <span class="va">rho</span><span class="op">^</span><span class="fu"><a href="https://rdrr.io/r/base/MathFun.html">abs</a></span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/base/col.html">col</a></span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/base/diag.html">diag</a></span><span class="op">(</span><span class="va">p</span><span class="op">)</span><span class="op">)</span><span class="op">-</span><span class="fu"><a href="https://rdrr.io/r/base/row.html">row</a></span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/base/diag.html">diag</a></span><span class="op">(</span><span class="va">p</span><span class="op">)</span><span class="op">)</span><span class="op">)</span>
<span class="va">X</span> <span class="op">&lt;-</span> <span class="fu">MASS</span><span class="fu">::</span><span class="fu"><a href="https://rdrr.io/pkg/MASS/man/mvrnorm.html">mvrnorm</a></span><span class="op">(</span>n<span class="op">=</span><span class="va">n</span>,mu<span class="op">=</span><span class="va">mu</span>,Sigma<span class="op">=</span><span class="va">Sigma</span><span class="op">)</span></code></pre></div>
<p>We simulate the input-output effects from independent Bernoulli distributions. The parameter <code>pi</code> determines the number of effects, with small <code>pi</code> leading to few effects, and large <code>pi</code> leading to many effects (0 &lt; <code>pi</code> &lt; 1). The scalar <code>alpha</code> represents the intercept, and the <code>p</code>-dimensional vector <code>beta</code> represents the slopes.</p>
<div class="sourceCode" id="cb7"><html><body><pre class="r"><span class="no">pi</span> <span class="kw">&lt;-</span> <span class="fl">0.01</span>
<span class="no">alpha</span> <span class="kw">&lt;-</span> <span class="fl">0</span>
<span class="no">beta</span> <span class="kw">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/stats/Binomial.html">rbinom</a></span>(<span class="kw">n</span><span class="kw">=</span><span class="no">p</span>,<span class="kw">size</span><span class="kw">=</span><span class="fl">1</span>,<span class="kw">prob</span><span class="kw">=</span><span class="no">pi</span>)</pre></body></html></div>
<div class="sourceCode" id="cb7"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="va">pi</span> <span class="op">&lt;-</span> <span class="fl">0.01</span>
<span class="va">alpha</span> <span class="op">&lt;-</span> <span class="fl">0</span>
<span class="va">beta</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/stats/Binomial.html">rbinom</a></span><span class="op">(</span>n<span class="op">=</span><span class="va">p</span>,size<span class="op">=</span><span class="fl">1</span>,prob<span class="op">=</span><span class="va">pi</span><span class="op">)</span></code></pre></div>
<p>From the intercept <code>alpha</code>, the slopes <code>beta</code> and the inputs <code>X</code>, we calculate the linear predictor, the <code>n</code>-dimensional vector <code>eta</code>. Rescale the linear predictor to make the effects weaker or stronger. Set the argument <code>family</code> to <code>"gaussian"</code>, <code>"binomial"</code>, or <code>"poisson"</code> to define the distribution. The <code>n</code> times <code>p</code> matrix <code>Y</code> represents the outputs. We assume the outcomes are <em>positively</em> correlated.</p>
<div class="sourceCode" id="cb8"><html><body><pre class="r"><span class="no">eta</span> <span class="kw">&lt;-</span> <span class="no">alpha</span> + <span class="no">X</span> <span class="kw">%*%</span> <span class="no">beta</span>
<span class="no">eta</span> <span class="kw">&lt;-</span> <span class="fl">1.5</span>*<span class="fu"><a href="https://rdrr.io/r/base/scale.html">scale</a></span>(<span class="no">eta</span>)
<span class="no">family</span> <span class="kw">&lt;-</span> <span class="st">"gaussian"</span>
<span class="kw">if</span>(<span class="no">family</span><span class="kw">==</span><span class="st">"gaussian"</span>){
<span class="no">mean</span> <span class="kw">&lt;-</span> <span class="no">eta</span>
<span class="no">Y</span> <span class="kw">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/lapply.html">replicate</a></span>(<span class="kw">n</span><span class="kw">=</span><span class="no">q</span>,<span class="kw">expr</span><span class="kw">=</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="no">mean</span>))
}
<span class="kw">if</span>(<span class="no">family</span><span class="kw">==</span><span class="st">"binomial"</span>){
<span class="no">prob</span> <span class="kw">&lt;-</span> <span class="fl">1</span>/(<span class="fl">1</span>+<span class="fu"><a href="https://rdrr.io/r/base/Log.html">exp</a></span>(-<span class="no">eta</span>))
<span class="no">Y</span> <span class="kw">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/lapply.html">replicate</a></span>(<span class="kw">n</span><span class="kw">=</span><span class="no">q</span>,<span class="kw">expr</span><span class="kw">=</span><span class="fu"><a href="https://rdrr.io/r/stats/Binomial.html">rbinom</a></span>(<span class="kw">n</span><span class="kw">=</span><span class="no">n</span>,<span class="kw">size</span><span class="kw">=</span><span class="fl">1</span>,<span class="kw">prob</span><span class="kw">=</span><span class="no">prob</span>))
}
<span class="kw">if</span>(<span class="no">family</span><span class="kw">==</span><span class="st">"poisson"</span>){
<span class="no">lambda</span> <span class="kw">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/Log.html">exp</a></span>(<span class="no">eta</span>)
<span class="no">Y</span> <span class="kw">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/lapply.html">replicate</a></span>(<span class="kw">n</span><span class="kw">=</span><span class="no">q</span>,<span class="kw">expr</span><span class="kw">=</span><span class="fu"><a href="https://rdrr.io/r/stats/Poisson.html">rpois</a></span>(<span class="kw">n</span><span class="kw">=</span><span class="no">n</span>,<span class="kw">lambda</span><span class="kw">=</span><span class="no">lambda</span>))
}
<span class="fu"><a href="https://rdrr.io/r/stats/cor.html">cor</a></span>(<span class="no">Y</span>)</pre></body></html></div>
<div class="sourceCode" id="cb8"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="va">eta</span> <span class="op">&lt;-</span> <span class="va">alpha</span> <span class="op">+</span> <span class="va">X</span> <span class="op">%*%</span> <span class="va">beta</span>
<span class="va">eta</span> <span class="op">&lt;-</span> <span class="fl">1.5</span><span class="op">*</span><span class="fu"><a href="https://rdrr.io/r/base/scale.html">scale</a></span><span class="op">(</span><span class="va">eta</span><span class="op">)</span>
<span class="va">family</span> <span class="op">&lt;-</span> <span class="st">"gaussian"</span>
<span class="kw">if</span><span class="op">(</span><span class="va">family</span><span class="op">==</span><span class="st">"gaussian"</span><span class="op">)</span><span class="op">{</span>
<span class="va">mean</span> <span class="op">&lt;-</span> <span class="va">eta</span>
<span class="va">Y</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/lapply.html">replicate</a></span><span class="op">(</span>n<span class="op">=</span><span class="va">q</span>,expr<span class="op">=</span><span class="fu"><a href="https://rdrr.io/r/stats/Normal.html">rnorm</a></span><span class="op">(</span>n<span class="op">=</span><span class="va">n</span>,mean<span class="op">=</span><span class="va">mean</span><span class="op">)</span><span class="op">)</span>
<span class="op">}</span>
<span class="kw">if</span><span class="op">(</span><span class="va">family</span><span class="op">==</span><span class="st">"binomial"</span><span class="op">)</span><span class="op">{</span>
<span class="va">prob</span> <span class="op">&lt;-</span> <span class="fl">1</span><span class="op">/</span><span class="op">(</span><span class="fl">1</span><span class="op">+</span><span class="fu"><a href="https://rdrr.io/r/base/Log.html">exp</a></span><span class="op">(</span><span class="op">-</span><span class="va">eta</span><span class="op">)</span><span class="op">)</span>
<span class="va">Y</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/lapply.html">replicate</a></span><span class="op">(</span>n<span class="op">=</span><span class="va">q</span>,expr<span class="op">=</span><span class="fu"><a href="https://rdrr.io/r/stats/Binomial.html">rbinom</a></span><span class="op">(</span>n<span class="op">=</span><span class="va">n</span>,size<span class="op">=</span><span class="fl">1</span>,prob<span class="op">=</span><span class="va">prob</span><span class="op">)</span><span class="op">)</span>
<span class="op">}</span>
<span class="kw">if</span><span class="op">(</span><span class="va">family</span><span class="op">==</span><span class="st">"poisson"</span><span class="op">)</span><span class="op">{</span>
<span class="va">lambda</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/Log.html">exp</a></span><span class="op">(</span><span class="va">eta</span><span class="op">)</span>
<span class="va">Y</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/lapply.html">replicate</a></span><span class="op">(</span>n<span class="op">=</span><span class="va">q</span>,expr<span class="op">=</span><span class="fu"><a href="https://rdrr.io/r/stats/Poisson.html">rpois</a></span><span class="op">(</span>n<span class="op">=</span><span class="va">n</span>,lambda<span class="op">=</span><span class="va">lambda</span><span class="op">)</span><span class="op">)</span>
<span class="op">}</span>
<span class="fu"><a href="https://rdrr.io/r/stats/cor.html">cor</a></span><span class="op">(</span><span class="va">Y</span><span class="op">)</span></code></pre></div>
</div>
<div id="application" class="section level2">
<h2 class="hasAnchor">
<a href="#application" class="anchor"></a>Application</h2>
<p>The function <code>joinet</code> fits univariate and multivariate regression. Set the argument <code>alpha.base</code> to 0 (ridge) or 1 (lasso).</p>
<div class="sourceCode" id="cb9"><html><body><pre class="r"><span class="no">object</span> <span class="kw">&lt;-</span> <span class="fu"><a href="../reference/joinet.html">joinet</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="no">family</span>)</pre></body></html></div>
<div class="sourceCode" id="cb9"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="va">object</span> <span class="op">&lt;-</span> <span class="fu"><a href="../reference/joinet.html">joinet</a></span><span class="op">(</span>Y<span class="op">=</span><span class="va">Y</span>,X<span class="op">=</span><span class="va">X</span>,family<span class="op">=</span><span class="va">family</span><span class="op">)</span></code></pre></div>
<p>Standard methods are available. The function <code>predict</code> returns the predicted values from the univariate (<code>base</code>) and multivariate (<code>meta</code>) models. The function <code>coef</code> returns the estimated intercepts (<code>alpha</code>) and slopes (<code>beta</code>) from the multivariate model (input-output effects). And the function <code>weights</code> returns the weights from stacking (output-output effects).</p>
<div class="sourceCode" id="cb10"><html><body><pre class="r"><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 class="sourceCode" id="cb10"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="fu"><a href="https://rdrr.io/r/stats/predict.html">predict</a></span><span class="op">(</span><span class="va">object</span>,newx<span class="op">=</span><span class="va">X</span><span class="op">)</span>
<span class="fu"><a href="https://rdrr.io/r/stats/coef.html">coef</a></span>(<span class="no">object</span>)
<span class="fu"><a href="https://rdrr.io/r/stats/coef.html">coef</a></span><span class="op">(</span><span class="va">object</span><span class="op">)</span>
<span class="fu"><a href="https://rdrr.io/r/stats/weights.html">weights</a></span>(<span class="no">object</span>)</pre></body></html></div>
<span class="fu"><a href="https://rdrr.io/r/stats/weights.html">weights</a></span><span class="op">(</span><span class="va">object</span><span class="op">)</span></code></pre></div>
<p>The function <code>cv.joinet</code> compares the predictive performance of univariate (<code>base</code>) and multivariate (<code>meta</code>) regression by nested cross-validation. The argument <code>type.measure</code> determines the loss function.</p>
<div class="sourceCode" id="cb11"><html><body><pre class="r"><span class="fu"><a href="../reference/cv.joinet.html">cv.joinet</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="no">family</span>)</pre></body></html></div>
<div class="sourceCode" id="cb11"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="fu"><a href="../reference/cv.joinet.html">cv.joinet</a></span><span class="op">(</span>Y<span class="op">=</span><span class="va">Y</span>,X<span class="op">=</span><span class="va">X</span>,family<span class="op">=</span><span class="va">family</span><span class="op">)</span></code></pre></div>
<pre><code>## [,1] [,2]
## base 1.204741 1.523550
## meta 1.185200 1.278125
......@@ -168,7 +179,7 @@
<div id="reference" class="section level2">
<h2 class="hasAnchor">
<a href="#reference" class="anchor"></a>Reference</h2>
<p>Armin Rauschenberger and Enrico Glaab (2020). “Predicting correlated outcomes from molecular data”. <em>Manuscript in preparation.</em></p>
<p>Armin Rauschenberger and Enrico Glaab (2021). “Predicting correlated outcomes from molecular data”. <em>Manuscript in preparation.</em></p>
</div>
</div>
......@@ -187,7 +198,7 @@
</div>
<div class="pkgdown">
<p>Site built with <a href="https://pkgdown.r-lib.org/">pkgdown</a> 1.5.1.</p>
<p>Site built with <a href="https://pkgdown.r-lib.org/">pkgdown</a> 1.6.1.</p>
</div>
</footer>
......
// Pandoc 2.9 adds attributes on both header and div. We remove the former (to
// be compatible with the behavior of Pandoc < 2.8).
document.addEventListener('DOMContentLoaded', function(e) {
var hs = document.querySelectorAll("div.section[class*='level'] > :first-child");
var i, h, a;
for (i = 0; i < hs.length; i++) {
h = hs[i];
if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6
a = h.attributes;
while (a.length > 0) h.removeAttribute(a[0].name);
}
});
This source diff could not be displayed because it is too large. You can view the blob instead.
// Pandoc 2.9 adds attributes on both header and div. We remove the former (to
// be compatible with the behavior of Pandoc < 2.8).
document.addEventListener('DOMContentLoaded', function(e) {
var hs = document.querySelectorAll("div.section[class*='level'] > :first-child");
var i, h, a;
for (i = 0; i < hs.length; i++) {
h = hs[i];
if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6
a = h.attributes;
while (a.length > 0) h.removeAttribute(a[0].name);
}
});
......@@ -71,7 +71,7 @@
</button>
<span class="navbar-brand">
<a class="navbar-link" href="index.html">joinet</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">0.0.7</span>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">0.0.8</span>
</span>
</div>
......@@ -96,13 +96,13 @@
<ul class="nav navbar-nav navbar-right">
<li>
<a href="https://github.com/rauschenberger/joinet">
<span class="fa fa-github"></span>
<span class="fas fa-github"></span>
</a>
</li>
<li>
<a href="https://cran.r-project.org/package=joinet">
<span class="fa fa-download"></span>
<span class="fas fa-download"></span>
</a>
</li>
......@@ -141,7 +141,7 @@
</div>
<div class="pkgdown">
<p>Site built with <a href="https://pkgdown.r-lib.org/">pkgdown</a> 1.5.1.</p>
<p>Site built with <a href="https://pkgdown.r-lib.org/">pkgdown</a> 1.6.1.</p>
</div>
</footer>
......
......@@ -31,7 +31,7 @@
</button>
<span class="navbar-brand">
<a class="navbar-link" href="index.html">joinet</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">0.0.7</span>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">0.0.8</span>
</span>
</div>
......@@ -56,13 +56,13 @@
<ul class="nav navbar-nav navbar-right">
<li>
<a href="https://github.com/rauschenberger/joinet">
<span class="fa fa-github"></span>
<span class="fas fa-github"></span>
</a>
</li>
<li>
<a href="https://cran.r-project.org/package=joinet">
<span class="fa fa-download"></span>
<span class="fas fa-download"></span>