
Transition network analysis of nested data with the tna R package: Resampling, permutation, and mosaic tests that respect the nesting
Mohammed Saqr
University of Eastern FinlandSonsoles López-Pernas
University of Eastern Finland2026-11-27
Source:vignettes/articles/tna-nested-data.Rmd
tna-nested-data.RmdKeywords: nested data; cluster bootstrap; permutation test; Rao-Scott test; transition network analysis; R
Introduction
The order in which learners plan, act, monitor and revise provides
information about learning processes that activity counts alone cannot
capture (Bakeman & Gottman, 1997; Molenaar & Järvelä, 2014;
Peeters et al., 2020; Reimann, 2009; Saqr & López-Pernas, 2023; Saqr
et al., 2019). Markov models provide a basis for analysing transitions
in educational process data (Helske et al., 2024), while research on
memory in network flows and higher-order models shows how dependencies
can extend beyond the immediately preceding state (Lambiotte et al.,
2019; Rosvall et al., 2014; Scholtes, 2017). Transition network analysis
(TNA) represents these sequential patterns as a directed network: nodes
represent coded states, and edges represent the probabilities of moving
from one state to the next (Saqr, López-Pernas, & Tikka, 2025; Saqr,
López-Pernas, Törmänen, et al., 2025). This companion tutorial focuses
on analysing sequences that are nested within a higher unit using the
tna R package (Tikka et al., 2025). We assume basic
familiarity with preparing sequence data and building a TNA model.
Transition network analysis is part of Dynalytics (Saqr,
López-Pernas, & Misiejuk, 2026), a framework in which validation is
integral to the analysis of dynamical systems. The bootstrap tests the
stability of each edge, case-dropping the stability of centralities,
split-half reliability the consistency of the network, permutation the
differences between groups, and the mosaic test the association between
states and groups. With nested sequences, these tests are only as
trustworthy as the units used to resample, partition or compare the
data. The actor argument identifies the higher unit and
makes validation respect the dependence among sequences nested within
it. A pattern is reported or refuted based on a rigorous statistical
test matching the claims.
In many studies, sequences are collected within shared settings. A project may generate several work sessions, and students may belong to the same team or class. Sessions within a project share its goals and development history, while students within a team or class share tasks, interactions and instructional conditions. These shared circumstances can make sequences from the same higher unit more alike than sequences from different units. Keeping each sequence intact preserves its internal order, but inference must also account for the dependence between sequences belonging to the same unit (Field & Welsh, 2007; Ren et al., 2010).
We illustrate this problem using coded human contributions from human-AI programming sessions nested within projects (Saqr, 2026). We first prepare one sequence per session and build an aggregate transition network. We then examine edge stability, centrality stability and split-half reliability, before comparing the earlier and later periods of the study. At each stage, we compare an analysis that treats sessions as independent with an analysis that respects their project membership. The purpose is to show how the unit used for resampling and statistical testing affects the evidence supporting a network, and how to make that unit correspond to the structure of a study.
Installation
Only the tna package is needed for this tutorial; the
data are read directly from Zenodo.
install.packages("tna")Why Nesting Matters
There are two sources of dependence to consider. Within a sequence, the order of events is the object of analysis, so resampling should preserve the observed transitions. Between sequences, shared membership of a project, team or class can introduce additional dependence. Resampling intact sessions preserves their internal order, but still assumes independence between sessions. When sessions within projects are positively associated, this can overstate the amount of independent information and produce confidence intervals that are too narrow or tests that reject too readily. Cluster resampling instead uses the higher units as the independent sampling units and retains the observations belonging to each selected unit (Field & Welsh, 2007; Ren et al., 2010).
The actor argument identifies this higher unit in the
validation functions. In the bootstrap, projects are sampled with
replacement and all their sessions accompany them. In case-dropping, a
selected project and all its sessions are removed together. In
split-half reliability, all sessions from a project are assigned to the
same half. In the restricted permutation test, the reassignment of
period labels follows project membership: projects observed in only one
period move together, while sessions from projects observed in both
periods are shuffled within their own project. For the mosaic analysis,
project membership is used to account for clustering when calculating
residuals and tests of association.
The session remains the unit that defines a sequence throughout these
procedures. Project membership determines which sequences are sampled,
removed or assigned together. This distinction is especially important
when using actor in different functions: during data
preparation it identifies the sequences to construct, whereas in the
validation calls it identifies the higher unit to preserve. The choice
should follow the study design. Here, inference treats projects as the
independent units, and the session-level analyses provide a sensitivity
comparison.
The Data
We read the human_long dataset from its Zenodo record
(Saqr, 2026); it contains coded human turns from 429 human-AI
vibe-coding sessions nested within 34 projects. The nine codes are
Command, Correct, Frustrate, Inquire, Interrupt, Refine, Request,
Specify and Verify. These codes become the states of the transition
network. A human turn can contain more than one code, so rows represent
code occurrences rather than necessarily distinct messages.
Each coded observation has a session identifier and a project identifier. The session identifies the sequence within which transitions are observed, and the project identifies the higher unit to which that sequence belongs. This gives us the same analytical distinction needed in educational studies that record repeated sessions within learners or individual learners within teams.
message_id project session_id timestamp session_date code
1 3439 Project_7 0086cabebd15 1772661600 2026-03-05 Specify
2 3439 Project_7 0086cabebd15 1772661600 2026-03-05 Command
3 3439 Project_7 0086cabebd15 1772661600 2026-03-05 Specify
4 3440 Project_7 0086cabebd15 1772661600 2026-03-05 Interrupt
5 3442 Project_7 0086cabebd15 1772661600 2026-03-05 Verify
6 3444 Project_7 0086cabebd15 1772661600 2026-03-05 Specify
cluster code_order order_in_session
1 Directive 1 1
2 Directive 2 2
3 Directive 3 3
4 Metacognitive 1 4
5 Evaluative 1 7
6 Directive 1 10
We divide the study period at 21 February 2026. Sessions dated before that day are labelled Early, and sessions dated on or after it are labelled Late. These chronological portions of the study will be used for the group comparison later in the tutorial; the division does not imply equal numbers of sessions or projects in each period.
human_long$period <- ifelse(human_long$session_date < "2026-02-21", "Early", "Late")The prepare_data() function converts the long event log
into sequences. We use actor = "session_id" to construct
one sequence per session, and order_in_session to arrange
its codes. Supplying this numeric ordering variable through
order = means that sequence order is already defined and no
timestamp parsing is needed. The project and period columns are retained
as metadata, making them available for the subsequent validation and
group comparison. In this call, the session identifier defines the
boundaries of each sequence; project membership will be supplied
separately when selecting the higher unit for inference.
prepared <- prepare_data(human_long, action = "code", actor = "session_id",
order = "order_in_session")Before fitting the model, we examine how many sessions each project contributes. The contributions range from one to 81 sessions, with a median of two and a mean of 12.62. The nesting is therefore unbalanced: many projects contribute few sessions, while some contribute substantially more. This matters when resampling whole projects because retaining or removing a project can involve very different numbers of sessions. It also makes clear why the number of sessions cannot be treated as the number of independent projects.
Min. 1st Qu. Median Mean 3rd Qu. Max.
1.0 2.0 2.0 12.6 13.0 81.0
Building the Model
We build one TNA model from all 429 sessions. The model combines transitions observed within sessions while preserving their boundaries. In the transition probability matrix, a row identifies the current state and a column identifies the following state. A diagonal entry represents repetition of the same code. For example, the estimated probability of Specify following Request is approximately 0.62, and the probability of Specify following Refine is approximately 0.46. These describe the pooled transition patterns that the validation procedures will examine.
The initial probabilities describe the states with which sessions
begin. The network plot provides a visual representation of the
transition matrix, with stronger transitions drawn as thicker edges.
Setting minimum = 0.05 hides smaller edges in the plot;
this is a display threshold and does not establish statistical support.
Both versions of each validation procedure below start from this same
fitted model.
model <- tna(prepared)
modelState Labels :
Command, Correct, Frustrate, Inquire, Interrupt, Refine, Request, Specify, Verify
Transition Probability Matrix :
Command Correct Frustrate Inquire Interrupt Refine Request Specify
Command 0.239 0.088 0.054 0.065 0.035 0.038 0.155 0.277
Correct 0.093 0.092 0.137 0.057 0.055 0.112 0.120 0.279
Frustrate 0.103 0.117 0.177 0.075 0.046 0.171 0.110 0.125
Inquire 0.200 0.126 0.097 0.187 0.093 0.064 0.085 0.105
Interrupt 0.261 0.080 0.092 0.123 0.102 0.080 0.072 0.120
Refine 0.057 0.075 0.071 0.047 0.042 0.087 0.147 0.455
Request 0.096 0.020 0.046 0.066 0.051 0.033 0.041 0.616
Specify 0.264 0.058 0.081 0.071 0.166 0.074 0.071 0.172
Verify 0.226 0.078 0.162 0.119 0.043 0.097 0.117 0.082
Verify
Command 0.047
Correct 0.056
Frustrate 0.077
Inquire 0.043
Interrupt 0.068
Refine 0.018
Request 0.031
Specify 0.043
Verify 0.076
Initial Probabilities :
Command Correct Frustrate Inquire Interrupt Refine Request Specify
0.1282 0.0000 0.0023 0.0000 0.0210 0.0023 0.0280 0.8182
Verify
0.0000
plot(model, minimum = 0.05)
Transition network of the human turns in 429 vibe-coding sessions
Bootstrapping Edges
Bootstrapping examines how an estimated network varies when the
observed data are resampled with replacement and the model is rebuilt
(Davison & Hinkley, 1997; Efron, 1979; Efron & Tibshirani, 1986,
1994). We run the procedure twice, using 1,000 iterations and the same
seed. The first call samples sessions individually, treating them as
independent. The second uses actor = "project" to sample
whole projects, carrying all the sessions of each selected project into
the bootstrap sample. This is a cluster bootstrap, which preserves the
dependence represented by project membership (Cameron et al., 2008;
Field & Welsh, 2007).
The distinction concerns the source of sampling variation. The session bootstrap asks how the network changes when individual sessions are sampled from the observed collection. The project bootstrap asks how it changes when the collection of contributing projects is resampled. Because projects differ in size, project bootstrap samples can also differ in their total number of sessions. The observed transition estimates remain the same; the uncertainty surrounding them is evaluated under a different sampling structure.
boot_naive <- bootstrap(model, iter = 1000, seed = 265)
boot_nested <- bootstrap(model, iter = 1000, seed = 265, actor = "project")We compare two aspects of the summaries: how many edges meet the
bootstrap stability criterion and how wide their confidence intervals
are. The sig flag records whether an edge meets that
criterion. The session bootstrap identifies 45 significant edges,
compared with 37 under project resampling. These flags describe
resampling support for the estimated edges and should be interpreted
alongside their weights and intervals.
The interval-width ratio divides the width of each project bootstrap interval by the corresponding session bootstrap width. A ratio above one indicates a wider interval after accounting for nesting. The median ratio is 1.18 and the mean is 1.21, indicating generally greater uncertainty under project resampling. The ratios range from 0.76 to 1.92, however, so the change is not uniform across edges. Some intervals become narrower.
boot_both <- merge(summary(boot_naive), summary(boot_nested),
by = c("from", "to"), suffixes = c("_naive", "_nested"))
c(naive = sum(boot_both$sig_naive), nested = sum(boot_both$sig_nested)) naive nested
45 37
ci_width_ratio <- with(boot_both, (ci_upper_nested - ci_lower_nested) /
(ci_upper_naive - ci_lower_naive))
summary(ci_width_ratio) Min. 1st Qu. Median Mean 3rd Qu. Max.
0.755 1.001 1.178 1.207 1.378 1.923
The following table identifies the edges whose significance flags change. Eighteen edges change classification: 13 lose bootstrap support and five gain it. For example, Command to Verify changes from p = .014 in the session bootstrap to p = .128 in the project bootstrap, while Command to Refine changes from p = .074 to p = .025. The reduction from 45 to 37 supported edges therefore reflects changes in both directions.
These changes arise from resampling the same observed network at different levels. An edge that loses support is still present in the fitted transition matrix, but its interpretation as a stable feature is less secure under the project sampling structure. The plots display the edges retained by each procedure and help locate these differences within the network. The substantive interpretation should follow the procedure that matches the nesting in the data.
subset(boot_both, sig_naive != sig_nested,
select = c(from, to, weight_naive, p_value_naive, p_value_nested)) from to weight_naive p_value_naive p_value_nested
6 Command Refine 0.038 0.074 0.025
9 Command Verify 0.047 0.014 0.128
10 Correct Command 0.093 0.058 0.048
11 Correct Correct 0.092 0.037 0.054
15 Correct Refine 0.112 0.019 0.053
21 Frustrate Frustrate 0.177 0.004 0.056
25 Frustrate Request 0.110 0.019 0.170
29 Inquire Correct 0.126 0.009 0.116
39 Interrupt Frustrate 0.092 0.041 0.192
46 Refine Command 0.057 0.048 0.179
52 Refine Request 0.147 0.023 0.058
55 Request Command 0.096 0.011 0.054
58 Request Inquire 0.066 0.055 0.020
67 Specify Inquire 0.071 0.007 0.070
72 Specify Verify 0.043 0.005 0.079
75 Verify Frustrate 0.162 0.031 0.074
76 Verify Inquire 0.119 0.051 0.041
80 Verify Specify 0.082 0.081 0.029


Edges that survive the bootstrap, ignoring and respecting the nesting
Centrality Stability
Centrality measures describe the positions of states within the network. Case-dropping examines whether those positions remain similar when part of the data is removed and the network is estimated again. The correlation stability coefficient, or CS-coefficient, summarises the largest tested proportion of cases that can be removed while retaining the required agreement with the original centrality values across resamples (Epskamp et al., 2018). Larger values indicate greater stability under this procedure; the coefficient itself is a proportion of cases removed, rather than a correlation.
We compare session-level case-dropping with case-dropping that
removes whole projects using actor = "project", with 500
iterations in each analysis. InStrength and Betweenness both have
CS-coefficients of 0.90 under either procedure. OutStrength decreases
from 0.80 when sessions are dropped to 0.70 when projects are dropped.
Thus, the effect of accounting for nesting differs across centrality
measures.
The unit underlying these coefficients also changes. A coefficient in the first analysis refers to a proportion of sessions, whereas a coefficient in the second refers to a proportion of projects. Because project sizes are unequal, removing a given proportion of projects need not remove the same proportion of sessions. We should therefore read the coefficients as stability summaries under their respective sampling designs, and use the project-level result when discussing robustness to the removal of projects.
set.seed(265)
cs_naive <- estimate_cs(model, iter = 500)
cs_nested <- estimate_cs(model, iter = 500, actor = "project")
cs_naiveCentrality Stability Coefficients
InStrength OutStrength Betweenness
0.9 0.8 0.9
cs_nestedCentrality Stability Coefficients
InStrength OutStrength Betweenness
0.9 0.7 0.9


Centrality stability, ignoring and respecting the nesting
Split-Half Reliability
Split-half reliability examines agreement between networks estimated
from two subsets of the data. The procedure repeatedly divides the data,
builds a network from each half and compares the resulting edge weights.
If sessions are allocated freely, the two halves can contain sessions
from the same project. Shared project characteristics can then
contribute to agreement between the halves. With
actor = "project", each project is assigned wholly to one
half, so the comparison concerns networks built from different sets of
projects. The numbers of sessions in the halves can differ because
projects contribute unequal numbers of sessions.
Across 500 splits, the mean Pearson correlation between the two networks decreases from 0.97 in the session-level analysis to 0.95 in the project-level analysis. The average mean absolute difference also increases, although both values round to 0.02, and the mean Bray-Curtis dissimilarity increases from 0.08 to 0.10. Higher correlations indicate greater similarity, whereas larger absolute differences and dissimilarities indicate weaker agreement. The overall edge patterns remain highly correlated, but the discrepancy measures show less agreement when entire projects are kept separate. Reporting both forms of comparison helps distinguish similarity in the pattern of edges from closeness in their estimated weights.
set.seed(265)
rel_naive <- reliability(model, iter = 500)
rel_nested <- reliability(model, iter = 500, actor = "project")
rel_naiveReliability summary
[38;5;246m# A tibble: 4 × 8
[39m
metric mean sd median min max q25 q75
[3m
[38;5;246m<chr>
[39m
[23m
[3m
[38;5;246m<dbl>
[39m
[23m
[3m
[38;5;246m<dbl>
[39m
[23m
[3m
[38;5;246m<dbl>
[39m
[23m
[3m
[38;5;246m<dbl>
[39m
[23m
[3m
[38;5;246m<dbl>
[39m
[23m
[3m
[38;5;246m<dbl>
[39m
[23m
[3m
[38;5;246m<dbl>
[39m
[23m
[38;5;250m1
[39m Mean Abs. Diff. 0.017
[4m2
[24m 0.001
[4m7
[24m
[4m2
[24m 0.017
[4m1
[24m 0.012
[4m2
[24m 0.024
[4m9
[24m 0.015
[4m9
[24m 0.018
[4m3
[24m
[38;5;250m2
[39m Median Abs. Diff. 0.013
[4m1
[24m 0.001
[4m8
[24m
[4m0
[24m 0.013
[4m1
[24m 0.008
[4m5
[24m
[4m5
[24m 0.018
[4m4
[24m 0.011
[4m8
[24m 0.014
[4m4
[24m
[38;5;250m3
[39m Pearson 0.970 0.006
[4m5
[24m
[4m4
[24m 0.970 0.936 0.986 0.966 0.974
[38;5;250m4
[39m Bray-Curtis 0.077
[4m2
[24m 0.007
[4m7
[24m
[4m4
[24m 0.077
[4m1
[24m 0.055
[4m1
[24m 0.112 0.071
[4m5
[24m 0.082
[4m3
[24m
rel_nestedReliability summary
[38;5;246m# A tibble: 4 × 8
[39m
metric mean sd median min max q25 q75
[3m
[38;5;246m<chr>
[39m
[23m
[3m
[38;5;246m<dbl>
[39m
[23m
[3m
[38;5;246m<dbl>
[39m
[23m
[3m
[38;5;246m<dbl>
[39m
[23m
[3m
[38;5;246m<dbl>
[39m
[23m
[3m
[38;5;246m<dbl>
[39m
[23m
[3m
[38;5;246m<dbl>
[39m
[23m
[3m
[38;5;246m<dbl>
[39m
[23m
[38;5;250m1
[39m Mean Abs. Diff. 0.021
[4m5
[24m 0.002
[4m5
[24m
[4m3
[24m 0.021
[4m3
[24m 0.015
[4m7
[24m 0.036
[4m8
[24m 0.019
[4m9
[24m 0.023
[4m0
[24m
[38;5;250m2
[39m Median Abs. Diff. 0.016
[4m3
[24m 0.002
[4m3
[24m
[4m9
[24m 0.016
[4m4
[24m 0.010
[4m7
[24m 0.025
[4m9
[24m 0.014
[4m6
[24m 0.017
[4m8
[24m
[38;5;250m3
[39m Pearson 0.954 0.010
[4m8
[24m 0.954 0.888 0.978 0.948 0.962
[38;5;250m4
[39m Bray-Curtis 0.096
[4m8
[24m 0.011
[4m4
[24m 0.095
[4m9
[24m 0.070
[4m8
[24m 0.165 0.089
[4m7
[24m 0.104
Comparing the Two Periods
We now compare transition patterns in the Early and Late periods. The project composition is partly overlapping: 17 projects contribute sessions only to Early, 12 only to Late, and five contribute sessions to both. The period comparison therefore includes both differences between sets of projects and differences within projects observed over time. This structure will determine how labels can be reassigned in the permutation test.
The group_tna() function uses the period metadata to
build a separate model for each period. The plots show the resulting
transition networks side by side, using the same display threshold as
the aggregate network. Visual differences provide a starting point for
comparison, but their statistical support requires a test that respects
project membership. As this is a comparison of observed periods, its
substantive interpretation also needs to consider the projects and
activities represented at each time.
group_model <- group_tna(prepared, group = "period")
plot(group_model, minimum = 0.05)

Transition networks of the early and the late sessions
The mosaic plot examines the distribution of codes across periods. Its cell areas represent the observed composition, and the residual shading shows departures from the counts expected if code and period were independent. A positive residual indicates more occurrences than expected under that model, while a negative residual indicates fewer. This concerns how frequently codes occur, which is a different question from how codes follow one another in the transition networks.
In the default plot, the residual calculation treats each code occurrence as an independent observation. Codes within a session, and sessions within a project, can share characteristics, so the apparent strength of an association in this plot needs to be assessed with the nesting taken into account.
plot_mosaic(group_model)
Codes by period, residuals ignoring the nesting
Adding actor = "project" calculates the code-by-period
counts project by project and adjusts the residuals for clustering. Each
residual is divided by the square root of its corresponding design
effect. The observed counts are unchanged, while the residual shading
reflects the additional information about project membership. The
subtitle reports the Rao-Scott test, which adjusts contingency-table
inference for the sampling design (Rao & Scott, 1984).
The difference between the two analyses is substantial. The ordinary Pearson test gives χ²(8) = 56.90, p < .001, whereas the Rao-Scott test gives F(3.37, 111.09) = 1.92, p = .123. The overall reported design effect is 3.70. This summarises the impact of clustering on the test and should be distinguished from the cell-specific design effects used to adjust individual residuals. Under the Rao-Scott analysis, the evidence is insufficient to reject independence of code and period at the .05 level. This result concerns the overall code composition; it does not establish that every transition probability is the same in the two periods.
plot_mosaic(group_model, actor = "project")
Codes by period, residuals respecting the nesting in projects
The mosaic_test() function places the ordinary Pearson
result alongside four approaches that account for clustering or
stratification. The Rao-Scott row corresponds to the adjusted mosaic
plot and uses all 34 projects. The Donner-Klar row contains missing
values because the method requires a variable that is constant within
every actor. Period does not satisfy that requirement here: five
projects contain both Early and Late sessions. This row therefore
indicates that the test is inapplicable to this structure, rather than
reporting a non-significant result.
The Cochran-Mantel-Haenszel (CMH) test asks about association between code and period within projects. It uses the five projects represented in both periods and gives a statistic of 40.19 with eight degrees of freedom and p < .001. This is a conditional comparison within those projects, whereas the Rao-Scott result addresses the overall code-by-period association with clustering taken into account. Their results should be read in relation to these different questions.
The GEE Wald test also gives p < .001, with a statistic of 48.31 and eight degrees of freedom, using all 34 projects. The output notes that its cluster-robust covariance can yield a liberal Wald test unless there are many actors relative to the degrees of freedom. Accordingly, the rows should be interpreted in light of their assumptions and inferential targets. The significant CMH and GEE results do not change the Rao-Scott result displayed with the adjusted mosaic, and the choice of test should follow the research question and data structure.
mosaic_test(group_model, actor = "project") method test statistic df df2 p_value n
1 chisq Pearson 56.9 8.0 NA 0.0000000019 10796
2 rao_scott Rao-Scott 1.9 3.4 111 0.1230481315 10796
3 donner_klar Donner-Klar NA NA NA NA 10796
4 cmh Cochran-Mantel-Haenszel 40.2 8.0 NA 0.0000029513 10796
5 gee GEE Wald 48.3 8.0 NA 0.0000000862 10796
actors design_effect icc
1 NA NA NA
2 34 3.7 NA
3 NA NA NA
4 5 NA NA
5 34 NA NA
note
1 <NA>
2 <NA>
3 Donner-Klar needs one variable that is constant within every actor
4 <NA>
5 Wald test with a cluster-robust covariance; liberal unless the actors are many relative to the degrees of freedom
We next test differences in transition probabilities using permutations. The observed difference for each edge is compared with differences obtained after reassigning period labels and rebuilding the group networks. This creates a reference distribution for assessing how unusual the observed difference is under the permitted reassignments (Good, 2005). The sequential order within each session is preserved throughout.
We again use 1,000 iterations and the same seed for the two analyses.
The first call reassigns sessions freely between periods. The second
specifies actor = "project" and restricts the permutations
to reflect the project structure. Projects observed in only one period
move as whole units. For the five projects observed in both periods,
sessions are shuffled between periods within their own project. These
restrictions define which observations are treated as exchangeable under
the null comparison.
Using the returned edgewise p-values below .05, the unrestricted test identifies 17 transition differences and the restricted test identifies 10. All 10 are among the differences identified by the unrestricted test. For example, Request to Specify changes from p = .014 to p = .119, while Interrupt to Verify remains significant with p approximately .001 under both procedures. The observed group differences are unchanged; their support changes because the reference distributions reflect different assumptions about independence.
The table reports transitions that meet the threshold in either analysis, and the final plot displays the differences retained by the restricted test. These are edgewise results at the displayed threshold. They should be reported with the magnitudes of the differences and the approach to multiple comparisons, rather than interpreting the count of significant edges as a single test of the entire network. An edge that does not meet the threshold has insufficient evidence of a period difference under this procedure; this does not demonstrate equivalence.
perm_naive <- permutation_test(group_model, iter = 1000, seed = 265)
perm_nested <- permutation_test(group_model, iter = 1000, seed = 265, actor = "project")
perm_both <- merge(summary(perm_naive), summary(perm_nested),
by = c("pair", "from", "to"), suffixes = c("_naive", "_nested"))
c(naive = sum(perm_both$p_value_naive < 0.05),
nested = sum(perm_both$p_value_nested < 0.05)) naive nested
17 10
subset(perm_both, (p_value_naive < 0.05) | (p_value_nested < 0.05),
select = c(from, to, diff_true_naive, p_value_naive, p_value_nested)) from to diff_true_naive p_value_naive p_value_nested
5 Command Interrupt -0.03 0.005 0.010
7 Command Request 0.04 0.028 0.047
8 Command Specify -0.08 0.001 0.018
9 Command Verify 0.03 0.002 0.036
14 Correct Interrupt -0.04 0.018 0.122
18 Correct Verify 0.06 0.005 0.048
21 Frustrate Frustrate -0.09 0.003 0.039
27 Frustrate Verify 0.07 0.016 0.073
39 Interrupt Frustrate -0.05 0.023 0.212
45 Interrupt Verify 0.07 0.001 0.001
46 Refine Command -0.04 0.009 0.033
52 Refine Request -0.06 0.027 0.171
60 Request Refine -0.02 0.040 0.032
62 Request Specify 0.08 0.014 0.119
67 Specify Inquire -0.03 0.016 0.062
74 Verify Correct 0.06 0.035 0.080
77 Verify Interrupt -0.04 0.037 0.018
plot(perm_nested)
Significant differences between the periods, respecting the nesting
Reporting
A report should distinguish the sequence unit from the higher sampling unit. For this example, there are 429 session sequences nested within 34 projects, with project contributions ranging from one to 81 sessions. State that each session was ordered using its recorded within-session order and retained as a separate sequence. For the period comparison, report the boundary of 21 February 2026 and the composition of the groups: 17 projects observed only in Early, 12 only in Late, and five in both.
Describe how project membership entered every validation procedure.
All four resampling methods in the nested analysis used
actor with the project identifier: bootstrap samples
contained whole projects, case-dropping removed whole projects,
split-half allocations kept each project together, and permutations
followed the combination of whole-project and within-project
reassignment described above. Report the iteration counts and
random-seed settings, as well as the Rao-Scott adjustment used for the
mosaic. For reproducibility, the code specifies 1,000 iterations for
bootstrap and permutation analyses and 500 for case-dropping and
split-half reliability.
Present the nested analysis as the analysis aligned with the sampling structure, and the session-level analysis as a sensitivity check. Report edge estimates and uncertainty, centrality stability, split-half agreement and the relevant group-comparison statistics. Here, the changes from 45 to 37 bootstrap-supported edges and from 17 to 10 permutation-significant differences show that some conclusions depend on the assumed unit of independence. The comparison is useful because it identifies that sensitivity, while the unchanged point estimates preserve the descriptive account of the observed sequences.
Summary
Nested sequence data require attention to both the boundaries of each sequence and the relationships between sequences. In this tutorial, sessions define the sequences and projects define the higher units used in validation. Preserving those units changes the uncertainty and statistical support attached to the same observed transition networks.
The project-level analyses generally yield wider edge intervals, fewer supported edges and fewer supported period differences, alongside some changes in the opposite direction. Centrality stability and split-half agreement also need to be read under the appropriate sampling structure. For applied researchers, the transferable principle is to make data preparation, resampling and interpretation reflect the design of the study, whether the higher unit is a project, learner, team or class. The resulting claims can then be tied to both the observed sequential patterns and the evidence obtained when their nesting is respected.
How to cite this article
Saqr, M., & López-Pernas, S. (2026). Transition network analysis of nested data with the tna R package: Resampling, permutation, and mosaic tests that respect the nesting. tna. https://doi.org/10.5281/zenodo.24608489 · HTML · PDF
Additional Resources
- Dynalytics — a framework for the rigorous analytics of dynamical systems: the packages, tutorials, papers, and book chapters behind it.
- Package sites and articles — documentation of the R packages of the Dynalytics framework, with their articles and tutorials.
- Nestimate — dynamic, probabilistic, and higher-order network analysis in R (CRAN).
If you prefer a visual interface to writing code, use CarmNote TNA. It runs transition network analysis in a single HTML file that opens in your browser: no installation, no internet connection needed, and your data never leave your computer. It covers network estimation, bootstrap and permutation validation, group comparison, clustering, pattern and process mining, and higher-order Markov models.
Get CarmNote TNA · Website · Documentation · All CarmNotes
Prefer jamovi? JTNA brings TNA to jamovi as a point-and-click module, with its own tutorial.
References
- Bakeman, R., & Gottman, J. M. (1997). Observing interaction: An introduction to sequential analysis (2nd ed.). Cambridge University Press. https://doi.org/10.1017/CBO9780511527685
- Cameron, A. C., Gelbach, J. B., & Miller, D. L. (2008). Bootstrap-based improvements for inference with clustered errors. The Review of Economics and Statistics, 90(3), 414–427. https://doi.org/10.1162/rest.90.3.414
- Davison, A. C., & Hinkley, D. V. (1997). Bootstrap methods and their application. Cambridge University Press. https://doi.org/10.1017/CBO9780511802843
- Efron, B. (1979). Bootstrap methods: Another look at the jackknife. The Annals of Statistics, 7(1), 1–26. https://doi.org/10.1214/aos/1176344552
- Efron, B., & Tibshirani, R. (1986). Bootstrap methods for standard errors, confidence intervals, and other measures of statistical accuracy. Statistical Science, 1(1), 54–75. https://doi.org/10.1214/ss/1177013815
- Efron, B., & Tibshirani, R. J. (1994). An introduction to the bootstrap. Chapman & Hall/CRC. https://doi.org/10.1201/9780429246593
- Epskamp, S., Borsboom, D., & Fried, E. I. (2018). Estimating psychological networks and their accuracy: A tutorial paper. Behavior Research Methods, 50(1), 195–212. https://doi.org/10.3758/s13428-017-0862-1
- Field, C. A., & Welsh, A. H. (2007). Bootstrapping clustered data. Journal of the Royal Statistical Society Series B: Statistical Methodology, 69(3), 369–390. https://doi.org/10.1111/j.1467-9868.2007.00593.x
- Good, P. I. (2005). Permutation, parametric and bootstrap tests of hypotheses (3rd ed.). Springer. https://doi.org/10.1007/b138696
- Helske, J., Helske, S., Saqr, M., López-Pernas, S., & Murphy, K. (2024). A modern approach to transition analysis and process mining with Markov models in education. In M. Saqr & S. López-Pernas (Eds.), Learning analytics methods and tutorials (pp. 381–427). Springer. https://doi.org/10.1007/978-3-031-54464-4_12
- Lambiotte, R., Rosvall, M., & Scholtes, I. (2019). From networks to optimal higher-order models of complex systems. Nature Physics, 15(4), 313–320. https://doi.org/10.1038/s41567-019-0459-y
- Molenaar, I., & Järvelä, S. (2014). Sequential and temporal characteristics of self and socially regulated learning. Metacognition and Learning, 9(2), 75–85. https://doi.org/10.1007/s11409-014-9114-2
- Peeters, W., Saqr, M., & Viberg, O. (2020). Applying learning analytics to map students’ self-regulated learning tactics in an academic writing course. In Proceedings of the 28th International Conference on Computers in Education (ICCE 2020) (pp. 245–254). Asia-Pacific Society for Computers in Education. https://library.apsce.net/index.php/ICCE/article/view/3926
- Rao, J. N. K., & Scott, A. J. (1984). On chi-squared tests for multiway contingency tables with cell proportions estimated from survey data. The Annals of Statistics, 12(1), 46–60. https://doi.org/10.1214/aos/1176346391
- Reimann, P. (2009). Time is precious: Variable- and event-centred approaches to process analysis in CSCL research. International Journal of Computer-Supported Collaborative Learning, 4(3), 239–257. https://doi.org/10.1007/s11412-009-9070-z
- Ren, S., Lai, H., Tong, W., Aminzadeh, M., Hou, X., & Lai, S. (2010). Nonparametric bootstrapping for hierarchical data. Journal of Applied Statistics, 37(9), 1487–1498. https://doi.org/10.1080/02664760903046102
- Rosvall, M., Esquivel, A. V., Lancichinetti, A., West, J. D., & Lambiotte, R. (2014). Memory in network flows and its effects on spreading dynamics and community detection. Nature Communications, 5, 4630. https://doi.org/10.1038/ncomms5630
- Saqr, M. (2026). Coded turns of human-AI vibe coding sessions [Data set]. Zenodo. https://doi.org/10.5281/zenodo.24528524
- Saqr, M., & López-Pernas, S. (2023). The temporal dynamics of online problem-based learning: Why and when sequence matters. International Journal of Computer-Supported Collaborative Learning, 18(1), 11–37. https://doi.org/10.1007/s11412-023-09385-1
- Saqr, M., López-Pernas, S., & Misiejuk, K. (2026). Dynalytics: The birth of a framework for rigorous analytics of dynamical systems [Preprint]. SSRN. https://doi.org/10.2139/ssrn.6832584
- Saqr, M., López-Pernas, S., & Tikka, S. (2025). Mapping relational dynamics with transition network analysis: A primer and tutorial. In M. Saqr & S. López-Pernas (Eds.), Advanced learning analytics methods: AI, precision and complexity. Springer. https://lamethods.org/book2/chapters/ch15-tna/ch15-tna.html
- Saqr, M., López-Pernas, S., Törmänen, T., Kaliisa, R., Misiejuk, K., & Tikka, S. (2025). Transition network analysis: A novel framework for modeling, visualizing, and identifying the temporal patterns of learners and learning processes. In Proceedings of the 15th International Learning Analytics and Knowledge Conference (LAK ’25) (pp. 351–361). ACM. https://doi.org/10.1145/3706468.3706513
- Saqr, M., Nouri, J., & Fors, U. (2019). Time to focus on the temporal dimension of learning: A learning analytics study of the temporal patterns of students’ interactions and self-regulation. International Journal of Technology Enhanced Learning, 11(4), 398–412. https://doi.org/10.1504/IJTEL.2019.102549
- Scholtes, I. (2017). When is a network a network? Multi-order graphical model selection in pathways and temporal networks. In Proceedings of the 23rd ACM SIGKDD International Conference on Knowledge Discovery and Data Mining (pp. 1037–1046). ACM. https://doi.org/10.1145/3097983.3098145
- Tikka, S., López-Pernas, S., & Saqr, M. (2025). tna: An R package for transition network analysis. Applied Psychological Measurement, 49(6), 326–328. https://doi.org/10.1177/01466216251348840