comparison mixomics_blocksplsda_additional_funct.R @ 2:c8533e9298e5 draft

"planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 8cb5630238352459037b3647eebfabb5554566f6-dirty"
author ppericard
date Fri, 23 Oct 2020 10:15:56 +0000
parents
children
comparison
equal deleted inserted replaced
1:e93350dc99f1 2:c8533e9298e5
1 #' @title Determination of selected variables for all components
2 #' @description The function unionSelectBlockVariables determines, for each block, the selected block variables
3 #' for all components.
4 #' @param res_block_splsda type : sgccda. This parameter is the output of block.splsda function
5 #' mixOmics.
6 #' @details For each block, the function unionSelectBlockVariables returns 1 if the block variable is selected for
7 #' at least one component. Otherwise, this function returns 0.
8 #' @return type : list of matrix. For each block, if the block variable is selected, the value 1 is associated with
9 #' this block variable. Otherwise the value 0 is associated with this block variable.
10 #' @examples
11 #' data(res_data_integration)
12 #' list_union_selected_block_variables = unionSelectBlockVariables(res_data_integration)
13 #' @export
14 unionSelectBlockVariables <-function(res_block_splsda)
15 {
16 ncomp = res_block_splsda$ncomp[1]
17
18 names_blocks = names(res_block_splsda$loadings)
19 index_Y = which(names_blocks == "Y")
20 names_blocks = names_blocks[ - index_Y]
21 list_select_block_variables = list()
22
23 for(i in 1:length(names_blocks))
24 {
25 mat_loadings_i = res_block_splsda$loadings[[i]]
26 index_i = c()
27
28 for(j in 1:ncomp)
29 {
30 loadings_i_j = mat_loadings_i[, j]
31 index_i_j = which(loadings_i_j != 0)
32
33 index_i = c(index_i, index_i_j)
34
35 } # End for(j 1:ncomp).
36
37 index_i = unique(index_i)
38
39 mat_select_block_variables = matrix(0,
40 nrow = dim(mat_loadings_i)[1],
41 ncol = 1)
42 mat_select_block_variables[index_i, 1] = rep(1, length(index_i))
43 rownames(mat_select_block_variables) = rownames(mat_loadings_i)
44
45 list_select_block_variables[[i]] = mat_select_block_variables
46
47 } # End for(i in 1:length(names_blocks)).
48
49 names(list_select_block_variables) = names_blocks
50
51 return(list_select_block_variables)
52 }