nct: Network Comparison Test

Description Usage Arguments Details Value Note References Examples

View source: R/nct.R

Description

A re-implementation and extension of the permutation based network comparison test introduced in \insertCitevan2017comparing;textualGGMncv. Such extensions include scaling to networks with many nodes and the option to use custom test-statistics.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
nct(
  Y_g1,
  Y_g2,
  iter = 1000,
  desparsify = TRUE,
  method = "pearson",
  FUN = NULL,
  cores = 1,
  progress = TRUE,
  update_progress = 4,
  ...
)

Arguments

Y_g1

A matrix (or data.frame) of dimensions n by p, corresponding to the first dataset (p must be the same for Y_g1 and Y_g2).

Y_g2

A matrix of dimensions n by p, corresponding to the second dataset (p must be the same for Y_g1 and Y_g2).

iter

Numeric. Number of (Monte Carlo) permutations (defaults to 1000).

desparsify

Logical. Should the de-sparsified glasso estimator be computed (defaults to TRUE)? This is much faster, as the tuning parameter is fixed to \mjseqn\lambda = \sqrtlog(p)/n.

method

character string. Which correlation coefficient (or covariance) is to be computed. One of "pearson" (default), "kendall", or "spearman".

FUN

A function or list of functions (defaults to NULL), specifying custom test-statistics. See Examples.

cores

Numeric. Number of cores to use when executing the permutations in parallel (defaults to 1).

progress

Logical. Should a progress bar be included (defaults to TRUE)?

update_progress

How many times should the progress bar be updated (defaults to 4)? Note that setting this to a large value should result in the worse performance, due to additional overhead communicating among the parallel processes.

...

Additional arguments passed to ggmncv.

Details

User-Defined Functions

These functions must have two arguments, corresponding to the partial correlation network for each group. An example is provided below.

For user-defined functions (FUN), absolute values are used to compute the p-value, assuming more than one value is returned (e.g., centrality). This is done to mimic the R package NCT.

A fail-safe method to ensure the p-value is computed correctly is to access the permutations and observed values from the nct object.

Finally, comparing edges is not implemented. The most straightforward way to do this is with compare_edges, which uses the de-sparsified estimator.

Value

A list of class nct, including the following

For user-defined functions, i.e., those provided to FUN, the function name is pasted to _pvalue, _obs, and _perm.

Note

In \insertCitevan2017comparing;textualGGMncv, it was suggested that these are tests of invariance. To avoid confusion, that terminology is not used in GGMncv. This is because these tests assume invariance or the null is true, and thus can only be used to detect differences. Hence, it would be incorrect to suggest networks are the same, or evidence for invariance, by merely failing to reject the null hypothesis \insertCitewilliams_nullGGMncv.

For the defaults, Jensen-Shannon divergence is a symmetrized version of Kullback-Leibler divergence (the average of both directions).

Computational Speed

This implementation has two key features that should make it scale to larger networks: (1) parallel computation and (2) the R package glassoFast is used under the hood (as opposed to glasso). CPU (time) comparisons are provided in \insertCitesustik2012glassofast;textualGGMncv.

Non-regularized

Non-regularized can be implemented by setting lambda = 0. Note this is provided to ggmncv via ....

References

\insertAllCited

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# generate network
main <- gen_net(p = 10)

# assume groups are equal
y1 <- MASS::mvrnorm(n = 500,
                    mu = rep(0, 10),
                    Sigma = main$cors)

y2 <- MASS::mvrnorm(n = 500,
                    mu = rep(0, 10),
                    Sigma = main$cors)

compare_ggms <- nct(y1, y2, iter = 500,
                    progress = FALSE)

compare_ggms

# custom function
# note: x & y are partial correlation networks

# correlation
Correlation <- function(x, y){
cor(x[upper.tri(x)], y[upper.tri(y)])
}

compare_ggms <- nct(y1, y2,iter = 100,
                    FUN = Correlation,
                    progress = FALSE)

compare_ggms

# correlation and strength

Strength <- function(x, y){
NetworkToolbox::strength(x) - NetworkToolbox::strength(y)
}

compare_ggms <- nct(y1, y2, iter = 100,
                    FUN = list(Correlation = Correlation,
                               Strength = Strength),
                    progress = FALSE)

compare_ggms

GGMncv documentation built on Dec. 15, 2021, 9:10 a.m.