
Compare Two Networks from Sequence Data using a Permutation Test
Source:R/permutation.R
permutation_test.RdThis function compares two networks built from sequence data using permutation tests. The function builds Markov models for two sequence objects, computes the transition probabilities, and compares them by performing permutation tests. It returns the differences in transition probabilities, effect sizes, estimated p-values, and confidence intervals.
Usage
permutation_test(x, ...)
# S3 method for class 'tna'
permutation_test(
x,
y,
adjust = "none",
iter = 1000,
paired = FALSE,
level = 0.05,
measures = character(0),
actor = NULL,
...
)Arguments
- x
A
tnaobject containing sequence data for the firsttnamodel. Grouped models with scaled edge weights, and their networks, are not resampled (an error of classtna_error_scaling). Two models with scaled edge weights are compared with a message (classtna_message_scaling): each is scaled on its own, so comparing them is not warranted.- ...
Additional arguments passed to
centralities().- y
A
tnaobject containing sequence data for the secondtnamodel.- adjust
A
characterstring for the method to adjust p-values with for multiple comparisons. The default is"none"for no adjustment. See themethodargument ofstats::p.adjust()for details and available adjustment methods. The edge p-values are corrected over the edges tested: the transitions present in either network, each pair of a co-occurrence network counted once. A transition absent from both keeps its p-value of 1.- iter
An
integergiving the number of permutations to perform. The default is 1000.- paired
A
logicalvalue. IfTRUE, perform paired permutation tests; ifFALSE, perform unpaired tests. The default isFALSE.- level
A
numericvalue giving the significance level for the permutation tests. The default is 0.05.- measures
A
charactervector of centrality measures to test. Seecentralities()for a list of available centrality measures.- actor
An optional actor identifier for sequences nested in actors (for example, several sessions per student). Either a
characterstring naming a non-sequence column of the data the models were built from (such as a column ofmeta_datafromprepare_data()), or a vector with one identifier per sequence (the sequences ofxfirst, then those ofy). When given, the permutation respects the nesting: actors whose sequences are all in one group are reassigned between the groups as whole units, and the sequences of actors present in both groups are shuffled within the actor (Good, 2005). A warning is given when the actors allow too few distinct permutations to reachlevel. Cannot be combined withpaired = TRUE. The defaultNULLpermutes single sequences.
Value
A tna_permutation object which is a list with two elements:
edges and centralities (NULL when measures is empty). Both contain
the following elements:
stats: Adata.frameof original differences, effect sizes, and estimated p-values, with one row per edge (columnsedge_name,diff_true,effect_size,p_value) or per state and centrality measure (columnsstate,centrality,diff_true,effect_size,p_value). The effect size is the observed difference divided by the standard deviation of the differences of the permuted samples, andNAwhen the permuted differences do not vary.diffs_true: The differences in the data: amatrixfor the edges, and adata.framewith one row per state and one column per measure for the centralities.diffs_sig: The same asdiffs_truewith the non-significant differences set to zero.
Use summary.tna_permutation() for the results as a tidy table.
References
Good, P. (2005). Permutation, Parametric, and Bootstrap Tests of Hypotheses (3rd ed.). Springer.
See also
Validation functions
bootstrap(),
deprune(),
estimate_cs(),
markov_order(),
permutation_test.group_tna(),
plot.group_tna_bootstrap(),
plot.group_tna_permutation(),
plot.group_tna_stability(),
plot.tna_bootstrap(),
plot.tna_markov_order(),
plot.tna_permutation(),
plot.tna_reliability(),
plot.tna_stability(),
print.group_tna_bootstrap(),
print.group_tna_permutation(),
print.group_tna_stability(),
print.summary.group_tna_bootstrap(),
print.summary.tna_bootstrap(),
print.summary.tna_markov_order(),
print.tna_bootstrap(),
print.tna_markov_order(),
print.tna_permutation(),
print.tna_reliability(),
print.tna_stability(),
prune(),
pruning_details(),
reliability(),
reprune(),
summary.group_tna_bootstrap(),
summary.tna_bootstrap(),
summary.tna_markov_order(),
summary.tna_permutation(),
summary.tna_reliability(),
summary.tna_stability()
Examples
model_x <- tna(head(group_regulation, 200))
model_y <- tna(tail(group_regulation, 200))
# Small number of iterations for CRAN
permutation_test(model_x, model_y, iter = 20)
#> # A tibble: 81 × 4
#> edge_name diff_true effect_size p_value
#> <chr> <dbl> <dbl> <dbl>
#> 1 adapt -> adapt 0 NA 1
#> 2 cohesion -> adapt 0.00541 0.912 0.857
#> 3 consensus -> adapt 0.00106 0.329 0.952
#> 4 coregulate -> adapt 0.0111 0.839 0.381
#> 5 discuss -> adapt -0.116 -6.90 0.0476
#> 6 emotion -> adapt 0.00275 0.314 0.905
#> 7 monitor -> adapt -0.0102 -1.10 0.524
#> 8 plan -> adapt 0.00180 0.591 0.429
#> 9 synthesis -> adapt -0.0863 -1.44 0.190
#> 10 adapt -> cohesion -0.0361 -0.445 0.762
#> # ℹ 71 more rows