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)

Arguments

M1

(Possibly sparsified) square matrix.

M2

(Possibly sparsified) square matrix over the same features as M1.

Value

An object of class list:

M1subset

A pruned matrix for class 1.

M2subset

A pruned matrix for class 2.

Details

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.

See also

Author

Carel F.W. Peeters <carel.peeters@wur.nl>

Examples


## 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