Tests whether two networks estimated from independent samples differ at three levels: global strength (M-statistic), network structure (S-statistic, max absolute edge difference), and individual edges (E-statistic per edge). Inference is via permutation of group labels.
Arguments
- data1
A numeric matrix or data.frame of observations from group 1.
- data2
A numeric matrix or data.frame of observations from group 2. Same number of columns as
data1.- iter
Integer. Number of permutation iterations. Default 1000.
- gamma
EBIC tuning parameter for glasso. Default 0.5.
- paired
Logical. If
TRUE, perform a paired permutation (within-subject swap). DefaultFALSE.- abs
Logical. If
TRUE, compute global strength on absolute edge weights. DefaultTRUE.- weighted
Logical. If
TRUE, use weighted networks for the tests. IfFALSE, binarize before computing statistics. DefaultTRUE.- p_adjust
P-value adjustment method for the per-edge tests (any method in
stats::p.adjust.methods). Default"none".- x
For the
print()method: an object of classnet_nct.- ...
In
print.net_nct()andsummary.net_nct(): Ignored.- object
For the
summary()method: an object of classnet_nct.
Value
A list of class net_nct with elements:
- nw1, nw2
Estimated weighted adjacency matrices.
- M
List with
observed,perm,p_valuefor the global strength test. P-values are permutation p-values,(sum(perm >= observed) + 1) / (iter + 1).- S
Same structure for the maximum absolute edge difference.
- E
Same structure for the per-edge tests (
observedandp_valueare one value per upper-triangle edge,permaniterby edges matrix), plusedge_names, a two-column data frame of the node pairs (NULLwhendata1has no column names).- n_iter
Number of permutations.
- paired
Whether a paired test was used.
- params
List of the settings used:
gamma,abs,weighted,p_adjust.
In print.net_nct(): The input object, invisibly.
In summary.net_nct(): A data frame with columns from, to, diff_observed, p_value, significant. Attributes m_stat and s_stat each hold a one-row data frame with observed and p_value.
Details
Follows NetworkComparisonTest::NCT() with defaults
abs = TRUE, weighted = TRUE, paired = FALSE. The
network estimator is EBIC-selected glasso applied to a Pearson
correlation matrix, with Matrix::nearPD symmetrization (matching
NCT's NCT_estimator_GGM default). The glasso solver is not the
Fortran one NCT wraps, so results agree to independent-solver precision
(of the order of 1e-4 on the test statistics) rather than
bit-for-bit, even under the same seed.
Methods
summary.net_nct(): Returns a tidy data frame with one row per edge test. The global M (strength) and S (structure) statistics are attached as attributes.
Examples
set.seed(1)
x1 <- matrix(rnorm(100 * 4), 100, 4)
x2 <- matrix(rnorm(100 * 4), 100, 4)
colnames(x1) <- colnames(x2) <- paste0("V", 1:4)
# iter = 20 keeps the example fast; a real analysis uses 1000 or more.
res <- nct(x1, x2, iter = 20)
res
#> Network Comparison Test [20 permutations | unpaired]
#> Global strength (M): observed = 0.0000 p = 1.0000
#> Network structure (S): observed = 0.0000 p = 1.0000
#> Edge tests (E): 6 edges, 0 significant at p < 0.05
summary(res)
#> from to diff_observed p_value significant
#> 1 V1 V2 0 1 FALSE
#> 2 V1 V3 0 1 FALSE
#> 3 V2 V3 0 1 FALSE
#> 4 V1 V4 0 1 FALSE
#> 5 V2 V4 0 1 FALSE
#> 6 V3 V4 0 1 FALSE