testEdges: Test edges from SCORPION networks

View source: R/testEdges.R

testEdgesR Documentation

Test edges from SCORPION networks

Description

Performs statistical testing of network edges from runSCORPION output. Supports single-sample tests (testing if edges differ from zero) and two-sample tests (comparing edges between two groups).

Usage

testEdges(
  networksDF,
  testType = c("single", "two.sample"),
  group1,
  group2 = NULL,
  paired = FALSE,
  alternative = c("two.sided", "greater", "less"),
  padjustMethod = "BH",
  minMeanEdge = 0
)

Arguments

networksDF

A data.frame output from runSCORPION containing TF-target pairs as rows and network identifiers as columns.

testType

Character specifying the test type. Options are:

  • "single": Single-sample test (one-sample t-test against zero)

  • "two.sample": Two-sample comparison (t-test between two groups)

group1

Character vector of column names in networksDF representing the first group (or the only group for single-sample tests).

group2

Character vector of column names in networksDF representing the second group. Required for two-sample tests, ignored for single-sample tests.

paired

Logical indicating whether to perform a paired t-test. Default FALSE. When TRUE, group1 and group2 must have the same length and be in matched order (e.g., group1[1] is paired with group2[1]). Useful for comparing matched samples such as Tumor vs Normal from the same patient.

alternative

Character specifying the alternative hypothesis. Options: "two.sided" (default), "greater", or "less".

padjustMethod

Character specifying the p-value adjustment method for multiple testing correction. See p.adjust for options. Default "BH" (Benjamini-Hochberg FDR).

minMeanEdge

Numeric threshold for minimum mean absolute edge weight to include in testing. Edges with mean absolute weight below this threshold are excluded. Default 0 (no filtering).

Details

For single-sample tests, the function tests whether the mean edge weight across replicates significantly differs from zero using a one-sample t-test.

For two-sample tests, the function compares edge weights between two groups using Welch's t-test (unequal variances assumed).

For paired tests, the function calculates the difference between matched pairs and performs a one-sample t-test on the differences (testing if mean difference differs from zero). This is appropriate when samples are matched (e.g., Tumor and Normal from the same patient).

Edges are tested independently, and p-values are adjusted for multiple testing using the specified method.

The function uses fully vectorized computations for efficiency, making it suitable for large-scale analyses with millions of edges. T-statistics and p-values are calculated using matrix operations without iteration.

Value

A data.frame containing:

  • tf: Transcription factor

  • target: Target gene

  • meanEdge: Mean edge weight

  • tStatistic: Test statistic

  • pValue: Raw p-value

  • pAdj: Adjusted p-value

  • For two-sample tests: meanGroup1, meanGroup2, diffMean (Group1 - Group2), log2FoldChange

Examples

## Not run: 
# Load test data and build networks by donor and region
# Note: T = Tumor, N = Normal, B = Border regions
data(scorpionTest)
nets <- runSCORPION(
  gexMatrix = scorpionTest$gex,
  tfMotifs = scorpionTest$tf,
  ppiNet = scorpionTest$ppi,
  cellsMetadata = scorpionTest$metadata,
  groupBy = c("donor", "region")
)

# Single-sample test: Test if edges in Tumor region differ from zero
tumor_nets <- grep("--T$", colnames(nets), value = TRUE)  # T = Tumor
results_single <- testEdges(
  networksDF = nets,
  testType = "single",
  group1 = tumor_nets
)

# Two-sample test: Compare Tumor vs Border regions
tumor_nets <- grep("--T$", colnames(nets), value = TRUE)  # T = Tumor
border_nets <- grep("--B$", colnames(nets), value = TRUE)  # B = Border
results_tumor_vs_border <- testEdges(
  networksDF = nets,
  testType = "two.sample",
  group1 = tumor_nets,
  group2 = border_nets
)

# View top differential edges (Tumor vs Border)
head(results_tumor_vs_border[order(results_tumor_vs_border$pAdj), ])

# Compare Tumor vs Normal regions
normal_nets <- grep("--N$", colnames(nets), value = TRUE)  # N = Normal
results_tumor_vs_normal <- testEdges(
  networksDF = nets,
  testType = "two.sample",
  group1 = tumor_nets,
  group2 = normal_nets
)

# Filter by minimum edge weight for focused analysis
results_filtered <- testEdges(
  networksDF = nets,
  testType = "two.sample",
  group1 = tumor_nets,
  group2 = normal_nets,
  minMeanEdge = 0.1  # Only test edges with |mean| >= 0.1
)

# Paired t-test: Compare matched Tumor vs Normal samples (same patient)
# Ensure columns are ordered by patient: P31--T with P31--N, P32--T with P32--N, etc.
tumor_nets_ordered <- c("P31--T", "P32--T", "P33--T")
normal_nets_ordered <- c("P31--N", "P32--N", "P33--N")
results_paired <- testEdges(
  networksDF = nets,
  testType = "two.sample",
  group1 = tumor_nets_ordered,
  group2 = normal_nets_ordered,
  paired = TRUE
)

## End(Not run)

SCORPION documentation built on Feb. 5, 2026, 1:06 a.m.

Related to testEdges in SCORPION...