R/rags2ridges.R
Union.Rd
Convenience function that subsets 2 square matrices (over the same features) to the union of features that have nonzero row (column) entries (i.e., features implied in graphical connections).
Union(M1, M2)
(Possibly sparsified) square matrix
.
(Possibly sparsified) square matrix
over the same features
as M1
.
An object of class list:
A pruned matrix
for
class 1.
A pruned matrix
for class 2.
Say you have 2 class-specific precision matrices that are estimated over the same variables/features. For various reasons (such as, e.g., the desire to visualize pruned class-specific networks in the same coordinates) one may want to prune these matrices to those features that are implied in graphical connections in at least 1 class.
## Invoke data
data(ADdata)
## Subset
ADclass1 <- ADmetabolites[, sampleInfo$ApoEClass == "Class 1"]
ADclass2 <- ADmetabolites[, sampleInfo$ApoEClass == "Class 2"]
## Transpose data
ADclass1 <- t(ADclass1)
ADclass2 <- t(ADclass2)
## Correlations for subsets
rAD1 <- cor(ADclass1)
rAD2 <- cor(ADclass2)
## Simple precision estimates
P1 <- ridgeP(rAD1, 2)
P2 <- ridgeP(rAD2, 2)
Plist = list(P1 = P1, P2 = P2)
## Threshold matrices
Mats <- sparsify.fused(Plist, threshold = "top", top = 20)
#> - Retained elements: 20
#> - Corresponding to 0.08 % of possible edges
#>
#> - Retained elements: 20
#> - Corresponding to 0.08 % of possible edges
#>
## Prune sparsified partial correlation matrices
## To union of features implied by edge
MatsPrune <- Union(Mats$P1$sparseParCor, Mats$P2$sparseParCor)
#> Warning: 'as.is' should be specified by the caller; using TRUE
#> Warning: 'as.is' should be specified by the caller; using TRUE
#> Warning: 'as.is' should be specified by the caller; using TRUE
#> Warning: 'as.is' should be specified by the caller; using TRUE