Skip to content

Commit

Permalink
Optimize vignette
Browse files Browse the repository at this point in the history
  • Loading branch information
fouodo committed Dec 11, 2024
1 parent 0eed9fa commit 726e693
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 31 deletions.
2 changes: 1 addition & 1 deletion R/Lrner.R
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,8 @@ Lrner <- R6Class("Lrner",
use_var_sel = FALSE,
verbose = TRUE) {
train_data = private$train_layer$getTrainData()
# Train only on complete data
train_data = train_data$clone(deep = FALSE)
# Train only on complete data
if (private$na_rm) {
all_data = train_data$getDataFrame()
complete_data = train_data$getCompleteData()
Expand Down
5 changes: 1 addition & 4 deletions R/TestMetaLayer.R
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,12 @@ TestMetaLayer <- R6Class("TestMetaLayer",
#' Name of individual column IDs.
#' @param data_frame `data.frame(1)` \cr
#' \code{data.frame} of layer specific predictions.
#' @param meta_layer `TestLayer(1)` \cr
#' Layer where to store the [TestData] object.
#'
#' @export
# TODO: Please do not export me.
setTestData = function (id,
ind_col,
data_frame,
meta_layer) {
data_frame) {
TestData$new(id = id,
ind_col = ind_col,
data_frame = data_frame,
Expand Down
17 changes: 10 additions & 7 deletions R/TrainMetaLayer.R
Original file line number Diff line number Diff line change
Expand Up @@ -257,23 +257,26 @@ TrainMetaLayer <- R6Class("TrainMetaLayer",
#' Name of individual column IDs.
#' @param data_frame `data.frame` \cr
#' \code{data.frame} of layer specific predictions.
#' @param target `character` \cr
#' Name of the target variable
#'
#' @export
# TODO: Please do not export me.
setTrainData = function (id,
ind_col,
data_frame,
target) {
data_frame) {
# nocov start
if (sum(!complete.cases(data_frame)) == nrow(data_frame)) {
warning("No individual fully overlaps across all layers.")
}
# nocov end
TrainData$new(id = id,
data_frame = data_frame,
train_layer = self)
if (self$getLrner()$getNaRm()) {
TrainData$new(id = id,
data_frame = data_frame[complete.cases(data_frame), ],
train_layer = self)
} else {
TrainData$new(id = id,
data_frame = data_frame,
train_layer = self)
}
return(self)
},
#' @description
Expand Down
2 changes: 0 additions & 2 deletions R/Training.R
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,6 @@ Training <- R6Class("Training",
# This code accesses each layer (except TrainMetaLayer) level
# and get the individual IDs.
layers = layers[layers$class %in% c("TrainLayer", "TrainMetaLayer"), ]
current_model = NULL
models = list()
for (k in layers$key) {
layer = self$getFromHashTable(key = k)
Expand All @@ -609,7 +608,6 @@ Training <- R6Class("Training",
getData = function() {
layers = self$getKeyClass()
layers = layers[layers$class %in% c("TrainLayer", "TrainMetaLayer"), ]
current_model = NULL
all_data = list()
for (k in layers$key) {
layer = self$getFromHashTable(key = k)
Expand Down
32 changes: 16 additions & 16 deletions doc/fuseMLR.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

<meta name="author" content="Cesaire Fouodo" />

<meta name="date" content="2024-12-11" />
<meta name="date" content="2024-12-12" />

<title>How does fuseMLR work?</title>

Expand Down Expand Up @@ -340,7 +340,7 @@

<h1 class="title toc-ignore">How does fuseMLR work?</h1>
<h4 class="author">Cesaire Fouodo</h4>
<h4 class="date">2024-12-11</h4>
<h4 class="date">2024-12-12</h4>



Expand Down Expand Up @@ -471,15 +471,15 @@ <h3>C.1 - Creating a training</h3>
<span id="cb4-12"><a href="#cb4-12" tabindex="-1"></a> <span class="at">param_train_list =</span> <span class="fu">list</span>(<span class="at">probability =</span> <span class="cn">TRUE</span>,</span>
<span id="cb4-13"><a href="#cb4-13" tabindex="-1"></a> <span class="at">mtry =</span> 1L),</span>
<span id="cb4-14"><a href="#cb4-14" tabindex="-1"></a> <span class="at">param_pred_list =</span> <span class="fu">list</span>(),</span>
<span id="cb4-15"><a href="#cb4-15" tabindex="-1"></a> <span class="at">na_action =</span> <span class="st">&quot;na.keep&quot;</span>)</span>
<span id="cb4-15"><a href="#cb4-15" tabindex="-1"></a> <span class="at">na_action =</span> <span class="st">&quot;na.rm&quot;</span>)</span>
<span id="cb4-16"><a href="#cb4-16" tabindex="-1"></a><span class="co">#&gt; Training : training</span></span>
<span id="cb4-17"><a href="#cb4-17" tabindex="-1"></a><span class="co">#&gt; Problem type : classification</span></span>
<span id="cb4-18"><a href="#cb4-18" tabindex="-1"></a><span class="co">#&gt; Status : Not trained</span></span>
<span id="cb4-19"><a href="#cb4-19" tabindex="-1"></a><span class="co">#&gt; Number of layers: 1</span></span>
<span id="cb4-20"><a href="#cb4-20" tabindex="-1"></a><span class="co">#&gt; Layers trained : 0</span></span>
<span id="cb4-21"><a href="#cb4-21" tabindex="-1"></a><span class="co">#&gt; p : 131</span></span>
<span id="cb4-22"><a href="#cb4-22" tabindex="-1"></a><span class="co">#&gt; n : 50</span></span>
<span id="cb4-23"><a href="#cb4-23" tabindex="-1"></a><span class="co">#&gt; na.action : na.keep</span></span></code></pre></div>
<span id="cb4-23"><a href="#cb4-23" tabindex="-1"></a><span class="co">#&gt; na.action : na.rm</span></span></code></pre></div>
<div class="sourceCode" id="cb5"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb5-1"><a href="#cb5-1" tabindex="-1"></a><span class="co"># Create gene protein abundance layer</span></span>
<span id="cb5-2"><a href="#cb5-2" tabindex="-1"></a><span class="fu">createTrainLayer</span>(<span class="at">training =</span> training,</span>
<span id="cb5-3"><a href="#cb5-3" tabindex="-1"></a> <span class="at">train_layer_id =</span> <span class="st">&quot;proteinexpr&quot;</span>,</span>
Expand All @@ -502,7 +502,7 @@ <h3>C.1 - Creating a training</h3>
<span id="cb5-20"><a href="#cb5-20" tabindex="-1"></a><span class="co">#&gt; Layers trained : 0</span></span>
<span id="cb5-21"><a href="#cb5-21" tabindex="-1"></a><span class="co">#&gt; p : 131 | 160</span></span>
<span id="cb5-22"><a href="#cb5-22" tabindex="-1"></a><span class="co">#&gt; n : 50 | 50</span></span>
<span id="cb5-23"><a href="#cb5-23" tabindex="-1"></a><span class="co">#&gt; na.action : na.keep | na.keep</span></span></code></pre></div>
<span id="cb5-23"><a href="#cb5-23" tabindex="-1"></a><span class="co">#&gt; na.action : na.rm | na.keep</span></span></code></pre></div>
<div class="sourceCode" id="cb6"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb6-1"><a href="#cb6-1" tabindex="-1"></a><span class="co"># Create methylation layer</span></span>
<span id="cb6-2"><a href="#cb6-2" tabindex="-1"></a><span class="fu">createTrainLayer</span>(<span class="at">training =</span> training,</span>
<span id="cb6-3"><a href="#cb6-3" tabindex="-1"></a> <span class="at">train_layer_id =</span> <span class="st">&quot;methylation&quot;</span>,</span>
Expand All @@ -525,7 +525,7 @@ <h3>C.1 - Creating a training</h3>
<span id="cb6-20"><a href="#cb6-20" tabindex="-1"></a><span class="co">#&gt; Layers trained : 0</span></span>
<span id="cb6-21"><a href="#cb6-21" tabindex="-1"></a><span class="co">#&gt; p : 131 | 160 | 367</span></span>
<span id="cb6-22"><a href="#cb6-22" tabindex="-1"></a><span class="co">#&gt; n : 50 | 50 | 50</span></span>
<span id="cb6-23"><a href="#cb6-23" tabindex="-1"></a><span class="co">#&gt; na.action : na.keep | na.keep | na.keep</span></span></code></pre></div>
<span id="cb6-23"><a href="#cb6-23" tabindex="-1"></a><span class="co">#&gt; na.action : na.rm | na.keep | na.keep</span></span></code></pre></div>
<p>Also add a meta-layer. We use the weighted mean (internal function to
<code>fuseMLR</code>) as meta-learner. Similarly learners, a
meta-learner should allow at least the arguments <code>x</code> and
Expand Down Expand Up @@ -563,7 +563,7 @@ <h3>C.1 - Creating a training</h3>
<span id="cb7-13"><a href="#cb7-13" tabindex="-1"></a><span class="co">#&gt; Layers trained : 0</span></span>
<span id="cb7-14"><a href="#cb7-14" tabindex="-1"></a><span class="co">#&gt; p : 131 | 160 | 367</span></span>
<span id="cb7-15"><a href="#cb7-15" tabindex="-1"></a><span class="co">#&gt; n : 50 | 50 | 50</span></span>
<span id="cb7-16"><a href="#cb7-16" tabindex="-1"></a><span class="co">#&gt; na.action : na.keep | na.keep | na.keep</span></span>
<span id="cb7-16"><a href="#cb7-16" tabindex="-1"></a><span class="co">#&gt; na.action : na.rm | na.keep | na.keep</span></span>
<span id="cb7-17"><a href="#cb7-17" tabindex="-1"></a><span class="fu">print</span>(training)</span>
<span id="cb7-18"><a href="#cb7-18" tabindex="-1"></a><span class="co">#&gt; Training : training</span></span>
<span id="cb7-19"><a href="#cb7-19" tabindex="-1"></a><span class="co">#&gt; Problem type : classification</span></span>
Expand All @@ -572,7 +572,7 @@ <h3>C.1 - Creating a training</h3>
<span id="cb7-22"><a href="#cb7-22" tabindex="-1"></a><span class="co">#&gt; Layers trained : 0</span></span>
<span id="cb7-23"><a href="#cb7-23" tabindex="-1"></a><span class="co">#&gt; p : 131 | 160 | 367</span></span>
<span id="cb7-24"><a href="#cb7-24" tabindex="-1"></a><span class="co">#&gt; n : 50 | 50 | 50</span></span>
<span id="cb7-25"><a href="#cb7-25" tabindex="-1"></a><span class="co">#&gt; na.action : na.keep | na.keep | na.keep</span></span></code></pre></div>
<span id="cb7-25"><a href="#cb7-25" tabindex="-1"></a><span class="co">#&gt; na.action : na.rm | na.keep | na.keep</span></span></code></pre></div>
<p>Function <code>upsetplot()</code> is available to generate an upset
of the training data, i.e. an overview how patients overlap across
layers.</p>
Expand Down Expand Up @@ -660,7 +660,7 @@ <h3>C.2 - Variable selection</h3>
<span id="cb10-6"><a href="#cb10-6" tabindex="-1"></a><span class="co">#&gt; Layers trained : 0</span></span>
<span id="cb10-7"><a href="#cb10-7" tabindex="-1"></a><span class="co">#&gt; p : 19 | 1 | 35</span></span>
<span id="cb10-8"><a href="#cb10-8" tabindex="-1"></a><span class="co">#&gt; n : 50 | 50 | 50</span></span>
<span id="cb10-9"><a href="#cb10-9" tabindex="-1"></a><span class="co">#&gt; na.action : na.keep | na.keep | na.keep</span></span></code></pre></div>
<span id="cb10-9"><a href="#cb10-9" tabindex="-1"></a><span class="co">#&gt; na.action : na.rm | na.keep | na.keep</span></span></code></pre></div>
<p>For each layer, the variable selection results show the chosen
variables.</p>
</div>
Expand Down Expand Up @@ -713,8 +713,8 @@ <h3>C.2 - Train</h3>
<span id="cb12-6"><a href="#cb12-6" tabindex="-1"></a><span class="co">#&gt; Layers trained : 4</span></span>
<span id="cb12-7"><a href="#cb12-7" tabindex="-1"></a><span class="co">#&gt; Var. sel. used : Yes</span></span>
<span id="cb12-8"><a href="#cb12-8" tabindex="-1"></a><span class="co">#&gt; p : 19 | 1 | 35 | 3</span></span>
<span id="cb12-9"><a href="#cb12-9" tabindex="-1"></a><span class="co">#&gt; n : 50 | 50 | 50 | 69</span></span>
<span id="cb12-10"><a href="#cb12-10" tabindex="-1"></a><span class="co">#&gt; na.action : na.keep | na.keep | na.keep | na.rm</span></span></code></pre></div>
<span id="cb12-9"><a href="#cb12-9" tabindex="-1"></a><span class="co">#&gt; n : 50 | 50 | 50 | 26</span></span>
<span id="cb12-10"><a href="#cb12-10" tabindex="-1"></a><span class="co">#&gt; na.action : na.rm | na.keep | na.keep | na.rm</span></span></code></pre></div>
<p>We can also display a summary of <code>training</code> to see more
details on layer levels. Information about the training data modality,
the variable selection method and the learner stored at each layer will
Expand All @@ -729,8 +729,8 @@ <h3>C.2 - Train</h3>
<span id="cb13-8"><a href="#cb13-8" tabindex="-1"></a><span class="co">#&gt; Layers trained : 4</span></span>
<span id="cb13-9"><a href="#cb13-9" tabindex="-1"></a><span class="co">#&gt; Var. sel. used : Yes</span></span>
<span id="cb13-10"><a href="#cb13-10" tabindex="-1"></a><span class="co">#&gt; p : 19 | 1 | 35 | 3</span></span>
<span id="cb13-11"><a href="#cb13-11" tabindex="-1"></a><span class="co">#&gt; n : 50 | 50 | 50 | 69</span></span>
<span id="cb13-12"><a href="#cb13-12" tabindex="-1"></a><span class="co">#&gt; na.action : na.keep | na.keep | na.keep | na.rm</span></span>
<span id="cb13-11"><a href="#cb13-11" tabindex="-1"></a><span class="co">#&gt; n : 50 | 50 | 50 | 26</span></span>
<span id="cb13-12"><a href="#cb13-12" tabindex="-1"></a><span class="co">#&gt; na.action : na.rm | na.keep | na.keep | na.rm</span></span>
<span id="cb13-13"><a href="#cb13-13" tabindex="-1"></a><span class="co">#&gt; ----------------</span></span>
<span id="cb13-14"><a href="#cb13-14" tabindex="-1"></a><span class="co">#&gt; </span></span>
<span id="cb13-15"><a href="#cb13-15" tabindex="-1"></a><span class="co">#&gt; Layer geneexpr</span></span>
Expand Down Expand Up @@ -852,8 +852,8 @@ <h3>C.2 - Train</h3>
<span id="cb13-131"><a href="#cb13-131" tabindex="-1"></a><span class="co">#&gt; Layer : meta_layer</span></span>
<span id="cb13-132"><a href="#cb13-132" tabindex="-1"></a><span class="co">#&gt; Ind. id. : IDS</span></span>
<span id="cb13-133"><a href="#cb13-133" tabindex="-1"></a><span class="co">#&gt; Target : disease</span></span>
<span id="cb13-134"><a href="#cb13-134" tabindex="-1"></a><span class="co">#&gt; n : 69</span></span>
<span id="cb13-135"><a href="#cb13-135" tabindex="-1"></a><span class="co">#&gt; Missing : 43</span></span>
<span id="cb13-134"><a href="#cb13-134" tabindex="-1"></a><span class="co">#&gt; n : 26</span></span>
<span id="cb13-135"><a href="#cb13-135" tabindex="-1"></a><span class="co">#&gt; Missing : 0</span></span>
<span id="cb13-136"><a href="#cb13-136" tabindex="-1"></a><span class="co">#&gt; p : 3</span></span>
<span id="cb13-137"><a href="#cb13-137" tabindex="-1"></a><span class="co">#&gt; ----------------</span></span></code></pre></div>
<p>We use <code>extractModel()</code> to retrieve the list of stored
Expand All @@ -875,7 +875,7 @@ <h3>C.2 - Train</h3>
<span id="cb15-4"><a href="#cb15-4" tabindex="-1"></a><span class="co">#&gt; $ geneexpr :&#39;data.frame&#39;: 50 obs. of 21 variables:</span></span>
<span id="cb15-5"><a href="#cb15-5" tabindex="-1"></a><span class="co">#&gt; $ proteinexpr:&#39;data.frame&#39;: 50 obs. of 3 variables:</span></span>
<span id="cb15-6"><a href="#cb15-6" tabindex="-1"></a><span class="co">#&gt; $ methylation:&#39;data.frame&#39;: 50 obs. of 37 variables:</span></span>
<span id="cb15-7"><a href="#cb15-7" tabindex="-1"></a><span class="co">#&gt; $ meta_layer :&#39;data.frame&#39;: 69 obs. of 5 variables:</span></span></code></pre></div>
<span id="cb15-7"><a href="#cb15-7" tabindex="-1"></a><span class="co">#&gt; $ meta_layer :&#39;data.frame&#39;: 26 obs. of 5 variables:</span></span></code></pre></div>
<p>The three simulated training modalities and the meta-data are
returned.</p>
</div>
Expand Down
2 changes: 1 addition & 1 deletion vignettes/fuseMLR.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ createTrainLayer(training = training,
param_train_list = list(probability = TRUE,
mtry = 1L),
param_pred_list = list(),
na_action = "na.keep")
na_action = "na.rm")
```

```{r proteinexpr, include=TRUE, eval=TRUE}
Expand Down

0 comments on commit 726e693

Please sign in to comment.