Network Estimation and Analysis with Nestimate

Nestimate is a unified framework for estimating, validating, and comparing networks from sequential and cross-sectional data. It implements two complementary paradigms: Transition Network Analysis (TNA), which models the relational dynamics of temporal processes as weighted directed networks using stochastic Markov models; and Psychological Network Analysis (PNA), which estimates the conditional dependency structure among variables using regularized partial correlations and graphical models. Both paradigms share the same build_network() interface, the same validation engine (bootstrap, permutation, centrality stability), and the same output format — enabling researchers to apply a consistent analytic workflow across fundamentally different data types.

This vignette demonstrates both paradigms, covering network estimation, statistical validation, data-driven clustering, and group comparison.

Part I: Transition Network Analysis

Theoretical Grounding

TNA uses stochastic process modeling to capture the dynamics of temporal processes, namely Markov models. Markov models align with the view that a temporal process is an outcome of a stochastic data generating process that produces various network configurations or patterns based on rules, constraints, or guiding principles. The transitions are governed by a stochastic process: the specific ways in which the system changes or evolves is rather random and therefore can’t be strictly determined. That is, the transitions are probabilistically dependent on preceding states — a method that assumes events are probabilistically dependent on the preceding ones like Markov models.

The main principle of TNA is representing the transition matrix between events as a graph to take full advantage of graph theory potentials and the wealth of network analysis. TNA brings network measures at the node, edge, and graph level; pattern mining through dyads, triads, and communities; clustering of sub-networks into typical behavioral strategies; and rigorous statistical validation at each edge through bootstrapping, permutation, and case-dropping techniques. Such statistical rigor that brings validation and hypothesis testing at each step of the analysis offers a method for researchers to build, verify, and advance existing theories on the basis of a robust scientific approach.

Data

The human_cat dataset contains 10,796 coded human interactions from 429 human-AI pair programming sessions across 34 projects, classified into 9 behavioral categories. Each row represents a single interaction event — the kind of data typically exported from log files, coded interaction data, or learning management systems.

library(Nestimate)

# Subsample for vignette speed (CRAN build-time limit)
set.seed(1)
keep <- sample(unique(human_cat$session_id), 100)
human_sub <- human_cat[human_cat$session_id %in% keep, ]

head(human_sub)

The dataset is in long format with columns recording what happened (category), who did it (session_id), and when (timestamp). Additional columns like project, code, and superclass are automatically preserved as metadata and can be used later for group comparisons or covariate analysis without manual data wrangling.

Building Networks

Building networks in Nestimate is a single step: the build_network() function is the universal entry point for all network estimation. It accepts long-format event data directly with three key parameters:

Under the hood, build_network() calls prepare_data() to convert the long-format event log into wide-format sequences, automatically handling chronological ordering, session detection, and metadata preservation.

Transition Network (TNA)

The standard TNA method estimates a first-order Markov model from sequence data. Given a sequence of events, the transition probability \(P(v_j | v_i)\) is estimated as the ratio of observed transitions from state \(v_i\) to state \(v_j\) to the total number of outgoing transitions from \(v_i\). These estimated probabilities are assembled into a transition matrix \(T\), where each element \(T_{ij}\) represents the estimated probability of transitioning from \(v_i\) to \(v_j\). The resulting directed weighted network captures the probabilistic dependencies between events — the contingencies that shape the temporal process.

net_tna <- build_network(human_sub, method = "tna",
                         action = "category", actor = "session_id",
                         time = "timestamp")
print(net_tna)
#> Transition Network (relative probabilities) [directed]
#>   Weights: [0.016, 0.618]  |  mean: 0.108
#> 
#>   Weight matrix:
#>             Command Correct Frustrate Inquire Interrupt Refine Request Specify
#>   Command     0.190   0.095     0.038   0.051     0.033  0.046   0.164   0.321
#>   Correct     0.085   0.111     0.138   0.048     0.053  0.116   0.116   0.302
#>   Frustrate   0.068   0.168     0.194   0.079     0.016  0.215   0.105   0.120
#>   Inquire     0.148   0.178     0.154   0.166     0.071  0.047   0.095   0.101
#>   Interrupt   0.266   0.070     0.063   0.175     0.175  0.035   0.070   0.098
#>   Refine      0.038   0.095     0.089   0.057     0.044  0.095   0.120   0.424
#>   Request     0.090   0.020     0.060   0.060     0.040  0.035   0.035   0.618
#>   Specify     0.290   0.070     0.076   0.055     0.183  0.055   0.059   0.171
#>   Verify      0.195   0.092     0.115   0.115     0.034  0.161   0.092   0.115
#>             Verify
#>   Command    0.062
#>   Correct    0.032
#>   Frustrate  0.037
#>   Inquire    0.041
#>   Interrupt  0.049
#>   Refine     0.038
#>   Request    0.040
#>   Specify    0.040
#>   Verify     0.080 
#> 
#>   Initial probabilities:
#>   Command       0.285  ████████████████████████████████████████
#>   Specify       0.277  ███████████████████████████████████████
#>   Inquire       0.124  █████████████████
#>   Interrupt     0.086  ████████████
#>   Request       0.072  ██████████
#>   Frustrate     0.058  ████████
#>   Verify        0.037  █████
#>   Correct       0.035  █████
#>   Refine        0.026  ████

Frequency Network (FTNA)

The frequency method preserves raw transition counts rather than normalizing to conditional probabilities. This is useful when absolute frequencies matter — for instance, a transition that occurs 500 times from a common state may be more practically important than one occurring 5 times from a rare state, even if the latter has a higher conditional probability. Frequency networks retain the magnitude of evidence for each transition, which is lost in the normalization step.

net_ftna <- build_network(human_sub, method = "ftna",
                          action = "category", actor = "session_id",
                          time = "timestamp")
print(net_ftna)
#> Transition Network (frequency counts) [directed]
#>   Weights: [3.000, 152.000]  |  mean: 24.264
#> 
#>   Weight matrix:
#>             Command Correct Frustrate Inquire Interrupt Refine Request Specify
#>   Command        74      37        15      20        13     18      64     125
#>   Correct        16      21        26       9        10     22      22      57
#>   Frustrate      13      32        37      15         3     41      20      23
#>   Inquire        25      30        26      28        12      8      16      17
#>   Interrupt      38      10         9      25        25      5      10      14
#>   Refine          6      15        14       9         7     15      19      67
#>   Request        18       4        12      12         8      7       7     123
#>   Specify       152      37        40      29        96     29      31      90
#>   Verify         17       8        10      10         3     14       8      10
#>             Verify
#>   Command       24
#>   Correct        6
#>   Frustrate      7
#>   Inquire        7
#>   Interrupt      7
#>   Refine         6
#>   Request        8
#>   Specify       21
#>   Verify         7 
#> 
#>   Initial probabilities:
#>   Command       0.285  ████████████████████████████████████████
#>   Specify       0.277  ███████████████████████████████████████
#>   Inquire       0.124  █████████████████
#>   Interrupt     0.086  ████████████
#>   Request       0.072  ██████████
#>   Frustrate     0.058  ████████
#>   Verify        0.037  █████
#>   Correct       0.035  █████
#>   Refine        0.026  ████

Attention Network (ATNA)

The attention method applies temporal decay weighting, giving more importance to recent transitions within each sequence. The lambda parameter controls the decay rate: higher values produce faster decay. This captures the idea that later events in a process may be more indicative of the underlying dynamics than early ones — for example, in learning settings where initial exploration gives way to more purposeful regulatory behavior.

net_atna <- build_network(human_sub, method = "atna",
                          action = "category", actor = "session_id",
                          time = "timestamp")
print(net_atna)
#> Attention Network (decay-weighted transitions) [directed]
#>   Weights: [1.618, 67.769]  |  mean: 12.823
#> 
#>   Weight matrix:
#>             Command Correct Frustrate Inquire Interrupt Refine Request Specify
#>   Command    39.286  19.628     9.970  11.136    12.841 10.308  28.485  64.700
#>   Correct    10.807  12.940    13.081   6.480     5.724 12.129  10.195  28.924
#>   Frustrate   8.540  15.364    19.758   8.491     2.505 18.919  10.327  17.227
#>   Inquire    12.897  16.355    13.144  13.651     6.631  4.453   8.490  13.084
#>   Interrupt  17.757   4.939     4.374  11.229    15.604  2.886   4.753  10.214
#>   Refine      5.783   9.262     9.188   4.667     3.627 10.121   9.701  31.823
#>   Request    10.640   3.665     7.111   6.880     8.700  5.497   5.107  51.864
#>   Specify    67.769  19.713    22.507  16.891    40.493 17.207  23.893  59.857
#>   Verify      8.492   4.208     5.077   4.885     1.618  6.830   4.724   8.135
#>             Verify
#>   Command   12.114
#>   Correct    3.205
#>   Frustrate  3.479
#>   Inquire    3.547
#>   Interrupt  3.208
#>   Refine     3.133
#>   Request    4.791
#>   Specify   11.922
#>   Verify     3.348 
#> 
#>   Initial probabilities:
#>   Command       0.285  ████████████████████████████████████████
#>   Specify       0.277  ███████████████████████████████████████
#>   Inquire       0.124  █████████████████
#>   Interrupt     0.086  ████████████
#>   Request       0.072  ██████████
#>   Frustrate     0.058  ████████
#>   Verify        0.037  █████
#>   Correct       0.035  █████
#>   Refine        0.026  ████

Co-occurrence Network from Binary Data

When the data is binary (0/1) — as is common in learning analytics where multiple activities are coded as present or absent within time windows — build_network() automatically detects the format and uses co-occurrence analysis to model how codes are associated with each other. The resulting undirected network captures which events tend to co-occur, complementing the temporal sequencing captured by TNA.

data(learning_activities)
net <- build_network(learning_activities, method = "cna", actor = "student")
print(net)
#> Co-occurrence Network [undirected]
#>   Weights: [2681.000, 3290.000]  |  mean: 3047.333
#> 
#>   Weight matrix:
#>           Reading Video Forum Quiz Coding Review
#>   Reading    6100  3169  3211 2891   3138   3113
#>   Video      3169  6262  3183 2903   3278   3290
#>   Forum      3211  3183  5692 2942   2958   3045
#>   Quiz       2891  2903  2942 5379   2681   2725
#>   Coding     3138  3278  2958 2681   5886   3183
#>   Review     3113  3290  3045 2725   3183   6186

Window-based TNA (WTNA)

The wtna() function provides an alternative approach for computing networks from one-hot encoded (binary) data, using temporal windowing. This is useful when multiple states can be active simultaneously within a time window. WTNA supports three modes:

  • "transition": directed transitions between consecutive windows
  • "cooccurrence": undirected co-occurrence within windows
  • "both": a mixed network combining transitions and co-occurrences

Since states can co-occur within the same window and follow each other from one window to the next, a mixed network captures both relationships simultaneously — modeling the events that co-occur together and those that transition, which neither a purely directed nor a purely undirected network can represent alone.

net_wtna <- wtna(learning_activities, actor = "student",
                 method = "transition", type = "frequency")
print(net_wtna)
#> Network (method: wtna_transition) [directed]
#>   Weights: [877.000, 1094.000]  |  mean: 995.233
#> 
#>   Weight matrix:
#>           Reading Video Forum Quiz Coding Review
#>   Reading    1797  1006  1047  955   1036   1021
#>   Video      1054  1861  1054  972   1058   1043
#>   Forum      1043  1021  1672  943    956   1004
#>   Quiz        935   951   955 1584    877    894
#>   Coding     1008  1074   967  886   1737   1048
#>   Review     1033  1094   985  908   1029   1822 
#> 
#>   Initial probabilities:
#>   Reading       0.209  ████████████████████████████████████████
#>   Coding        0.194  █████████████████████████████████████
#>   Video         0.179  ██████████████████████████████████
#>   Review        0.151  █████████████████████████████
#>   Quiz          0.141  ███████████████████████████
#>   Forum         0.126  ████████████████████████
net_wtna_rel <- wtna(learning_activities, method = "transition", type = "relative")
print(net_wtna_rel)
#> Network (method: wtna_transition) [directed]
#>   Weights: [0.132, 0.159]  |  mean: 0.148
#> 
#>   Weight matrix:
#>           Reading Video Forum  Quiz Coding Review
#>   Reading   0.260 0.147 0.152 0.139  0.153  0.149
#>   Video     0.151 0.263 0.149 0.138  0.152  0.148
#>   Forum     0.158 0.154 0.249 0.142  0.146  0.150
#>   Quiz      0.152 0.153 0.154 0.253  0.142  0.146
#>   Coding    0.151 0.159 0.144 0.132  0.258  0.156
#>   Review    0.151 0.159 0.143 0.133  0.151  0.263 
#> 
#>   Initial probabilities:
#>   Reading       0.500  ████████████████████████████████████████
#>   Quiz          0.500  ████████████████████████████████████████
#>   Video         0.000  
#>   Forum         0.000  
#>   Coding        0.000  
#>   Review        0.000

Mixed network (transitions + co-occurrences)

Since states can co-occur within the same window and follow each other from one window to the next, a mixed network captures both relationships simultaneously.

net_wtna_mixed <- wtna(learning_activities, method = "both", type = "relative")
print(net_wtna_mixed)
#> Mixed Window TNA (transition + co-occurrence)
#> -- Transition (directed) --
#>   Nodes: 6  |  Edges: 30
#> -- Co-occurrence (undirected) --
#>   Nodes: 6  |  Edges: 15

Validation

Most research on networks or process mining uses descriptive methods. The validation or the statistical significance of such models are almost absent in the literature. Having validated models allows us to assess the robustness and reproducibility of our models to ensure that the insights we get are not merely a product of chance and are therefore generalizable. TNA offers rigorous validation and hypothesis testing at each step of the analysis.

Reliability

Split-half reliability assesses whether the network structure is stable when the data is randomly divided into two halves. High reliability means the network structure is a consistent property of the data, not driven by a small number of idiosyncratic sequences.

reliability(net_tna)
#> Split-Half Reliability (1000 iterations, split = 50%)
#>   Mean Abs. Dev.      mean = 0.0373  sd = 0.0038
#>   Median Abs. Dev.    mean = 0.0275  sd = 0.0038
#>   Correlation         mean = 0.8660  sd = 0.0290
#>   Max Abs. Dev.       mean = 0.1785  sd = 0.0450

Bootstrap Analysis

Bootstrapping is a re-sampling technique that entails repeatedly — usually hundreds, if not thousands of times — drawing samples from the original dataset with replacement to estimate the model for each of these samples. When edges consistently appear across the majority of the estimated models, they are considered stable and significant. In doing so, bootstrapping helps effectively filter out small, negligible, or spurious edges resulting in a stable model and valid model. The bootstrap also provides confidence intervals and p-values for each edge weight, offering a quantifiable measure of uncertainty and robustness for each transition in the network.

set.seed(42)
boot <- bootstrap_network(net_tna, iter = 100)
boot
#>   Edge                   Mean     95% CI          p
#>   -----------------------------------------------
#>   Request → Specify    0.627  [0.560, 0.707]  ** 
#>   Refine → Specify     0.422  [0.337, 0.510]  *  
#>   Command → Specify    0.324  [0.268, 0.369]  ** 
#>   Correct → Specify    0.297  [0.229, 0.357]  *  
#>   Specify → Command    0.293  [0.257, 0.337]  ** 
#>   ... and 4 more significant edges
#> 
#> Bootstrap Network  [Transition Network (relative) | directed]
#>   Iterations : 100  |  Nodes : 9
#>   Edges      : 7 significant / 72 total
#>   CI         : 95%  |  Inference: stability  |  CR [0.75, 1.25]

Centrality Stability

Centrality measures provide a quantification of the role or importance of a state or an event in the process. However, the robustness of these rankings must be verified. Centrality stability analysis quantifies how robust centrality rankings are to case-dropping: the CS-coefficient is the maximum proportion of cases that can be dropped while maintaining a correlation of at least 0.7 with the original centrality values. A CS-coefficient above 0.5 indicates stable centrality rankings; below 0.25 indicates instability and the centrality ranking should not be interpreted.

centrality_stability(net_tna, iter = 100)
#> Centrality Stability (100 iterations, threshold = 0.7)
#>   Drop proportions: 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9
#> 
#>   CS-coefficients:
#>     InStrength       0.90
#>     OutStrength      0.40
#>     Betweenness      0.70

Clustering

Clusters represent typical transition networks that recur across different instances. Unlike communities, clusters involve the entire network where groups of sequences are similarly interconnected and each exhibit a distinct transition pattern with its own set of transition probabilities. Identifying clusters captures the dynamics, revealing typical relations that learners frequently adopt as units across different instances. cluster_data() computes pairwise dissimilarities between sequences and partitions them into k groups, then builds a separate network for each cluster.

Cls <- cluster_data(net_tna, k = 3)
Clusters <- build_network(Cls, method = "tna")
Clusters
#> Group Networks (3 groups)
#>   Cluster 1: 9 nodes, 69 edges
#>   Cluster 2: 9 nodes, 70 edges
#>   Cluster 3: 9 nodes, 64 edges

Centrality

The centrality() function computes centrality measures for each cluster network. For directed networks, the defaults are InStrength (the sum of incoming transition probabilities — how central a state is as a destination), OutStrength (the sum of outgoing transition probabilities), and Betweenness (how often a state bridges transitions between other states).

Nestimate::centrality(Clusters)
#> $`Cluster 1`
#>           InStrength OutStrength Betweenness
#> Command    1.0032974   0.8333333  0.35714286
#> Correct    0.8241398   0.9629630  0.14285714
#> Frustrate  0.6223616   0.8000000  0.07142857
#> Inquire    0.3980134   0.8333333  0.07142857
#> Interrupt  0.5333948   0.7049180  0.71428571
#> Refine     0.7438466   0.8703704  0.64285714
#> Request    1.2179623   0.9670330  0.35714286
#> Specify    1.9852848   0.8397790  1.64285714
#> Verify     0.2982442   0.8148148  0.07142857
#> 
#> $`Cluster 2`
#>           InStrength OutStrength Betweenness
#> Command    1.2480754   0.8100000  0.42857143
#> Correct    0.8903853   0.8559322  0.07142857
#> Frustrate  0.8460361   0.8468468  0.42857143
#> Inquire    0.8472279   0.8415842  0.35714286
#> Interrupt  0.3237684   0.9545455  0.00000000
#> Refine     0.6941852   0.9230769  0.14285714
#> Request    0.7677513   0.9666667  0.07142857
#> Specify    1.9570691   0.7750000  1.07142857
#> Verify     0.3574870   0.9583333  0.00000000
#> 
#> $`Cluster 3`
#>           InStrength OutStrength Betweenness
#> Command    1.2101759   0.7840909   0.2142857
#> Correct    0.4237366   0.8823529   0.0000000
#> Frustrate  0.6601482   0.6666667   0.1428571
#> Inquire    0.5686020   0.8125000   0.8571429
#> Interrupt  0.6187306   0.8684211   1.3571429
#> Refine     0.7281452   0.9230769   0.2142857
#> Request    0.4261307   0.9444444   0.0000000
#> Specify    2.8730356   0.8888889   1.7142857
#> Verify     0.2617371   1.0000000   0.0000000

Permutation Test for Clusters

TNA offers a rigorous systematic method for process comparison based on permutation. Permutation testing is particularly important for data-driven clusters: because clustering algorithms partition sequences to maximize between-group separation, some degree of apparent difference is guaranteed by construction. The permutation test provides the necessary corrective — by randomly reassigning sequences to groups while preserving internal sequential structure, it constructs null distributions for edge-level differences. Only differences that exceed this null distribution constitute evidence of genuine structural divergence rather than algorithmic artifacts.

perm <- permutation_test(Clusters$`Cluster 1`, Clusters$`Cluster 2`,
                         iter = 100)
perm
#> Permutation Test:Transition Network (relative probabilities) [directed]
#>   Iterations: 100  |  Alpha: 0.05
#>   Nodes: 9  |  Edges tested: 81  |  Significant: 8

Mixed Markov Models

Mixed Markov Models (MMM) provide an alternative clustering approach that uses an EM algorithm to discover latent subgroups with distinct transition dynamics. Unlike cluster_data(), which clusters based on sequence dissimilarity, MMM directly models the transition probabilities within each component and assigns sequences probabilistically through soft assignments. The covariates argument integrates external variables into the EM algorithm, allowing mixing proportions to depend on observed characteristics.

data("group_regulation_long")

net_GR <- build_network(group_regulation_long, method = "tna",
                        action = "Action", actor = "Actor",
                        time = "Time")

mmmCls <- build_mmm(net_GR, k = 2, covariates = c("Group"))
summary(mmmCls)
#> Mixed Markov Model
#>   k = 2 | 2000 sequences | 9 states
#>   LL = -45975.1 | BIC = 93181.5 | ICL = 93188.1
#> 
#>   Cluster  Size  Mix%%   AvePP
#>   ------------------------------
#>         1  1001  50.1%  0.999
#>         2   999  49.9%  0.999
#> 
#>   Overall AvePP = 0.999 | Entropy = 0.005 | Class.Err = 0.0%
#>   Covariates:    Group (integrated, 1 predictors)
#> 
#> --- Cluster 1 (50.1%, n=1001) ---
#>            adapt cohesion consensus coregulate discuss emotion monitor  plan
#> adapt      0.000    0.278     0.460      0.030   0.070   0.111   0.035 0.016
#> cohesion   0.000    0.007     0.448      0.166   0.084   0.113   0.053 0.129
#> consensus  0.005    0.009     0.080      0.207   0.136   0.062   0.060 0.432
#> coregulate 0.011    0.036     0.156      0.032   0.305   0.146   0.078 0.217
#> discuss    0.120    0.033     0.214      0.096   0.222   0.099   0.028 0.011
#> emotion    0.002    0.325     0.301      0.047   0.078   0.095   0.042 0.111
#> monitor    0.011    0.061     0.159      0.064   0.381   0.086   0.018 0.207
#> plan       0.001    0.019     0.287      0.011   0.075   0.116   0.076 0.416
#> synthesis  0.302    0.037     0.387      0.067   0.088   0.075   0.021 0.023
#>            synthesis
#> adapt          0.000
#> cohesion       0.000
#> consensus      0.007
#> coregulate     0.019
#> discuss        0.176
#> emotion        0.000
#> monitor        0.014
#> plan           0.000
#> synthesis      0.000
#> 
#> --- Cluster 2 (49.9%, n=999) ---
#>            adapt cohesion consensus coregulate discuss emotion monitor  plan
#> adapt      0.000    0.260     0.523      0.000   0.030   0.143   0.029 0.014
#> cohesion   0.005    0.044     0.538      0.082   0.040   0.118   0.017 0.151
#> consensus  0.004    0.020     0.083      0.171   0.233   0.082   0.035 0.364
#> coregulate 0.022    0.036     0.109      0.013   0.235   0.203   0.096 0.266
#> discuss    0.024    0.062     0.426      0.073   0.168   0.112   0.017 0.013
#> emotion    0.003    0.326     0.337      0.023   0.122   0.062   0.032 0.091
#> monitor    0.011    0.049     0.160      0.051   0.369   0.097   0.019 0.226
#> plan       0.001    0.032     0.294      0.024   0.060   0.182   0.075 0.327
#> synthesis  0.144    0.029     0.573      0.015   0.029   0.065   0.000 0.146
#>            synthesis
#> adapt          0.000
#> cohesion       0.006
#> consensus      0.008
#> coregulate     0.019
#> discuss        0.106
#> emotion        0.005
#> monitor        0.019
#> plan           0.003
#> synthesis      0.000
#> 
#> Covariate Analysis (integrated into EM -- influences cluster membership) 
#> 
#> Cluster Profiles (numeric):
#>  Cluster N (%)      Group Mean (SD) Group Median
#>  1       1001 (50%) 150.45 (28.91)  150.00      
#>  2       999 (50%)  50.45 (28.85)   50.00       
#> 
#> Predictors of Membership (reference: Cluster 1):
#>  Cluster Variable OR   95% CI       p      Sig
#>  2       Group    0.15 [0.15, 0.15] <0.001 ***
#> 
#> Model: AIC = 25.3 | BIC = 36.5 | McFadden R-squared = 0.99

Building networks from the MMM result produces one network per discovered cluster:

Mnets <- build_network(mmmCls)
Mnets
#> Group Networks (2 groups)
#>   Cluster 1: 9 nodes, 72 edges
#>   Cluster 2: 9 nodes, 72 edges

Post-hoc Covariate Analysis

cluster_data() supports post-hoc covariate analysis: covariates do not influence the clustering but are analyzed after the fact to characterize who ends up in which cluster. This is the appropriate approach when the clustering should reflect behavioral patterns alone, and the researcher then asks whether those patterns are associated with external variables.

Post <- cluster_data(net_GR, k = 2, covariates = c("Achiever"))
summary(Post)
#> Sequence Clustering Summary
#>   Method:        pam 
#>   Dissimilarity: hamming 
#>   Silhouette:    0.1839 
#> 
#> Per-cluster statistics:
#>  cluster size mean_within_dist
#>        1  982         10.69340
#>        2 1018         18.59498
#> 
#> Post-hoc Covariate Analysis (does not influence cluster membership) 
#> 
#> Cluster Profiles (categorical):
#>  Cluster N    Achiever=High N(%) Achiever=Low N(%)
#>  1        982 504 (51%)          478 (49%)        
#>  2       1018 496 (49%)          522 (51%)        
#> 
#> Predictors of Membership (reference: Cluster 1):
#>  Cluster Variable    OR   95% CI       p     Sig
#>  2       AchieverLow 1.11 [0.93, 1.32] 0.245    
#> 
#> Model: AIC = 2774.6 | BIC = 2785.8 | McFadden R-squared = 0.00
#> 
#> Note: Covariates are post-hoc and do not influence cluster assignments.
Postgr <- build_network(Post)
Postgr
#> Group Networks (2 groups)
#>   Cluster 1: 9 nodes, 71 edges
#>   Cluster 2: 9 nodes, 71 edges

Part II: Psychological Network Analysis

Theoretical Grounding

Probabilistic processes are commonly — and indeed best — represented mathematically as matrices, where rows represent nodes and columns denote direct probabilistic interactions between them. Several probabilistic network disciplines have recently become popular, most notably psychological networks, which estimate the conditional dependency structure among a set of variables. In psychological network analysis, variables (e.g., symptoms, traits, behaviors) are represented as nodes, and edges represent partial correlations — the association between two variables after controlling for all others. This approach reveals which variables are directly connected versus those whose association is mediated through other variables.

Nestimate supports three estimation methods for psychological networks, all accessed through the same build_network() interface.

Data

The srl_strategies dataset contains frequency counts of 9 self-regulated learning strategies for 250 students, falling into three clusters: metacognitive (Planning, Monitoring, Evaluating), cognitive (Elaboration, Organization, Rehearsal), and resource management (Help_Seeking, Time_Mgmt, Effort_Reg).

data(srl_strategies)
head(srl_strategies)

Correlation Network

The simplest approach estimates pairwise Pearson correlations. This produces a fully connected undirected network where every pair of variables has an edge. While informative as a starting point, correlation networks do not distinguish direct from indirect associations.

net_cor <- build_network(srl_strategies, method = "cor")
net_cor
#> Correlation Network [undirected]
#>   Sample size: 250
#>   Weights: [-0.130, 0.485]  |  +26 / -10 edges
#> 
#>   Weight matrix:
#>                Planning Monitoring Evaluating Elaboration Organization Rehearsal
#>   Planning        0.000      0.423      0.358      -0.096       -0.083    -0.019
#>   Monitoring      0.423      0.000      0.485       0.195        0.028     0.132
#>   Evaluating      0.358      0.485      0.000       0.077        0.313     0.076
#>   Elaboration    -0.096      0.195      0.077       0.000        0.432     0.341
#>   Organization   -0.083      0.028      0.313       0.432        0.000     0.339
#>   Rehearsal      -0.019      0.132      0.076       0.341        0.339     0.000
#>   Help_Seeking   -0.108     -0.116      0.023       0.008        0.123    -0.130
#>   Time_Mgmt       0.285      0.015      0.079      -0.033        0.085    -0.106
#>   Effort_Reg     -0.010     -0.008      0.250       0.050        0.135     0.029
#>                Help_Seeking Time_Mgmt Effort_Reg
#>   Planning           -0.108     0.285     -0.010
#>   Monitoring         -0.116     0.015     -0.008
#>   Evaluating          0.023     0.079      0.250
#>   Elaboration         0.008    -0.033      0.050
#>   Organization        0.123     0.085      0.135
#>   Rehearsal          -0.130    -0.106      0.029
#>   Help_Seeking        0.000     0.209      0.176
#>   Time_Mgmt           0.209     0.000      0.467
#>   Effort_Reg          0.176     0.467      0.000

Partial Correlation Network

Partial correlations control for all other variables, revealing direct associations only. If two variables are correlated solely because they share a common cause, their partial correlation will be near zero. This provides a more accurate picture of the dependency structure than zero-order correlations, though the resulting network can still be noisy in small samples.

net_pcor <- build_network(srl_strategies, method = "pcor")
net_pcor
#> Partial Correlation Network (unregularised) [undirected]
#>   Sample size: 250
#>   Weights: [-0.235, 0.502]  |  +21 / -15 edges
#> 
#>   Weight matrix:
#>                Planning Monitoring Evaluating Elaboration Organization Rehearsal
#>   Planning        0.000      0.268      0.283      -0.103       -0.146     0.046
#>   Monitoring      0.268      0.000      0.432       0.274       -0.213     0.095
#>   Evaluating      0.283      0.432      0.000      -0.156        0.406    -0.098
#>   Elaboration    -0.103      0.274     -0.156       0.000        0.380     0.181
#>   Organization   -0.146     -0.213      0.406       0.380        0.000     0.274
#>   Rehearsal       0.046      0.095     -0.098       0.181        0.274     0.000
#>   Help_Seeking   -0.121     -0.054      0.039       0.004        0.102    -0.144
#>   Time_Mgmt       0.397     -0.007     -0.207      -0.031        0.158    -0.137
#>   Effort_Reg     -0.235     -0.099      0.330       0.049       -0.092     0.096
#>                Help_Seeking Time_Mgmt Effort_Reg
#>   Planning           -0.121     0.397     -0.235
#>   Monitoring         -0.054    -0.007     -0.099
#>   Evaluating          0.039    -0.207      0.330
#>   Elaboration         0.004    -0.031      0.049
#>   Organization        0.102     0.158     -0.092
#>   Rehearsal          -0.144    -0.137      0.096
#>   Help_Seeking        0.000     0.161      0.051
#>   Time_Mgmt           0.161     0.000      0.502
#>   Effort_Reg          0.051     0.502      0.000

Regularized Network (EBICglasso)

The graphical lasso applies L1 regularization to the precision matrix (the inverse of the covariance matrix), producing a sparse network where weak or unreliable edges are shrunk to exactly zero. The gamma parameter controls sparsity through EBIC model selection — higher values yield sparser networks. This is the recommended approach for psychological network analysis, as it balances model fit against complexity and produces interpretable, replicable network structures.

net_glasso <- build_network(srl_strategies, method = "glasso",
                            params = list(gamma = 0.5))
net_glasso
#> Partial Correlation Network (EBICglasso) [undirected]
#>   Sample size: 250
#>   Weights: [0.089, 0.413]  |  +13 / -0 edges
#> 
#>   Weight matrix:
#>                Planning Monitoring Evaluating Elaboration Organization Rehearsal
#>   Planning        0.000      0.295      0.161       0.000        0.000     0.000
#>   Monitoring      0.295      0.000      0.361       0.105        0.000     0.000
#>   Evaluating      0.161      0.361      0.000       0.000        0.221     0.000
#>   Elaboration     0.000      0.105      0.000       0.000        0.329     0.228
#>   Organization    0.000      0.000      0.221       0.329        0.000     0.218
#>   Rehearsal       0.000      0.000      0.000       0.228        0.218     0.000
#>   Help_Seeking    0.000      0.000      0.000       0.000        0.000     0.000
#>   Time_Mgmt       0.205      0.000      0.000       0.000        0.000     0.000
#>   Effort_Reg      0.000      0.000      0.161       0.000        0.000     0.000
#>                Help_Seeking Time_Mgmt Effort_Reg
#>   Planning            0.000     0.205      0.000
#>   Monitoring          0.000     0.000      0.000
#>   Evaluating          0.000     0.000      0.161
#>   Elaboration         0.000     0.000      0.000
#>   Organization        0.000     0.000      0.000
#>   Rehearsal           0.000     0.000      0.000
#>   Help_Seeking        0.000     0.141      0.089
#>   Time_Mgmt           0.141     0.000      0.413
#>   Effort_Reg          0.089     0.413      0.000 
#> 
#>   Gamma: 0.50  |  Lambda: 0.1319

Predictability

Node predictability measures how well each node is predicted by its neighbors (R-squared from the network structure). High predictability indicates that a node’s variance is largely explained by its direct connections in the network; low predictability suggests the node is driven by factors outside the estimated network.

pred <- predictability(net_glasso)
round(pred, 3)
#>     Planning   Monitoring   Evaluating  Elaboration Organization    Rehearsal 
#>        0.251        0.316        0.332        0.241        0.279        0.161 
#> Help_Seeking    Time_Mgmt   Effort_Reg 
#>        0.051        0.274        0.252

Bootstrap Inference

Non-parametric bootstrap assesses edge stability, centrality stability, and provides significance tests for edge and centrality differences. The boot_glasso() function is specialized for graphical lasso networks, providing edge inclusion frequencies, confidence intervals, CS-coefficients, and pairwise difference tests in a single call.

boot_gl <- boot_glasso(net_glasso, iter = 100,
                       centrality = c("strength", "expected_influence"),
                       seed = 42)

Edge Significance

summary(boot_gl, type = "edges")

Centrality Stability

summary(boot_gl, type = "centrality")
#> $strength
#>           node      value   ci_lower  ci_upper
#> 1     Planning 0.48890448 0.37476117 1.5043481
#> 2   Monitoring 0.56833754 0.47147750 1.3200063
#> 3   Evaluating 0.67756154 0.55524956 1.6594405
#> 4  Elaboration 0.45874500 0.32637547 1.1827810
#> 5 Organization 0.56908428 0.46301831 1.5629458
#> 6    Rehearsal 0.30993044 0.25585130 0.9233126
#> 7 Help_Seeking 0.08468196 0.04323831 0.8343392
#> 8    Time_Mgmt 0.52038228 0.36990833 1.4011174
#> 9   Effort_Reg 0.43757251 0.28061194 1.1406496
#> 
#> $expected_influence
#>           node      value   ci_lower  ci_upper
#> 1     Planning 0.48890448  0.2131390 0.6396731
#> 2   Monitoring 0.56833754  0.4300082 0.8265708
#> 3   Evaluating 0.67756154  0.5552496 1.0610893
#> 4  Elaboration 0.45874500  0.2855666 0.7125323
#> 5 Organization 0.56908428  0.4468574 0.9984274
#> 6    Rehearsal 0.30993044  0.1011004 0.4730121
#> 7 Help_Seeking 0.08468196 -0.1307542 0.2177518
#> 8    Time_Mgmt 0.52038228  0.3513479 0.8549979
#> 9   Effort_Reg 0.43757251  0.2806119 0.6824216