tna: An R package for Transition Network Analysis

R-CMD-check Codecov test coverage License: MIT

An R package for the analysis of relational dynamics through Transition Network Analysis (TNA). TNA provides tools for building TNA models, plotting transition networks, calculating centrality measures, and identifying dominant events and patterns. TNA statistical techniques (e.g., bootstrapping and permutation tests) ensure the reliability of observed insights and confirm that identified dynamics are meaningful. See (Saqr et al., 2024) for more details on TNA.

Installation

You can install tna from GitHub with:

# install.packages("devtools")
devtools::install_github("sonsoleslp/tna")

Example

Load the library

library("tna")

Example data

data("group_regulation", package = "tna")

Build a Markov model

tna_model <- tna(group_regulation)
summary(tna_model)
metric value
Node Count 9.00
Edge Count 78.00
Network Density 1.00
Mean Distance 0.05
Mean Out-Strength 1.00
SD Out-Strength 0.81
Mean In-Strength 1.00
SD In-Strength 0.00
Mean Out-Degree 8.67
SD Out-Degree 0.71
Centralization (Out-Degree) 0.02
Centralization (In-Degree) 0.02
Reciprocity 0.99

Plot the transition network

plot(tna_model, cut = 0.3)

Calculate the centrality measures

cent <- centralities(tna_model)
State OutStrength InStrength ClosenessIn ClosenessOut Closeness Betweenness BetweennessRSP Diffusion Clustering
adapt 1.0000000 0.3445778 13.406025 2.333065 18.546309 17 1 5.586292 0.3369839
cohesion 0.9728614 0.8116478 3.651321 2.791075 13.812739 0 11 5.208633 0.2996487
consensus 0.9179965 2.6672185 0.797502 4.344062 11.481098 0 49 4.659728 0.1607773
coregulate 0.9766497 0.5665811 4.546876 2.308867 5.973798 5 15 5.147938 0.3057842
discuss 0.8051126 1.1882315 1.954285 2.680996 7.308377 0 30 4.627577 0.2397108
emotion 0.9231583 0.8941312 1.568289 3.132785 14.538635 0 18 5.069888 0.2904793
monitor 0.9818562 0.3457150 6.243045 2.210039 7.757314 3 5 5.156837 0.2888819
plan 0.6257918 1.1937843 5.474533 2.913798 17.593057 10 20 3.487529 0.2874904
synthesis 1.0000000 0.1915394 12.270650 2.183927 15.900927 14 3 5.582502 0.3586136

Plot the centrality measures

plot(cent, ncol = 3)

Estimate centrality stability

estimate_centrality_stability(tna_model)
#> Centrality Stability Coefficients
#> 
#>  InStrength OutStrength Betweenness 
#>         0.9         0.9         0.7

Identify and plot communities

coms <- communities(tna_model)
plot(coms)

Find and plot cliques

cqs <- cliques(tna_model, threshold = 0.12)
plot(cqs)

Compare high achievers (first 1000) with low achievers (last 1000)

tna_model_start_high <- tna(group_regulation[1:1000, ])
tna_model_start_low <- tna(group_regulation[1001:2000, ])
comparison <- permutation_test(
  tna_model_start_high, 
  tna_model_start_low,
  measures = c("InStrength")
)

Simple comparison vs. permutation test comparison

plot_compare(tna_model_start_high, tna_model_start_low)
plot(comparison)

Compare centralities

print(comparison$centralities$stats)
State Centrality diff_true p_value
adapt InStrength -0.23693341 0.000
cohesion InStrength 0.01634987 0.753
consensus InStrength 0.53680793 0.000
coregulate InStrength -0.25275371 0.000
discuss InStrength -0.09009651 0.050
emotion InStrength 0.19288376 0.000
monitor InStrength -0.09192991 0.001
plan InStrength 0.12225988 0.007
synthesis InStrength -0.04909607 0.003