Function that visualizes the sparsified precision matrix as an undirected graph.

Ugraph(
  M,
  type = c("plain", "fancy", "weighted"),
  lay = "layout_in_circle",
  coords = NULL,
  Vsize = 15,
  Vcex = 1,
  Vcolor = "orangered",
  VBcolor = "darkred",
  VLcolor = "black",
  prune = FALSE,
  legend = FALSE,
  label = "",
  Lcex = 1.3,
  PTcex = 4,
  cut = 0.5,
  scale = 10,
  pEcolor = "black",
  nEcolor = "grey",
  main = ""
)

Arguments

M

(Possibly sparsified) precision matrix

type

A character indicating the type of graph to be produced. Must be one of: "plain", "fancy", "weighted".

lay

A character mimicking a call to igraph layout functions. Determines the placement of vertices.

coords

A matrix containing coordinates. Alternative to the lay-argument for determining the placement of vertices.

Vsize

A numeric determining the vertex size.

Vcex

A numeric determining the size of the vertex labels.

Vcolor

A character (scalar or vector) determining the vertex color.

VBcolor

A character determining the color of the vertex border.

VLcolor

A character determining the color of the vertex labels.

prune

A logical determining if vertices of degree 0 should be removed.

legend

A logical indicating if the graph should come with a legend.

label

A character giving a name to the legend label.

Lcex

A numeric determining the size of the legend box.

PTcex

A numeric determining the size of the exemplary vertex in the legend box.

cut

A numeric indicating the cut-off for indicating strong edges when type = "fancy".

scale

A numeric representing a scale factor for visualizing strength of edges when type = "weighted".

pEcolor

A character determining the color of the edges tied to positive precision elements. Only when type = "weighted".

nEcolor

A character determining the color of the edges tied to negative precision elements. Only when type = "weighted".

main

A character giving the main figure title.

Value

The function returns a graph. The function also returns a matrix object containing the coordinates of the vertices in the given graph.

Details

The intended use of this function is to visualize a sparsified precision/partial correlation matrix as an undirected graph. When type = "plain" a plain undirected graph is given representing the conditional (in)dependencies exemplified by the sparsified precision.

When type = "fancy" a more elaborate graph is given in which dashed lines indicate negative partial correlations while solid lines indicate positive partial correlations, and in which grey lines indicate strong edges. Strong edges are deemed such by setting cut. If a the absolute value of a precision element \(\geq\) cut the corresponding edge is deemed strong and colored grey in the graph. The argument cut is thus only used when type = "fancy".

When type = "weighted" an undirected graph is given in which edge thickness represents the strength of the partial correlations. The nEcolor colored edges then represent negative partial correlations while pEcolor colored edges represent positive partial correlations. (Relative) edge thickness in this type of graph can be set by the argument scale. The arguments scale, nEcolor, and pEcolor are thus only used when type = "weighted".

The default layout gives a circular placement of the vertices. Most layout functions supported by igraph are supported (the function is partly a wrapper around certain igraph functions). The igraph layouts can be invoked by a character that mimicks a call to a igraph layout functions in the lay argument. When using lay = NULL one can specify the placement of vertices with the coords argument. The row dimension of this matrix should equal the number of (pruned) vertices. The column dimension then should equal 2 (for 2D layouts) or 3 (for 3D layouts). The coords argument can also be viewed as a convenience argument as it enables one, e.g., to layout a graph according to the coordinates of a previous call to Ugraph. If both the the lay and the coords arguments are not NULL, the lay argument takes precedence

The legend allows one to specify the kind of variable the vertices represent, such as, e.g., mRNA transcripts. The arguments label, Lcex, and PTcex are only used when legend = TRUE.

If prune = TRUE the vertices of degree 0 (vertices not implicated by any edge) are removed. For the colors supported by the arguments Vcolor, VBcolor, VLcolor, pEcolor, and nEcolor see https://stat.columbia.edu/~tzheng/files/Rcolor.pdf.

References

Csardi, G. and Nepusz, T. (2006). The igraph software package for complex network research. InterJournal, Complex Systems 1695. http://igraph.sf.net

van Wieringen, W.N. & Peeters, C.F.W. (2016). Ridge Estimation of Inverse Covariance Matrices from High-Dimensional Data, Computational Statistics & Data Analysis, vol. 103: 284-303. Also available as arXiv:1403.0904v3 [stat.ME].

van Wieringen, W.N. & Peeters, C.F.W. (2015). Application of a New Ridge Estimator of the Inverse Covariance Matrix to the Reconstruction of Gene-Gene Interaction Networks. In: di Serio, C., Lio, P., Nonis, A., and Tagliaferri, R. (Eds.) `Computational Intelligence Methods for Bioinformatics and Biostatistics'. Lecture Notes in Computer Science, vol. 8623. Springer, pp. 170-179.

Author

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

Examples


## Obtain some (high-dimensional) data
p = 25
n = 10
set.seed(333)
X = matrix(rnorm(n*p), nrow = n, ncol = p)
colnames(X)[1:25] = letters[1:25]

## Obtain regularized precision under optimal penalty
OPT <- optPenalty.LOOCV(X, lambdaMin = .5, lambdaMax = 30, step = 100)
#> Perform input checks... 
#> Calculating cross-validated negative log-likelihoods...
#> lambda = 0.5 done 
#> lambda = 0.521112064796442 done 
#> lambda = 0.543115568152822 done 
#> lambda = 0.56604815028642 done 
#> lambda = 0.589949040739926 done 
#> lambda = 0.614859125489326 done 
#> lambda = 0.640821016885354 done 
#> lambda = 0.667879126548165 done 
#> lambda = 0.696079741339917 done 
#> lambda = 0.725471102545235 done 
#> lambda = 0.756103488394997 done 
#> lambda = 0.788029300074619 done 
#> lambda = 0.821303151363959 done 
#> lambda = 0.855981962062195 done 
#> lambda = 0.89212505535748 done 
#> lambda = 0.929794259307953 done 
#> lambda = 0.969054012607691 done 
#> lambda = 1.00997147481854 done 
#> lambda = 1.0526166412564 done 
#> lambda = 1.09706246272843 done 
#> lambda = 1.14338497032617 done 
#> lambda = 1.19166340548777 done 
#> lambda = 1.24198035555219 done 
#> lambda = 1.29442189503684 done 
#> lambda = 1.34907773288074 done 
#> lambda = 1.40604136590477 done 
#> lambda = 1.46541023875169 done 
#> lambda = 1.52728591057948 done 
#> lambda = 1.59177422879317 done 
#> lambda = 1.65898551011235 done 
#> lambda = 1.72903472928405 done 
#> lambda = 1.80204171576394 done 
#> lambda = 1.87813135870213 done 
#> lambda = 1.95743382058443 done 
#> lambda = 2.04008475989428 done 
#> lambda = 2.12622556317653 done 
#> lambda = 2.21600358689979 done 
#> lambda = 2.30957240953135 done 
#> lambda = 2.40709209425555 done 
#> lambda = 2.5087294627854 done 
#> lambda = 2.61465838073554 done 
#> lambda = 2.72506005504483 done 
#> lambda = 2.84012334395744 done 
#> lambda = 2.96004508009247 done 
#> lambda = 3.08503040715507 done 
#> lambda = 3.21529313086478 done 
#> lambda = 3.35105608470152 done 
#> lambda = 3.49255151109498 done 
#> lambda = 3.64002145870927 done 
#> lambda = 3.79371819650269 done 
#> lambda = 3.9539046452707 done 
#> lambda = 4.12085482741052 done 
#> lambda = 4.29485433567656 done 
#> lambda = 4.47620082172873 done 
#> lambda = 4.66520450530918 done 
#> lambda = 4.86218870491866 done 
#> lambda = 5.0674903909002 done 
#> lambda = 5.28146076187626 done 
#> lambda = 5.50446584552545 done 
#> lambda = 5.73688712472652 done 
#> lambda = 5.97912219014072 done 
#> lambda = 6.23158542034891 done 
#> lambda = 6.49470869070685 done 
#> lambda = 6.76894211213128 done 
#> lambda = 7.05475480108065 done 
#> lambda = 7.3526356820475 done 
#> lambda = 7.66309432393553 done 
#> lambda = 7.98666181175188 done 
#> lambda = 8.32389165510583 done 
#> lambda = 8.67536073506814 done 
#> lambda = 9.04167029101067 done 
#> lambda = 9.42344694911443 done 
#> lambda = 9.8213437943055 done 
#> lambda = 10.2360414874525 done 
#> lambda = 10.6682494297369 done 
#> lambda = 11.1187069761873 done 
#> lambda = 11.5881847004551 done 
#> lambda = 12.0774857129934 done 
#> lambda = 12.587447034895 done 
#> lambda = 13.11894102974 done 
#> lambda = 13.6728768959011 done 
#> lambda = 14.2502022218612 done 
#> lambda = 14.8519046072019 done 
#> lambda = 15.4790133520375 done 
#> lambda = 16.1326012177839 done 
#> lambda = 16.813786262274 done 
#> lambda = 17.5237337523593 done 
#> lambda = 18.2636581572701 done 
#> lambda = 19.0348252261428 done 
#> lambda = 19.8385541532693 done 
#> lambda = 20.6762198347724 done 
#> lambda = 21.5492552205668 done 
#> lambda = 22.4591537656302 done 
#> lambda = 23.4074719847766 done 
#> lambda = 24.3958321153036 done 
#> lambda = 25.4259248920664 done 
#> lambda = 26.499512439728 done 
#> lambda = 27.6184312871313 done 
#> lambda = 28.7845955089513 done 
#> lambda = 30 done 


## Determine support regularized standardized precision under optimal penalty
PC0 <- sparsify(symm(OPT$optPrec), threshold = "localFDR")$sparseParCor
#> Step 1... determine cutoff point
#> Step 2... estimate parameters of null distribution and eta0
#> Step 3... compute p-values and estimate empirical PDF/CDF
#> Step 4... compute q-values and local fdr
#> Step 5... prepare for plotting

#> 
#> - Retained elements:  11 
#> - Corresponding to 3.67 % of possible edges 
#>  

## Obtain graphical representation
Ugraph(PC0, type = "fancy", cut = 0.07)
#> Warning: 'as.is' should be specified by the caller; using TRUE
#> Warning: 'as.is' should be specified by the caller; using TRUE

#>              [,1]       [,2]
#>  [1,]  1.00000000  0.0000000
#>  [2,]  0.96858316  0.2486899
#>  [3,]  0.87630668  0.4817537
#>  [4,]  0.72896863  0.6845471
#>  [5,]  0.53582679  0.8443279
#>  [6,]  0.30901699  0.9510565
#>  [7,]  0.06279052  0.9980267
#>  [8,] -0.18738131  0.9822873
#>  [9,] -0.42577929  0.9048271
#> [10,] -0.63742399  0.7705132
#> [11,] -0.80901699  0.5877853
#> [12,] -0.92977649  0.3681246
#> [13,] -0.99211470  0.1253332
#> [14,] -0.99211470 -0.1253332
#> [15,] -0.92977649 -0.3681246
#> [16,] -0.80901699 -0.5877853
#> [17,] -0.63742399 -0.7705132
#> [18,] -0.42577929 -0.9048271
#> [19,] -0.18738131 -0.9822873
#> [20,]  0.06279052 -0.9980267
#> [21,]  0.30901699 -0.9510565
#> [22,]  0.53582679 -0.8443279
#> [23,]  0.72896863 -0.6845471
#> [24,]  0.87630668 -0.4817537
#> [25,]  0.96858316 -0.2486899

## Obtain graphical representation with Fruchterman-Reingold layout
Ugraph(PC0, type = "fancy", lay = "layout_with_fr", cut = 0.07)
#> Warning: 'as.is' should be specified by the caller; using TRUE
#> Warning: 'as.is' should be specified by the caller; using TRUE

#>           [,1]     [,2]
#>  [1,] 28.18949 43.35287
#>  [2,] 31.45625 43.80960
#>  [3,] 28.92890 43.89910
#>  [4,] 30.61640 42.21654
#>  [5,] 26.11296 43.60425
#>  [6,] 29.88469 45.81763
#>  [7,] 25.71106 44.38086
#>  [8,] 29.51825 48.21335
#>  [9,] 30.76174 47.09181
#> [10,] 27.86109 48.53377
#> [11,] 24.96473 47.62133
#> [12,] 27.54855 45.97090
#> [13,] 27.14978 41.13931
#> [14,] 25.05062 43.52417
#> [15,] 24.16343 46.23411
#> [16,] 31.46453 45.46780
#> [17,] 25.19647 42.37033
#> [18,] 24.21886 44.36039
#> [19,] 26.44633 48.32574
#> [20,] 28.61240 47.07216
#> [21,] 26.07942 46.65558
#> [22,] 29.84658 43.86762
#> [23,] 24.41400 42.70750
#> [24,] 28.07646 41.20580
#> [25,] 29.00257 41.33106

## Add pruning
Ugraph(PC0, type = "fancy", lay = "layout_with_fr",
       cut = 0.07, prune = TRUE)
#> Warning: 'as.is' should be specified by the caller; using TRUE
#> Warning: 'as.is' should be specified by the caller; using TRUE

#>           [,1]     [,2]
#>  [1,] 23.89338 22.77083
#>  [2,] 24.05616 21.82444
#>  [3,] 21.36669 19.54714
#>  [4,] 22.03075 20.02815
#>  [5,] 20.34008 23.66565
#>  [6,] 20.96867 20.61036
#>  [7,] 20.00702 21.34735
#>  [8,] 21.56625 21.58340
#>  [9,] 24.08722 20.85356
#> [10,] 19.85986 20.52982
#> [11,] 21.27445 23.91858
#> [12,] 22.24386 24.02897

## Obtain graph and its coordinates
Coordinates <- Ugraph(PC0, type = "fancy", lay = "layout_with_fr",
                      cut = 0.07, prune = TRUE)
#> Warning: 'as.is' should be specified by the caller; using TRUE
#> Warning: 'as.is' should be specified by the caller; using TRUE

Coordinates
#>           [,1]     [,2]
#>  [1,] 14.34786 16.67492
#>  [2,] 13.63127 17.31143
#>  [3,] 10.32092 14.42705
#>  [4,] 11.09808 14.14544
#>  [5,] 13.23244 13.23214
#>  [6,] 10.92962 15.35790
#>  [7,] 10.20873 16.23351
#>  [8,] 12.06101 15.40507
#>  [9,] 12.83284 17.85718
#> [10,] 10.95923 16.56750
#> [11,] 13.93187 13.91019
#> [12,] 14.54018 14.65919