### Install NetworkComparisonTest Source: https://github.com/cvborkulo/networkcomparisontest/blob/master/_autodocs/INDEX.md Installation instructions for the package from CRAN or GitHub. ```r # From CRAN (older version) install.packages("NetworkComparisonTest") # From GitHub (current development version) install.packages("remotes") remotes::install_github("cvborkulo/NetworkComparisonTest") ``` -------------------------------- ### Setup Simulated Data for bootnet Source: https://github.com/cvborkulo/networkcomparisontest/blob/master/_autodocs/usage-examples.md Initializes the environment and generates continuous data matrices for network estimation. ```r library(bootnet) set.seed(789) # Simulate continuous data N <- 8 nSample <- 200 data1 <- matrix(rnorm(nSample * N), nrow = nSample, ncol = N) data2 <- matrix(rnorm(nSample * N), nrow = nSample, ncol = N) colnames(data1) <- colnames(data2) <- paste("V", 1:N, sep = "") ``` -------------------------------- ### Install NetworkComparisonTest from GitHub Source: https://github.com/cvborkulo/networkcomparisontest/blob/master/README.md Use the remotes package to install the package from the GitHub repository. ```r install.packages("remotes") remotes::install_github("cvborkulo/NetworkComparisonTest") ``` ```r install.packages("remotes") remotes::install_github("cvborkulo/NetworkComparisonTest", ref = "development") ``` -------------------------------- ### Setup Simulated Network Data Source: https://github.com/cvborkulo/networkcomparisontest/blob/master/_autodocs/usage-examples.md Initializes two datasets and defines specific edges of interest for targeted testing. ```r set.seed(321) # Create data where we know a priori which edges might differ N <- 10 nSample <- 250 # Define edges of interest (e.g., from theory/literature) edges_of_interest <- list( c(1, 2), # Hypothesized to differ c(3, 4), # Hypothesized to differ c(5, 6), # Hypothesized to differ c(7, 8) # Hypothesized to differ ) # Simulate data data1 <- matrix(rnorm(nSample * N), nrow = nSample, ncol = N) data2 <- matrix(rnorm(nSample * N), nrow = nSample, ncol = N) colnames(data1) <- colnames(data2) <- paste("Gene", 1:N, sep = "") ``` -------------------------------- ### Setup and Data Simulation for Binary Networks Source: https://github.com/cvborkulo/networkcomparisontest/blob/master/_autodocs/usage-examples.md Initializes the environment and generates two simulated datasets using the Ising model for testing purposes. ```r library(NetworkComparisonTest) library(IsingSampler) library(IsingFit) # Set seed for reproducibility set.seed(42) # Define Ising model parameters N <- 8 # Number of nodes/variables nSample <- 300 # Sample size per group # Create random network structure Graph <- matrix(sample(0:1, N^2, TRUE, prob = c(0.8, 0.2)), N, N) * runif(N^2, 0.5, 2) Graph <- pmax(Graph, t(Graph)) # Make symmetric diag(Graph) <- 0 # Remove self-loops # Calculate thresholds Thresh <- -rowSums(Graph) / 2 # Simulate two datasets from same underlying network data1 <- IsingSampler(nSample, Graph, Thresh) data2 <- IsingSampler(nSample, Graph, Thresh) # Add column names colnames(data1) <- colnames(data2) <- paste("Var", 1:N, sep = "") ``` -------------------------------- ### Complete NCT Workflow Source: https://github.com/cvborkulo/networkcomparisontest/blob/master/_autodocs/README.md A full example demonstrating data preparation, running the NCT test with permutation settings, and visualizing the results. ```r library(NetworkComparisonTest) # Prepare data data1 <- matrix(rnorm(100 * 10), nrow = 100, ncol = 10) # 100 obs, 10 vars data2 <- matrix(rnorm(100 * 10), nrow = 100, ncol = 10) # Run test result <- NCT(data1, data2, gamma = 0.5, # EBIC hyperparameter it = 1000, # Permutations binary.data = FALSE, # Gaussian data test.edges = TRUE, # Test individual edges edges = "all", # Test all edges p.adjust.methods = "BH") # FDR correction # View results summary(result) plot(result, what = "network") plot(result, what = "strength") plot(result, what = "edge") ``` -------------------------------- ### Estimating GGM Networks Source: https://github.com/cvborkulo/networkcomparisontest/blob/master/_autodocs/api-reference/estimators.md Examples demonstrating direct estimation of a GGM network and its integration within the NCT context. ```r # Create continuous data set.seed(123) continuous_data <- matrix(rnorm(100 * 6), nrow = 100, ncol = 6) colnames(continuous_data) <- c('V1', 'V2', 'V3', 'V4', 'V5', 'V6') # Estimate network using GGM network <- NCT_estimator_GGM(continuous_data, make.positive.definite = TRUE, gamma = 0.5, corMethod = "cor", verbose = FALSE) network # With polychoric correlations (for ordinal data) network <- NCT_estimator_GGM(continuous_data, make.positive.definite = TRUE, gamma = 0.5, corMethod = "cor_auto", verbose = FALSE) # OR within NCT context (automatic): result <- NCT(data1, data2, gamma = 0.5, binary.data = FALSE, it = 100) ``` -------------------------------- ### Setup Paired Network Data Source: https://github.com/cvborkulo/networkcomparisontest/blob/master/_autodocs/usage-examples.md Generates baseline and modified network structures to simulate pre- and post-intervention data for paired testing. ```r set.seed(456) # Create baseline network data N <- 6 nSample <- 150 base_network <- matrix(0, N, N) diag(base_network) <- 0 # Add some edges base_network[1,2] <- base_network[2,1] <- 0.6 base_network[2,3] <- base_network[3,2] <- 0.5 base_network[4,5] <- base_network[5,4] <- 0.4 base_network[5,6] <- base_network[6,5] <- 0.3 # Simulate pre-intervention data data_pre <- rmvnorm(nSample, mean = rep(0, N), sigma = cov2cor(base_network + diag(N))) # Post-intervention: modify network structure (e.g., weaken edge 1-2) modified_network <- base_network modified_network[1,2] <- modified_network[2,1] <- 0.2 # Weaken connection # Simulate post-intervention data data_post <- rmvnorm(nSample, mean = rep(0, N), sigma = cov2cor(modified_network + diag(N))) colnames(data_pre) <- colnames(data_post) <- paste("Node", 1:N, sep = "") ``` -------------------------------- ### Package Directory Structure Source: https://github.com/cvborkulo/networkcomparisontest/blob/master/_autodocs/architecture.md The file system layout of the R package, highlighting core source code, examples, and testing directories. ```text networkcomparisontest/ ├── R/ # Main source code directory │ ├── NCT.R # Core NCT function (572 lines) │ ├── s3Methods.R # S3 methods: print, summary, plot (160 lines) │ ├── estimators.R # Network estimators for binary/Gaussian data (33 lines) │ ├── NCT_cor_auto.R # Wrapper for polychoric correlations │ └── NCT_bootnet.R # Deprecated wrapper function (5 lines) ├── inst/examples/ # Example usage │ └── ex-NCT.R # Complete usage examples ├── tests/testthat/ # Test suite │ └── test-NCT.R # Automated tests ├── DESCRIPTION # Package metadata and dependencies ├── README.md # User-facing documentation └── NEWS.md # Release notes and changelog ``` -------------------------------- ### Interpret NCT Centrality P-values Source: https://github.com/cvborkulo/networkcomparisontest/blob/master/_autodocs/invariance-measures.md Example of accessing and interpreting the centrality p-value matrix from an NCT result object. ```r result$diffcen.pval # strength expectedInfluence betweenness # V1 0.023 0.156 0.742 # V2 0.156 0.089 0.031 # V3 0.845 0.045 0.234 ``` -------------------------------- ### Compare bootnet and Direct NCT Methods Source: https://github.com/cvborkulo/networkcomparisontest/blob/master/_autodocs/usage-examples.md Illustrates the advantages of using bootnet objects versus the direct NCT method for network comparison. ```r # bootnet method automatically: # - Extracts data from the object # - Uses the same estimator for both networks # - Uses identical estimation parameters # - Ensures reproducibility # Compare with direct method: result_direct <- NCT(data1, data2, gamma = 0.5, binary.data = FALSE) # Both approaches give similar results, but bootnet is more flexible # because it supports more estimation methods ``` -------------------------------- ### Basic usage with binary data Source: https://github.com/cvborkulo/networkcomparisontest/blob/master/_autodocs/api-reference/nct.md Demonstrates comparing two binary datasets using the IsingSampler and IsingFit packages. ```r library(IsingSampler) library(IsingFit) # Simulate two binary datasets set.seed(123) N <- 6 nSample <- 500 Graph <- matrix(sample(0:1, N^2, TRUE, prob = c(0.8, 0.2)), N, N) * runif(N^2, 0.5, 2) Graph <- pmax(Graph, t(Graph)) diag(Graph) <- 0 Thresh <- -rowSums(Graph) / 2 data1 <- IsingSampler(nSample, Graph, Thresh) data2 <- IsingSampler(nSample, Graph, Thresh) colnames(data1) <- colnames(data2) <- c('V1', 'V2', 'V3', 'V4', 'V5', 'V6') # Compare networks: test all three invariance measures result <- NCT(data1, data2, gamma = 0, it = 100, binary.data = TRUE, test.edges = TRUE, edges = list(c(1,2), c(3,6))) summary(result) ``` -------------------------------- ### Project File Structure Source: https://github.com/cvborkulo/networkcomparisontest/blob/master/_autodocs/README.md The directory layout for the project documentation. ```text output/ ├── README.md # This file ├── INDEX.md # Master index and navigation ├── api-reference/ # API documentation │ ├── nct.md # Main NCT function │ ├── s3-methods.md # Print, summary, plot methods │ ├── estimators.md # Network estimators │ └── deprecated.md # Deprecated functions ├── types.md # Data structures and types ├── configuration.md # Parameter reference ├── invariance-measures.md # Statistical concepts ├── architecture.md # Design and structure └── usage-examples.md # Complete working examples ``` -------------------------------- ### Using bootnet estimator objects Source: https://github.com/cvborkulo/networkcomparisontest/blob/master/_autodocs/api-reference/nct.md Shows how to compare networks directly using bootnet estimator objects. ```r library(bootnet) # Estimate networks using bootnet est1 <- estimateNetwork(data1, default = "IsingFit", tuning = 0) est2 <- estimateNetwork(data2, default = "IsingFit", tuning = 0) # Compare using bootnet objects (automatic estimator and arguments) result <- NCT(est1, est2, it = 100, test.edges = TRUE, edges = list(c(1,2), c(3,6))) summary(result) ``` -------------------------------- ### Estimate Network with Ising Model Source: https://github.com/cvborkulo/networkcomparisontest/blob/master/_autodocs/api-reference/estimators.md Demonstrates creating binary data and estimating a network structure using the Ising model, either directly or via the NCT function. ```r # Create binary data set.seed(123) binary_data <- matrix(sample(0:1, 100 * 6, replace = TRUE), nrow = 100, ncol = 6) colnames(binary_data) <- c('V1', 'V2', 'V3', 'V4', 'V5', 'V6') # Estimate network using Ising model network <- NCT_estimator_Ising(binary_data, gamma = 0.25, AND = TRUE) network # OR within NCT context (automatic): result <- NCT(data1, data2, gamma = 0.25, binary.data = TRUE, it = 100) ``` -------------------------------- ### Display Documentation File Structure Source: https://github.com/cvborkulo/networkcomparisontest/blob/master/_autodocs/GENERATION_SUMMARY.md Visual representation of the generated documentation directory structure. ```text /workspace/home/output/ ├── README.md # Quick start guide and navigation ├── INDEX.md # Master index with full navigation ├── GENERATION_SUMMARY.md # This document ├── api-reference/ │ ├── nct.md # Main NCT function (850+ lines) │ ├── s3-methods.md # S3 methods (260+ lines) │ ├── estimators.md # Estimator functions (220+ lines) │ └── deprecated.md # Deprecated functions (50+ lines) ├── types.md # Data structures and types (350+ lines) ├── configuration.md # Parameter reference (450+ lines) ├── invariance-measures.md # Statistical concepts (430+ lines) ├── architecture.md # Design and algorithms (480+ lines) └── usage-examples.md # Complete examples (700+ lines) ``` -------------------------------- ### Estimate Networks with bootnet Source: https://github.com/cvborkulo/networkcomparisontest/blob/master/_autodocs/usage-examples.md Demonstrates estimation using IsingFit, glasso, and Sparse Partial Correlation methods. ```r # Estimate using different bootnet methods # IsingFit for binary data est1_ising <- estimateNetwork(binary_data1, default = "IsingFit", tuning = 0) est2_ising <- estimateNetwork(binary_data2, default = "IsingFit", tuning = 0) # Graphical lasso for continuous data est1_glasso <- estimateNetwork(data1, default = "glasso", tuning = 0.5) est2_glasso <- estimateNetwork(data2, default = "glasso", tuning = 0.5) # Sparse partial correlation est1_spc <- estimateNetwork(data1, default = "SPC", tuning = 0.5) est2_spc <- estimateNetwork(data2, default = "SPC", tuning = 0.5) ``` -------------------------------- ### Run Network Comparison Test Source: https://github.com/cvborkulo/networkcomparisontest/blob/master/_autodocs/INDEX.md Basic workflow for preparing data, executing the NCT function, and visualizing results. ```r library(NetworkComparisonTest) # Prepare data data1 <- matrix(...) # First dataset (nobs × nvars) data2 <- matrix(...) # Second dataset (nobs × nvars) # Run network comparison test result <- NCT(data1, data2, gamma = 0.5, # Regularization parameter it = 1000, # Permutations binary.data = FALSE) # Data type # View results summary(result) plot(result, what = "strength") plot(result, what = "network") ``` -------------------------------- ### Configure Binary Data (Ising Model) Source: https://github.com/cvborkulo/networkcomparisontest/blob/master/_autodocs/configuration.md Specific configuration for binary data using the Ising model with stricter edge definitions. ```r NCT(data1, data2, gamma = 0.25, # Default for binary it = 1000, binary.data = TRUE, AND = TRUE, # Stricter edge definition weighted = TRUE, test.edges = TRUE, edges = "all", progressbar = TRUE) ``` -------------------------------- ### Generate and summarize an NCT object Source: https://github.com/cvborkulo/networkcomparisontest/blob/master/_autodocs/api-reference/s3-methods.md Run a Network Comparison Test and display the detailed summary output. ```r result <- NCT(data1, data2, gamma = 0.5, it = 100, binary.data = FALSE, test.edges = TRUE, edges = "all", test.centrality = TRUE, centrality = c("strength")) summary(result) ``` -------------------------------- ### Run NCT with bootnet Objects Source: https://github.com/cvborkulo/networkcomparisontest/blob/master/_autodocs/usage-examples.md Executes the Network Comparison Test using pre-estimated bootnet objects. Estimators and arguments must be identical for both objects. ```r # Important: Estimators and arguments must be identical for both objects # NCT automatically extracts estimator and arguments from bootnet objects result_bootnet <- NCT(est1_glasso, est2_glasso, it = 1000, # Note: gamma, binary.data, AND are ignored for bootnet inputs test.edges = TRUE, edges = "all", progressbar = TRUE) summary(result_bootnet) ``` -------------------------------- ### Display Source Code Analysis Table Source: https://github.com/cvborkulo/networkcomparisontest/blob/master/_autodocs/GENERATION_SUMMARY.md Summary table detailing the source files analyzed, their line counts, and coverage status. ```markdown | File | Lines | Purpose | Coverage | |------|-------|---------|----------| | R/NCT.R | 572 | Main function | ✅ Complete | | R/s3Methods.R | 160 | S3 methods | ✅ Complete | | R/estimators.R | 33 | Network estimators | ✅ Complete | | R/NCT_cor_auto.R | 260 | Wrapper function | ✅ Complete | | R/NCT_bootnet.R | 5 | Deprecated wrapper | ✅ Complete | | inst/examples/ex-NCT.R | 90 | Usage examples | ✅ Referenced | | DESCRIPTION | 41 | Package metadata | ✅ Used | | README.md | 72 | Package overview | ✅ Referenced | ``` -------------------------------- ### summary.NCT() Source: https://github.com/cvborkulo/networkcomparisontest/blob/master/_autodocs/README.md S3 summary method for NCT objects. ```APIDOC ## summary.NCT(object, ...) ### Description Provides a summary of the NCT object results. ``` -------------------------------- ### Migrate NCT_bootnet to NCT Source: https://github.com/cvborkulo/networkcomparisontest/blob/master/_autodocs/api-reference/deprecated.md Comparison between the deprecated function call and the current recommended implementation. ```r result <- NCT_bootnet(data1, data2, gamma = 0.5, it = 100) ``` ```r result <- NCT(data1, data2, gamma = 0.5, it = 100) ``` -------------------------------- ### Analyze Permutation Distributions in R Source: https://github.com/cvborkulo/networkcomparisontest/blob/master/_autodocs/usage-examples.md Visualize permutation distributions and calculate effect sizes based on observed versus permuted values. ```r # Examine permutation distributions hist(result$nwinv.perm, breaks = 50, main = "Network Invariance: Permutation Distribution") abline(v = result$nwinv.real, col = "red", lwd = 2, lty = 2) hist(result$glstrinv.perm, breaks = 50, main = "Global Strength: Permutation Distribution") abline(v = result$glstrinv.real, col = "red", lwd = 2, lty = 2) # Calculate effect size (proportion of permutations >= observed) effect_size_network <- sum(result$nwinv.perm >= result$nwinv.real) / length(result$nwinv.perm) effect_size_strength <- sum(result$glstrinv.perm >= result$glstrinv.real) / length(result$glstrinv.perm) cat("Effect Sizes:\n") cat("Network invariance:", effect_size_network, "\n") cat("Global strength:", effect_size_strength, "\n") ``` -------------------------------- ### Configure High-Power Discovery Source: https://github.com/cvborkulo/networkcomparisontest/blob/master/_autodocs/configuration.md This configuration is more lenient, utilizing FDR correction and centrality testing to increase discovery potential. ```r NCT(data1, data2, gamma = 0.25, # More lenient (denser networks) it = 1000, binary.data = FALSE, weighted = TRUE, test.edges = TRUE, edges = "all", p.adjust.methods = "fdr", # Liberal correction test.centrality = TRUE, # Also test node importance progressbar = TRUE) ``` -------------------------------- ### Visualize Network Comparison Results Source: https://github.com/cvborkulo/networkcomparisontest/blob/master/_autodocs/usage-examples.md Generates plots for network structure, global strength, and edge invariance tests. ```r # Plot network structure invariance test plot(result_basic, what = "network") # Plot global strength invariance test plot(result_basic, what = "strength") # Plot edge invariance tests plot(result_edges, what = "edge") ``` -------------------------------- ### Perform Network Comparison Test Source: https://github.com/cvborkulo/networkcomparisontest/blob/master/README.md Simulate binary datasets and perform the NCT to test network structure, global strength, and edge invariance. ```r library("IsingSampler") library("IsingFit") ### Simulate binary datasets under null hypothesis: N <- 6 # Number of nodes nSample <- 500 # Number of samples # Ising parameters: Graph <- matrix(sample(0:1,N^2,TRUE,prob = c(0.8, 0.2)),N,N) * runif(N^2,0.5,2) Graph <- pmax(Graph,t(Graph)) diag(Graph) <- 0 Thresh <- -rowSums(Graph) / 2 # Simulate: data1 <- IsingSampler(nSample, Graph, Thresh) data2 <- IsingSampler(nSample, Graph, Thresh) colnames(data1) <- colnames(data2) <- c('V1', 'V2', 'V3', 'V4', 'V5', 'V6') # Testing the three aspects that are validated (network invariance, global strength, edge weight) # 2 edges are tested here: between variable 1 and 2, # and between 3 and 6 (can be list(c(2,1),c(6,3)) as well) Res_1 <- NCT(data1, data2, gamma=0, it=1000, binary.data = TRUE, test.edges=TRUE, edges=list(c(1,2),c(3,6))) # Plot results of the network structure invariance test: plot(Res_1, what="network") # Plot results of global strength invariance test: plot(Res_1, what="strength") # Plot results of the edge invariance test: plot(Res_1, what="edge") ``` -------------------------------- ### Print NCT results in R Source: https://github.com/cvborkulo/networkcomparisontest/blob/master/_autodocs/api-reference/s3-methods.md Demonstrates how to trigger the print.NCT method by printing the result object or calling the print function explicitly. ```r result <- NCT(data1, data2, gamma = 0.5, it = 100, binary.data = FALSE, test.edges = TRUE, edges = list(c(1,2), c(3,6))) # Automatically calls print.NCT result # or explicitly: print(result) ``` -------------------------------- ### Configure Conservative Network Comparison Source: https://github.com/cvborkulo/networkcomparisontest/blob/master/_autodocs/configuration.md Use this configuration to minimize type-I errors by applying Bonferroni correction and standard regularization. ```r NCT(data1, data2, gamma = 0.5, # Standard regularization it = 1000, # Minimum reliable iterations binary.data = FALSE, # Assume Gaussian unless known binary weighted = TRUE, # Preserve edge weights test.edges = TRUE, edges = "all", # Comprehensive edge testing p.adjust.methods = "bonferroni", # Strong correction progressbar = TRUE) ``` -------------------------------- ### Configure Large Networks with Centrality Focus Source: https://github.com/cvborkulo/networkcomparisontest/blob/master/_autodocs/configuration.md Optimized for large networks by disabling edge testing and focusing on specific node centrality metrics. ```r NCT(data1, data2, gamma = 0.5, it = 1000, binary.data = FALSE, test.edges = FALSE, # Skip computationally expensive edge tests test.centrality = TRUE, centrality = c("strength", "expectedInfluence", "betweenness"), nodes = important_node_names, # Test only key nodes p.adjust.methods = "BH", progressbar = TRUE) ``` -------------------------------- ### print.NCT() Source: https://github.com/cvborkulo/networkcomparisontest/blob/master/_autodocs/README.md S3 print method for NCT objects. ```APIDOC ## print.NCT(x, ...) ### Description Prints the results of an NCT object. ``` -------------------------------- ### Configure Focused Edge Testing Source: https://github.com/cvborkulo/networkcomparisontest/blob/master/_autodocs/configuration.md Use this for hypothesis-driven research by specifying a list of edges to test, bypassing multiple comparison corrections. ```r NCT(data1, data2, gamma = 0.5, it = 1000, binary.data = FALSE, weighted = TRUE, test.edges = TRUE, edges = list(c("V1","V2"), c("V3","V4")), # Only specific edges p.adjust.methods = "none", # No correction needed for few tests progressbar = TRUE) ``` -------------------------------- ### print.NCT(x, ...) Source: https://github.com/cvborkulo/networkcomparisontest/blob/master/_autodocs/api-reference/s3-methods.md Displays a concise summary of NCT results including test statistics and p-values for invariance measures and edge tests. ```APIDOC ## print.NCT(x, ...) ### Description Displays a concise summary of NCT results including test statistics and p-values for all three invariance measures and, if applicable, edge test results. This is the method automatically called when you type the NCT result object name in the console. ### Parameters - **x** (NCT) - Required - An object of class NCT, returned by the NCT() function. - **...** (any) - Optional - Additional arguments passed to print (currently unused). ### Return Value Returns NULL invisibly. Prints formatted output to console. ### Example ```r result <- NCT(data1, data2, gamma = 0.5, it = 100, binary.data = FALSE, test.edges = TRUE, edges = list(c(1,2), c(3,6))) # Automatically calls print.NCT result # or explicitly: print(result) ``` ``` -------------------------------- ### plot.NCT(x, what, ...) Source: https://github.com/cvborkulo/networkcomparisontest/blob/master/_autodocs/api-reference/s3-methods.md Visualizes the permutation test results as histograms showing the permutation distribution with the observed test statistic overlaid. ```APIDOC ## plot.NCT(x, what, ...) ### Description Visualizes the permutation test results as histograms showing the permutation distribution with the observed test statistic overlaid. Facilitates visual inspection of the statistical evidence. ### Parameters - **x** (NCT) - Required - An object of class NCT, returned by the NCT() function. - **what** (character) - Optional - Specifies which test results to plot: "strength" (global strength), "network" (network structure), "edge" (individual edges), or "centrality" (centrality measures). - **...** (dots) - Optional - Additional arguments (currently unused). ### Return Value Returns NULL invisibly. Draws plots using base R graphics. ### Example ```r # Plot global strength invariance test plot(result, what = "strength") # Plot network structure invariance test plot(result, what = "network") # Plot edge invariance tests plot(result, what = "edge") # Plot centrality tests plot(result, what = "centrality") ``` ``` -------------------------------- ### NCT_estimator_Ising(x, gamma = 0.25, AND = TRUE) Source: https://github.com/cvborkulo/networkcomparisontest/blob/master/_autodocs/api-reference/estimators.md Estimates a network structure from binary data using the Ising model via the IsingFit package. ```APIDOC ## NCT_estimator_Ising(x, gamma = 0.25, AND = TRUE) ### Description Estimates a network structure from binary data using the Ising model via the IsingFit package. This function is typically used as an estimator argument within the NCT() function when binary.data = TRUE. ### Parameters - **x** (data.frame or matrix) - Required - Binary data matrix with dimensions nobs × nvars. All values must be 0 or 1. - **gamma** (numeric) - Optional - Hyperparameter for extended BIC (EBIC) in model selection. Range: 0 to 1. Default: 0.25. - **AND** (logical) - Optional - Rule for determining edge presence. If TRUE, uses AND-rule; if FALSE, uses OR-rule. Default: TRUE. ### Return Value Returns a numeric matrix of class `matrix` representing the weighted network adjacency matrix (nvars × nvars). ### Example ```r # Create binary data set.seed(123) binary_data <- matrix(sample(0:1, 100 * 6, replace = TRUE), nrow = 100, ncol = 6) colnames(binary_data) <- c('V1', 'V2', 'V3', 'V4', 'V5', 'V6') # Estimate network using Ising model network <- NCT_estimator_Ising(binary_data, gamma = 0.25, AND = TRUE) ``` ``` -------------------------------- ### Define and use a custom network estimator in R Source: https://github.com/cvborkulo/networkcomparisontest/blob/master/_autodocs/architecture.md Implement a function with the signature estimator(data, ...) and pass it to the NCT function via the estimator argument. ```r my_estimator <- function(data, param1 = 0.5, param2 = 0.1) { # Custom network estimation logic # ... return(network_matrix) } result <- NCT(data1, data2, estimator = my_estimator, estimatorArgs = list(param1 = 0.5, param2 = 0.1)) ``` -------------------------------- ### Perform Exploratory All-Edge Testing Source: https://github.com/cvborkulo/networkcomparisontest/blob/master/_autodocs/usage-examples.md Executes the NCT function on all possible edges with Bonferroni correction for comparison. ```r # For comparison: test all edges with multiple testing correction result_exploratory <- NCT(data1, data2, gamma = 0.5, it = 1000, binary.data = FALSE, test.edges = TRUE, edges = "all", p.adjust.methods = "bonferroni", # Strict correction progressbar = TRUE) # Note: Bonferroni correction is very stringent for many tests # Focused testing (4 edges) is more powerful than exploratory (45 edges) ``` -------------------------------- ### NCT_bootnet Source: https://github.com/cvborkulo/networkcomparisontest/blob/master/_autodocs/api-reference/deprecated.md A deprecated wrapper function for NCT() that is no longer maintained. Users should migrate to the NCT() function directly. ```APIDOC ## NCT_bootnet ### Description Deprecated function that serves as a wrapper to NCT() for backward compatibility. This function is no longer maintained and should not be used in new code. ### Function Signature NCT_bootnet(...) ### Parameters - **...** (any) - Required - All arguments are forwarded directly to NCT() without modification. ### Return Value Returns an NCT object (same as NCT()). ### Migration Guide Replace calls to `NCT_bootnet(...)` with `NCT(...)`. ``` -------------------------------- ### Run Network Comparison Test for Centrality Source: https://github.com/cvborkulo/networkcomparisontest/blob/master/_autodocs/usage-examples.md Executes the NCT function with centrality testing enabled to compare node importance metrics between two datasets. ```r # Run NCT with centrality testing result_centrality <- NCT(data1, data2, gamma = 0.5, # Default for Gaussian data it = 1000, binary.data = FALSE, test.centrality = TRUE, centrality = c("strength", "betweenness", "closeness"), nodes = "all", # Test all nodes p.adjust.methods = "BH", # Benjamini-Hochberg FDR correction progressbar = TRUE) # View results summary(result_centrality) # Access centrality differences result_centrality$diffcen.real # Observed differences result_centrality$diffcen.pval # P-values ``` -------------------------------- ### S3 Methods for NCT Source: https://github.com/cvborkulo/networkcomparisontest/blob/master/_autodocs/types.md Methods for displaying, summarizing, and visualizing the results of an NCT analysis. ```APIDOC ## S3 Methods ### Description Standard S3 methods for interacting with NCT objects. ### Methods - **print.NCT()**: Displays the NCT object. - **summary.NCT()**: Provides a summary of the NCT analysis results. - **plot.NCT()**: Generates visualizations for the NCT object. ``` -------------------------------- ### Estimate Networks with Ising and GGM Estimators Source: https://github.com/cvborkulo/networkcomparisontest/blob/master/_autodocs/INDEX.md Functions for estimating binary networks via Ising model or continuous networks via Gaussian Graphical Model. ```r NCT_estimator_Ising(x, gamma = 0.25, AND = TRUE) ``` ```r NCT_estimator_GGM(x, make.positive.definite = TRUE, gamma = 0.5, corMethod = c("cor","cor_auto"), verbose = FALSE) ``` -------------------------------- ### Apply Multiple Testing Correction in NCT Source: https://github.com/cvborkulo/networkcomparisontest/blob/master/_autodocs/invariance-measures.md Demonstrates applying Bonferroni correction for broad edge testing and disabling correction for specific hypothesis-driven edge comparisons. ```r # Bonferroni correction for edge testing result <- NCT(data1, data2, test.edges = TRUE, edges = "all", p.adjust.methods = "bonferroni") # No correction for focused hypothesis-driven testing result <- NCT(data1, data2, test.edges = TRUE, edges = list(c(1,2), c(3,4)), p.adjust.methods = "none") ``` -------------------------------- ### Plotting NCT Results Source: https://github.com/cvborkulo/networkcomparisontest/blob/master/_autodocs/api-reference/s3-methods.md Demonstrates how to visualize different aspects of an NCT object, including global strength, network structure, edge invariance, and centrality measures. ```r result <- NCT(data1, data2, gamma = 0.5, it = 1000, binary.data = FALSE, test.edges = TRUE, edges = list(c(1,2), c(3,6)), test.centrality = TRUE, centrality = c("strength")) # Plot global strength invariance test plot(result, what = "strength") # Plot network structure invariance test plot(result, what = "network") # Plot edge invariance tests (one histogram per tested edge) plot(result, what = "edge") # Plot centrality tests plot(result, what = "centrality") ``` -------------------------------- ### Optimize NCT Computation Time Source: https://github.com/cvborkulo/networkcomparisontest/blob/master/_autodocs/usage-examples.md Adjust parameters to reduce execution time during testing. Note that reducing iterations may impact result reliability. ```r # Reduce iterations (for testing only, not publication) result <- NCT(data1, data2, it = 100) # Fast but unreliable # Test only specific edges result <- NCT(data1, data2, test.edges = TRUE, edges = list(c(1,2), c(3,4))) # Fewer tests # Disable centrality testing result <- NCT(data1, data2, test.centrality = FALSE) # Skip centrality # Skip progress bar result <- NCT(data1, data2, progressbar = FALSE) ``` -------------------------------- ### NCT_bootnet function signature Source: https://github.com/cvborkulo/networkcomparisontest/blob/master/_autodocs/api-reference/deprecated.md The signature for the deprecated wrapper function. ```r NCT_bootnet(...) ``` -------------------------------- ### NCT() Source: https://github.com/cvborkulo/networkcomparisontest/blob/master/_autodocs/types.md The main function used to perform the Network Comparison Test, returning an NCT object containing the results of the analysis. ```APIDOC ## NCT() ### Description Main function to perform the Network Comparison Test. Returns an NCT object containing permutation distributions and call information. ### Usage NCT(data1, data2, ...) ### Returns - **NCT object** - Contains permutation distributions (glstrinv.perm, nwinv.perm, einv.perm, diffcen.perm) and the call information (info$call). ``` -------------------------------- ### summary.NCT(object, ...) Source: https://github.com/cvborkulo/networkcomparisontest/blob/master/_autodocs/api-reference/s3-methods.md Provides a comprehensive summary of NCT results with full details about sample dependency, data type, p-value correction method, and all test statistics and p-values. ```APIDOC ## summary.NCT(object, ...) ### Description Provides a comprehensive summary of NCT results with full details about sample dependency, data type, p-value correction method, and all test statistics and p-values. More verbose than print.NCT. ### Parameters - **object** (NCT) - Required - An object of class NCT, returned by the NCT() function. - **...** (any) - Optional - Additional arguments (currently unused). ### Return Value Returns NULL invisibly. Prints detailed formatted output to console. ### Example ```r result <- NCT(data1, data2, gamma = 0.5, it = 100, binary.data = FALSE, test.edges = TRUE, edges = "all", test.centrality = TRUE, centrality = c("strength")) summary(result) ``` ``` -------------------------------- ### Process and Visualize NCT Results Source: https://github.com/cvborkulo/networkcomparisontest/blob/master/_autodocs/INDEX.md Standard workflow for printing, summarizing, and plotting results from an NCT object. ```r result <- NCT(data1, data2, ...) print(result) # Concise output summary(result) # Detailed output plot(result, what = "strength") # Visualize global strength test plot(result, what = "network") # Visualize network structure test plot(result, what = "edge") # Visualize edge tests plot(result, what = "centrality") # Visualize centrality tests ``` -------------------------------- ### plot.NCT() Source: https://github.com/cvborkulo/networkcomparisontest/blob/master/_autodocs/README.md S3 plot method for NCT objects. ```APIDOC ## plot.NCT(x, ...) ### Description Generates a plot for the NCT object results. ``` -------------------------------- ### Handle Positive Definiteness Warnings Source: https://github.com/cvborkulo/networkcomparisontest/blob/master/_autodocs/usage-examples.md Ensure correlation matrices are positive definite by enabling automatic correction. ```r # Default behavior: automatically corrects result <- NCT(data1, data2, make.positive.definite = TRUE) ``` -------------------------------- ### Access Global Strength Invariance Results in R Source: https://github.com/cvborkulo/networkcomparisontest/blob/master/_autodocs/invariance-measures.md Accessing specific components of the NCT result object to retrieve observed statistics and p-values. ```r result$glstrinv.real # e.g., 3.21 (difference in global strength) result$glstrinv.sep # e.g., c(15.44, 12.23) (strengths of network 1 and 2) result$glstrinv.pval # e.g., 0.087 (p > 0.05: networks not significantly different in strength) ``` -------------------------------- ### Generate Custom Summary Tables in R Source: https://github.com/cvborkulo/networkcomparisontest/blob/master/_autodocs/usage-examples.md Filter and sort edge results to identify and print significant network edges. ```r # Build custom summary table edge_summary <- result$einv.pvals edge_summary$significant <- edge_summary[, 3] < 0.05 edge_summary <- edge_summary[order(edge_summary[, 3]), ] # Sort by p-value # Print top significant edges cat("Top 5 Significant Edges:\n") print(head(edge_summary[edge_summary$significant, ], 5)) ``` -------------------------------- ### Summarize NCT results Source: https://github.com/cvborkulo/networkcomparisontest/blob/master/tests/testthat/_snaps/NCT.md Displays the summary of an NCT object, showing invariance test statistics and p-values for different input configurations. ```R summary(NCT_a) ``` ```R summary(NCT_b) ``` ```R summary(NCT_c) ``` ```R summary(NCT_d) ``` -------------------------------- ### Testing with expected influence (signed strength) Source: https://github.com/cvborkulo/networkcomparisontest/blob/master/_autodocs/api-reference/nct.md Tests for differences in expected influence by setting abs = FALSE to include edge weight signs. ```r # Test with signed global strength (expected influence) instead of absolute strength result <- NCT(data1, data2, gamma = 0.5, it = 1000, binary.data = FALSE, abs = FALSE, # Include sign of edge weights test.edges = TRUE, edges = "all") summary(result) ``` -------------------------------- ### Network Estimator Functions Source: https://github.com/cvborkulo/networkcomparisontest/blob/master/_autodocs/README.md Specific estimators for different data types. Use NCT_estimator_Ising for binary data and NCT_estimator_GGM for Gaussian data. ```r NCT_estimator_Ising(x, gamma = 0.25, AND = TRUE) ``` ```r NCT_estimator_GGM(x, make.positive.definite = TRUE, gamma = 0.5, corMethod = c("cor","cor_auto"), verbose = FALSE) ``` -------------------------------- ### Execute Network Comparison Tests Source: https://github.com/cvborkulo/networkcomparisontest/blob/master/_autodocs/usage-examples.md Performs invariance tests for network structure, global strength, and specific edges using the NCT function. ```r # Basic comparison: test network structure and global strength only result_basic <- NCT(data1, data2, gamma = 0.25, # EBIC hyperparameter for binary data it = 1000, # 1000 permutations binary.data = TRUE, progressbar = TRUE) # Print summary summary(result_basic) # More detailed: also test specific edges result_edges <- NCT(data1, data2, gamma = 0.25, it = 1000, binary.data = TRUE, test.edges = TRUE, # Enable edge testing edges = list(c(1, 2), c(3, 4), c(5, 6)), # Test 3 specific edges p.adjust.methods = "bonferroni", progressbar = TRUE) summary(result_edges) ```