| testEdges | R Documentation |
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).
testEdges(
networksDF,
testType = c("single", "two.sample"),
group1,
group2 = NULL,
paired = FALSE,
alternative = c("two.sided", "greater", "less"),
padjustMethod = "BH",
minMeanEdge = 0
)
networksDF |
A data.frame output from |
testType |
Character specifying the test type. Options are:
|
group1 |
Character vector of column names in |
group2 |
Character vector of column names in |
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 |
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). |
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.
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
## 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.