View source: R/permutation_test.R
| permutation | R Documentation |
Compares two networks estimated by build_network using a
permutation test. Works with all built-in methods (transition and
association) as well as custom registered estimators. The test shuffles
which observations belong to which group, re-estimates networks, and tests
whether observed edge-wise differences exceed chance.
For transition methods ("relative", "frequency",
"co_occurrence"), uses a fast pre-computation strategy: per-sequence
count matrices are computed once, and each permutation iteration only
shuffles group labels and computes group-wise colSums.
For association methods ("cor", "pcor", "glasso",
and custom estimators), the full estimator is called on each permuted
group split.
permutation(
x,
y = NULL,
iter = 1000L,
alpha = 0.05,
paired = FALSE,
adjust = "none",
nlambda = 50L,
seed = NULL
)
x |
A |
y |
A |
iter |
Integer. Number of permutation iterations (default: 1000). |
alpha |
Numeric. Significance level (default: 0.05). |
paired |
Logical. If |
adjust |
Character. p-value adjustment method passed to
|
nlambda |
Integer. Number of lambda values for the |
seed |
Integer or NULL. RNG seed for reproducibility. |
An object of class "net_permutation" containing:
The first netobject.
The second netobject.
Observed difference matrix (x - y).
Observed difference where p < alpha, else 0.
P-value matrix (adjusted if adjust != "none").
Effect size matrix (observed diff / SD of permutation diffs).
Long-format data frame of edge-level results.
The network estimation method.
Number of permutation iterations.
Significance level used.
Whether paired permutation was used.
p-value adjustment method used.
build_network, bootstrap_network,
print.net_permutation,
summary.net_permutation
s1 <- data.frame(V1 = c("A","B","C"), V2 = c("B","C","A"))
s2 <- data.frame(V1 = c("A","C","B"), V2 = c("C","B","A"))
n1 <- build_network(s1, method = "relative")
n2 <- build_network(s2, method = "relative")
perm <- permutation(n1, n2, iter = 10)
set.seed(1)
d1 <- data.frame(V1 = sample(LETTERS[1:4], 20, TRUE),
V2 = sample(LETTERS[1:4], 20, TRUE),
V3 = sample(LETTERS[1:4], 20, TRUE))
d2 <- data.frame(V1 = sample(LETTERS[1:4], 20, TRUE),
V2 = sample(LETTERS[1:4], 20, TRUE),
V3 = sample(LETTERS[1:4], 20, TRUE))
net1 <- build_network(d1, method = "relative")
net2 <- build_network(d2, method = "relative")
perm <- permutation(net1, net2, iter = 100, seed = 42)
print(perm)
summary(perm)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.