Package 'tna'

Title: Transition Network Analysis (TNA)
Description: Provides tools for performing Transition Network Analysis (TNA) to study relational dynamics, including functions for building and plotting TNA models, 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) <doi:10.48550/arXiv.2411.15486> for more details on TNA.
Authors: Sonsoles López-Pernas [aut, cre], Santtu Tikka [aut], Mohammed Saqr [aut]
Maintainer: Sonsoles López-Pernas <[email protected]>
License: MIT + file LICENSE
Version: 0.3.1
Built: 2024-12-16 16:29:23 UTC
Source: https://github.com/sonsoleslp/tna

Help Index


The tna package.

Description

Provides tools for performing transition network analysis (TNA), including functions for building TNA models, plotting transition networks, and calculating centrality measures. The package relies on the qgraph and igraph for network plotting and centrality measure calculations.

Author(s)

Sonsoles López-Pernas, Santtu Tikka, Mohamed Saqr

References

Saqr M., López-Pernas S., Törmänen T., Kaliisa R., Misiejuk K., Tikka S. (2024). Transition Network Analysis: A Novel Framework for Modeling, Visualizing, and Identifying the Temporal Patterns of Learners and Learning Processes. https://arxiv.org/abs/2411.15486

Banerjee A., Chandrasekhar A., Duflo E., Jackson M. (2014). Gossip: Identifying Central Individuals in a Social Network. Working Paper.

Kivimaki, I., Lebichot, B., Saramaki, J., Saerens, M. (2016). Two betweenness centrality measures based on Randomized Shortest Paths. Scientific Reports, 6, 19668.

Serrano, M. A., Boguna, M., Vespignani, A. (2009). Extracting the multiscale backbone of complex weighted networks. Proceedings of the National Academy of Sciences, 106, 6483-6488.

Zhang, B., Horvath, S. (2005). A general framework for weighted gene co-expression network analysis. Statistical Applications in Genetics and Molecular Biology, 4(1).

See Also

Useful links:


Coerce a specific group from a group_tna object to an igraph object.

Description

Coerce a specific group from a group_tna object to an igraph object.

Usage

## S3 method for class 'group_tna'
as.igraph(x, which, ...)

Arguments

x

The object to convert.

which

The number or name of the group.

...

Additional arguments. None currently.

Value

An igraph object.


Coerce a tna object to an igraph object.

Description

Coerce a tna object to an igraph object.

Usage

## S3 method for class 'tna'
as.igraph(x, ...)

Arguments

x

The object to convert.

...

Additional arguments. None currently.

Value

An igraph object.


Build and Visualize a Network with Edge Betweenness

Description

This function builds a network from a transition matrix in a tna object and computes edge betweenness for the network. Optionally, it visualizes the network using the qgraph package, with the edge thickness representing the edge betweenness values.

Usage

betweenness_network(x, ...)

## S3 method for class 'tna'
betweenness_network(x, ...)

Arguments

x

A tna object containing transition matrices and associated metadata.

...

Ignored.

Details

The function first converts the transition matrix for the specified cluster into a directed graph using the igraph package. It then calculates the edge betweenness of the graph, which is a measure of how often an edge lies on the shortest paths between pairs of nodes.

If plot = TRUE, the function uses qgraph to visualize the network, where edge thickness is proportional to edge betweenness, node colors are derived from the tna object, and Pie values from the tna object are displayed on the nodes.

The layout of the network can be customized via the layout parameter, which can either be a predefined layout from qgraph or a user-specified matrix of node positions.

Value

A tna object where edge betweenness represents the edge weights.

Examples

model <- tna(group_regulation)
betweenness_network(model)

Bootstrap Transition Networks from Sequence Data

Description

Perform bootstrapping on transition networks created from sequence data stored in a tna object. Bootstrapped estimates of edge weights are returned with confidence intervals and significance testing.

Usage

bootstrap(x, ...)

## S3 method for class 'tna'
bootstrap(x, iter = 1000, level = 0.05, threshold, ...)

## S3 method for class 'group_tna'
bootstrap(x, ...)

Arguments

x

A tna or a group_tna object created from sequence data.

...

Ignored.

iter

An integer specifying the number of bootstrap samples to draw. Defaults to 1000.

level

A numeric value representing the significance level for hypothesis testing and confidence intervals. Defaults to 0.05.

threshold

A numeric value to compare edge weights against. The default is the 10th percentile of the edge weights.

Details

The function first computes the original edge weights for the specified cluster from the tna object. It then performs bootstrapping by resampling the sequence data and recalculating the edge weights for each bootstrap sample. The mean and standard deviation of the transitions are computed, and confidence intervals are derived. The function also calculates p-values for each edge and identifies significant edges based on the specified significance level. A matrix of significant edges (those with p-values below the significance level) is generated. Additional statistics on removed edges (those not considered significant) are provided.

All results, including the original transition matrix, bootstrapped estimates, and summary statistics for removed edges, are returned in a structured list.

Value

A tna_bootstrap object which is a list containing the following elements:

  • weights_orig: The original edge weight matrix.

  • weights_sig: The matrix of significant transitions (those with p-values below the significance level).

  • weights_mean: The mean weight matrix from the bootstrap samples.

  • weights_sd: The standard deviation matrix from the bootstrap samples.

  • ci_lower: The lower bound matrix of the confidence intervals for the edge weights.

  • ci_upper: The upper bound matrix of the confidence intervals for the edge weights.

  • p_values: The matrix of p-values for the edge weights.

  • summary: A data.frame summarizing the edges, their weights, p-values, statistical significance and confidence intervals.

If x is a group_tna object, the output is a group_tna_bootstrap object, which is a list of tna_bootstrap objects.

See Also

Evaluation and validation functions permutation_test(), prune(), pruning_details()

Cluster-related functions centralities(), cliques(), communities(), deprune(), estimate_cs(), group_model(), hist.group_tna(), mmm_stats(), plot.group_tna(), plot.group_tna_centralities(), plot.group_tna_cliques(), plot.group_tna_communities(), plot.group_tna_stability(), print.group_tna(), print.group_tna_bootstrap(), print.group_tna_centralities(), print.group_tna_cliques(), print.group_tna_communities(), print.group_tna_stability(), print.summary.group_tna(), print.summary.group_tna_bootstrap(), prune(), pruning_details(), rename_groups(), reprune(), summary.group_tna(), summary.group_tna_bootstrap()

Examples

model <- tna(engagement)
# Small number of iterations for CRAN
bootstrap(model, iter = 10)

Build a Transition Network Analysis Model

Description

This function constructs a transition network analysis (TNA) model from a given sequence. It takes a sequence of events or states and builds a Markov model. It extracts the transition probabilities and initial probabilities from the model and stores them in a list along with the state labels. Additionally, it creates a transition matrix with zero diagonal entries (without loops). Also accepts matrices of transition probabilities and initial state probabilities directly.

Usage

build_model(x, type = "relative", scaling = character(0L), ...)

## Default S3 method:
build_model(x, type = "relative", scaling = character(0L), inits, ...)

## S3 method for class 'matrix'
build_model(x, type = "relative", scaling = character(0L), inits, ...)

## S3 method for class 'stslist'
build_model(x, type = "relative", scaling = character(0L), ...)

## S3 method for class 'data.frame'
build_model(x, type = "relative", scaling = character(0L), ...)

tna(x, scaling = character(0L), ...)

ftna(x, scaling = character(0L), ...)

ctna(x, scaling = character(0L), ...)

group_tna(x, scaling = character(0L), ...)

group_ftna(x, scaling = character(0L), ...)

group_ctna(x, scaling = character(0L), ...)

Arguments

x

A stslist (from TraMineR), data.frame, or a matrix. For stslist and data.frame objects x should describe a sequence of events or states to be used for building the Markov model. If x is a matrix, it is assumed that the element on row i and column j is the weight of the edge representing the transition from state i to state j. If x is a data.frame, then it must be in wide format (each column is a time point with no extra columns).

type

A character string describing the weight matrix type. Currently supports the following types:

  • "relative" for relative frequencies (probabilities, the default)

  • "frequency" for frequencies.

  • "co-occurrence" for co-occurrences.

scaling

A character vector describing how to scale the weights defined by type. When a vector is provided, the scaling options are applied in the respective order. For example, c("rank", "minmax") would first compute the ranks, then scale them to the unit interval using min-max normalization. An empty vector corresponds to no scaling. Currently supports the following options:

  • "minmax" performs min-max normalization to scale the weights to the unit interval. Note that if the smallest weight is positive, it will be zero after scaling.

  • "max" Multiplies the weights by the reciprocal of the largest weight to scale the weights to the unit interval. This options preserves positive ranks, unlike "minmax" when all weights are positive.

  • "rank" Computes the ranks of the weights using rank() with ties.method = "average".

...

Ignored.

inits

An optional numeric vector of initial state probabilities for each state. Can be provided only if x is a matrix. The vector will be scaled to unity.

Value

An object of class tna which is a list containing the following elements:

  • weights: An adjacency matrix of the model (weight matrix).

  • inits: A numeric vector of initial values for each state. For matrix type x, this element will be NULL if inits is not directly provided

  • labels: A character vector of the state labels, or NULL if there are no labels.

  • data: The original sequence data that has been converted to an internal format used by the package when x is a stslist or a data.frame object. Otherwise NULL.

See Also

Core functions centralities(), plot.tna(), plot.tna_centralities(), plot_compare()

Examples

model <- build_model(engagement)
print(model)

model <- tna(engagement)

model <- ftna(engagement)

model <- ctna(engagement)

model <- group_tna(engagement, group = gl(2, 100))

model <- group_ftna(engagement, group = gl(2, 100))

model <- group_ctna(engagement, group = gl(2, 100))

Calculate Centrality Measures for a Transition Matrix

Description

Calculates several centrality measures. See 'Details' for information about the measures.

Usage

centralities(x, loops = FALSE, normalize = FALSE, measures, ...)

## S3 method for class 'tna'
centralities(x, loops = FALSE, normalize = FALSE, measures, ...)

## S3 method for class 'matrix'
centralities(x, loops = FALSE, normalize = FALSE, measures, ...)

## S3 method for class 'group_tna'
centralities(x, loops = FALSE, normalize = FALSE, measures, ...)

Arguments

x

A tna object, a group_tna object, or a square matrix representing edge weights.

loops

A logical value indicating whether to include loops in the network when computing the centrality measures (default is FALSE).

normalize

A logical value indicating whether the centralities should be normalized (default is FALSE).

measures

A character vector indicating which centrality measures should be computed. If missing, all available measures are returned. See 'Details' for available measures. The elements are partially matched ignoring case.

...

Ignored.

Details

The following measures are provided:

  • OutStrength: Outgoing strength centrality, calculated using igraph::strength() with mode = "out". It measures the total weight of the outgoing edges from each node.

  • InStrength: Incoming strength centrality, calculated using igraph::strength() with mode = "in". It measures the total weight of the incoming edges to each node.

  • ClosenessIn: Closeness centrality (incoming), calculated using igraph::closeness() with mode = "in". It measures how close a node is to all other nodes based on the incoming paths.

  • ClosenessOut: Closeness centrality (outgoing), calculated using igraph::closeness() with mode = "out". It measures how close a node is to all other nodes based on the outgoing paths.

  • Closeness: Closeness centrality (overall), calculated using igraph::closeness() with mode = "all". It measures how close a node is to all other nodes based on both incoming and outgoing paths.

  • Betweenness: Betweenness centrality defined by the number of geodesics calculated using igraph::betweenness().

  • BetweennessRSP: Betweenness centrality based on randomized shortest paths (Kivimäki et al. 2016). It measures the extent to which a node lies on the shortest paths between other nodes.

  • Diffusion: Diffusion centrality of Banerjee et.al. (2014). It measures the influence of a node in spreading information through the network.

  • Clustering: Signed clustering coefficient of Zhang and Horvath (2005) based on the symmetric adjacency matrix (sum of the adjacency matrix and its transpose). It measures the degree to which nodes tend to cluster together.

Value

A centralities object which is a tibble (tbl_df) containing centrality measures for each state.

See Also

Core functions build_model(), plot.tna(), plot.tna_centralities(), plot_compare()

Cluster-related functions bootstrap(), cliques(), communities(), deprune(), estimate_cs(), group_model(), hist.group_tna(), mmm_stats(), plot.group_tna(), plot.group_tna_centralities(), plot.group_tna_cliques(), plot.group_tna_communities(), plot.group_tna_stability(), print.group_tna(), print.group_tna_bootstrap(), print.group_tna_centralities(), print.group_tna_cliques(), print.group_tna_communities(), print.group_tna_stability(), print.summary.group_tna(), print.summary.group_tna_bootstrap(), prune(), pruning_details(), rename_groups(), reprune(), summary.group_tna(), summary.group_tna_bootstrap()

Examples

model <- tna(engagement)

# Centrality measures including loops in the network
centralities(model)

# Centrality measures excluding loops in the network
centralities(model, loops = FALSE)

# Centrality measures normalized
centralities(model, normalize = TRUE)

Identify Cliques in a Transition Network

Description

This function identifies cliques of a specified size in a transition network. It searches for cliques—complete subgraphs where every pair of nodes is connected—of size n in the transition matrix for the specified cluster in the tna object.

Usage

cliques(x, ...)

## S3 method for class 'tna'
cliques(x, size = 2, threshold = 0, sum_weights = FALSE, ...)

## S3 method for class 'group_tna'
cliques(x, size = 2, threshold = 0, sum_weights = FALSE, ...)

Arguments

x

A tna or a group_tna object.

...

Ignored.

size

An integer specifying the size of the cliques to identify. Defaults to 2 (dyads).

threshold

A numeric value that sets the minimum edge weight for an edge to be considered in the clique. Edges below this value are ignored. Defaults to 0.

sum_weights

A logical value specifying whether the sum of the weights should be above the threshold instead of individual weights of the directed edges. Defaults to FALSE.

Value

A tna_cliques object which is a list of two elements:

  • weights is a matrix of the edge weights in the clique.

  • inits is a numeric vector of initial weights for the clique.

If x is a group_tna object, a group_tna_cliques object is returned instead, which is a list or tna_cliques objects.

See Also

Cluster-related functions bootstrap(), centralities(), communities(), deprune(), estimate_cs(), group_model(), hist.group_tna(), mmm_stats(), plot.group_tna(), plot.group_tna_centralities(), plot.group_tna_cliques(), plot.group_tna_communities(), plot.group_tna_stability(), print.group_tna(), print.group_tna_bootstrap(), print.group_tna_centralities(), print.group_tna_cliques(), print.group_tna_communities(), print.group_tna_stability(), print.summary.group_tna(), print.summary.group_tna_bootstrap(), prune(), pruning_details(), rename_groups(), reprune(), summary.group_tna(), summary.group_tna_bootstrap()

Examples

model <- tna(engagement)

# Find  2-cliques (dyads)
cliq <- cliques(model, size = 2)

Community Detection for Transition Networks

Description

This function detects communities within the transition networks (represented by the tna object). It uses various algorithms to find communities in the graph representation of transitions and returns a list of communities for each cluster or a specified cluster. If multiple transition matrices exist, the function iterates over each cluster in the tna object to find communities using different algorithms. The function uses the igraph package to convert the transition matrices into graphs and then applies community detection algorithms (e.g., Walktrap, Fast Greedy, Label Propagation, Infomap, Edge Betweenness, Leading Eigenvector, and Spin Glass).

Usage

communities(x, ...)

## S3 method for class 'tna'
communities(x, gamma = 1, ...)

## S3 method for class 'group_tna'
communities(x, gamma = 1, ...)

Arguments

x

A tna or a group_tna object.

...

Ignored.

gamma

A numeric value depicting a parameter that affects the behavior of certain algorithms like the Spin Glass method. Defaults to 1.

Value

An object of class tna_communities which is a list with an element for each cluster containing:

  • counts: A list with the number of communities found by each algorithm.

  • assignments: A data.frame where each row corresponds to a node and each column to a community detection algorithm, with color-coded community assignments.

If x is a group_tna object, a group_tna_communities object is returned instead, which is a list of tna_communities objects.

See Also

Pattern-finding functions plot.tna_communities()

Cluster-related functions bootstrap(), centralities(), cliques(), deprune(), estimate_cs(), group_model(), hist.group_tna(), mmm_stats(), plot.group_tna(), plot.group_tna_centralities(), plot.group_tna_cliques(), plot.group_tna_communities(), plot.group_tna_stability(), print.group_tna(), print.group_tna_bootstrap(), print.group_tna_centralities(), print.group_tna_cliques(), print.group_tna_communities(), print.group_tna_stability(), print.summary.group_tna(), print.summary.group_tna_bootstrap(), prune(), pruning_details(), rename_groups(), reprune(), summary.group_tna(), summary.group_tna_bootstrap()

Examples

model <- tna(engagement)
comm <- communities(model)

Restore a Pruned Transition Network Analysis Model

Description

Restore a Pruned Transition Network Analysis Model

Usage

deprune(x, ...)

## S3 method for class 'tna'
deprune(x, ...)

## S3 method for class 'tna'
reprune(x, ...)

## S3 method for class 'group_tna'
deprune(x, ...)

Arguments

x

A tna or group_tna object.

...

Ignored.

Value

A tna or group_tna object that has not been pruned.

See Also

Cluster-related functions bootstrap(), centralities(), cliques(), communities(), estimate_cs(), group_model(), hist.group_tna(), mmm_stats(), plot.group_tna(), plot.group_tna_centralities(), plot.group_tna_cliques(), plot.group_tna_communities(), plot.group_tna_stability(), print.group_tna(), print.group_tna_bootstrap(), print.group_tna_centralities(), print.group_tna_cliques(), print.group_tna_communities(), print.group_tna_stability(), print.summary.group_tna(), print.summary.group_tna_bootstrap(), prune(), pruning_details(), rename_groups(), reprune(), summary.group_tna(), summary.group_tna_bootstrap()

Examples

model <- tna(engagement)
pruned_model <- prune(model, method = "threshold", threshold = 0.1)
depruned_model <- deprune(pruned_model) # restore original model

Example data on student engagement

Description

Students' engagement states (Active / Average / Disengaged) throughout a whole study program. The data was generated synthetically based on the article "The longitudinal association between engagement and achievement varies by time, students’ profiles, and achievement state: A full program study"

Usage

engagement

Format

A stslist object (sequence data).

Source

doi:10.1016/j.compedu.2023.104787

See Also

Other examples: engagement_mmm, group_regulation


Example mixed Markov model fitted to the engagement data

Description

Example mixed Markov model fitted to the engagement data

Usage

engagement_mmm

Format

A mhmm object.

Source

The data was generated via mixed_markov_model.R in https://github.com/sonsoleslp/tna/tree/main/data-raw/

See Also

Other examples: engagement, group_regulation


Estimate Centrality Stability

Description

Estimates the stability of centrality measures in a network using subset sampling without replacement. It allows for dropping varying proportions of cases and calculates correlations between the original centralities and those computed using sampled subsets.

Usage

estimate_cs(x, ...)

estimate_centrality_stability(x, ...)

## S3 method for class 'tna'
estimate_cs(
  x,
  loops = FALSE,
  normalize = FALSE,
  measures = c("InStrength", "OutStrength", "Betweenness"),
  iter = 1000,
  method = "pearson",
  drop_prop = seq(0.1, 0.9, by = 0.1),
  threshold = 0.7,
  certainty = 0.95,
  detailed = FALSE,
  progressbar = FALSE,
  ...
)

## S3 method for class 'tna'
estimate_centrality_stability(
  x,
  loops = FALSE,
  normalize = FALSE,
  measures = c("InStrength", "OutStrength", "Betweenness"),
  iter = 1000,
  method = "pearson",
  drop_prop = seq(0.1, 0.9, by = 0.1),
  threshold = 0.7,
  certainty = 0.95,
  detailed = FALSE,
  progressbar = FALSE,
  ...
)

## S3 method for class 'group_tna'
estimate_cs(
  x,
  loops = FALSE,
  normalize = FALSE,
  measures = c("InStrength", "OutStrength", "Betweenness"),
  iter = 1000,
  method = "pearson",
  drop_prop = seq(0.1, 0.9, by = 0.1),
  threshold = 0.7,
  certainty = 0.95,
  detailed = FALSE,
  progressbar = FALSE,
  ...
)

## S3 method for class 'group_tna'
estimate_centrality_stability(
  x,
  loops = FALSE,
  normalize = FALSE,
  measures = c("InStrength", "OutStrength", "Betweenness"),
  iter = 1000,
  method = "pearson",
  drop_prop = seq(0.1, 0.9, by = 0.1),
  threshold = 0.7,
  certainty = 0.95,
  detailed = FALSE,
  progressbar = FALSE,
  ...
)

Arguments

x

A tna or a group_tna object representing the temporal network analysis data. The object should be created from a sequence data object.

...

Ignored.

loops

A logical value indicating whether to include loops in the network when computing the centrality measures (default is FALSE).

normalize

A logical value indicating whether to normalize the centrality measures. The default is FALSE.

measures

A character vector of centrality measures to estimate. The default measures are "InStrength", "OutStrength", and "Betweenness". See centralities() for a list of available centrality measures.

iter

An integer specifying the number of resamples to draw. The default is 1000.

method

A character string indicating the correlation coefficient type. The default is "pearson". See stats::cor() for details.

drop_prop

A numeric vector specifying the proportions of cases to drop in each sampling iteration. Default is a sequence from 0.1 to 0.9 in increments of 0.1.

threshold

A numeric value specifying the correlation threshold for calculating the CS-coefficient. The default is 0.7.

certainty

A numeric value specifying the desired level of certainty for the CS-coefficient. Default is 0.95.

detailed

A logical value specifying whether to return detailed sampling results. If TRUE, detailed results are included in the output. The default is FALSE.

progressbar

A logical value. If TRUE, a progress bar is displayed Defaults to FALSE

Details

The function works by repeatedly resampling the data, dropping varying proportions of cases, and calculating centrality measures on the subsets. The correlation between the original centralities and the resampled centralities is calculated for each drop proportion. The stability of each centrality measure is then summarized using a centrality stability (CS) coefficient, which represents the proportion of dropped cases at which the correlations drop below a given threshold (default 0.7).

The results can be visualized by plotting the output object showing the stability of the centrality measures across different drop proportions, along with confidence intervals. The CS-coefficients are displayed in the subtitle.

Value

A tna_stability object which is a list with an element for each measure with the following elements:

  • cs_coefficient: The centrality stability (CS) coefficient of the measure.

  • correlations: A matrix of correlations between the original centrality and the resampled centralities for each drop proportion.

  • detailed_results: A detailed data frame of the sampled correlations, returned only if return_detailed = TRUE

If x is a group_tna object, a group_tna_stability object is returned instead, which is a list of tna_stability objects.

See Also

Cluster-related functions bootstrap(), centralities(), cliques(), communities(), deprune(), group_model(), hist.group_tna(), mmm_stats(), plot.group_tna(), plot.group_tna_centralities(), plot.group_tna_cliques(), plot.group_tna_communities(), plot.group_tna_stability(), print.group_tna(), print.group_tna_bootstrap(), print.group_tna_centralities(), print.group_tna_cliques(), print.group_tna_communities(), print.group_tna_stability(), print.summary.group_tna(), print.summary.group_tna_bootstrap(), prune(), pruning_details(), rename_groups(), reprune(), summary.group_tna(), summary.group_tna_bootstrap()

Cluster-related functions bootstrap(), centralities(), cliques(), communities(), deprune(), group_model(), hist.group_tna(), mmm_stats(), plot.group_tna(), plot.group_tna_centralities(), plot.group_tna_cliques(), plot.group_tna_communities(), plot.group_tna_stability(), print.group_tna(), print.group_tna_bootstrap(), print.group_tna_centralities(), print.group_tna_cliques(), print.group_tna_communities(), print.group_tna_stability(), print.summary.group_tna(), print.summary.group_tna_bootstrap(), prune(), pruning_details(), rename_groups(), reprune(), summary.group_tna(), summary.group_tna_bootstrap()

Examples

model <- tna(engagement)
# Small number of iterations and drop proportions for CRAN
estimate_cs(
  model,
  drop_prop = seq(0.3, 0.9, by = 0.2),
  measures = c("InStrength", "OutStrength"),
  iter = 10
)

Parse Event Data Into Sequence Data

Description

Parse Event Data Into Sequence Data

Usage

event2sequence(
  data,
  actor_col,
  time_col,
  action_col,
  time_threshold = 900,
  custom_format = NULL,
  is_unix_time = FALSE,
  unix_time_unit = "seconds",
  verbose = TRUE
)

Arguments

data

A data.frame with three columns for the actor, time, and action.

actor_col

A character string naming the actor column.

time_col

A character string naming the actor column.

action_col

A character string naming the actor column.

time_threshold

TODO

custom_format

A character string giving the format used to parse the time column.

is_unix_time

A logical value indicating whether the time column is in Unix time. The default is FALSE.

unix_time_unit

A character string giving the Unix time unit. The default is "seconds",

verbose

A logical value indicating whether to print informative messages during the parsing process. The default is TRUE.

Value

TODO.

Examples

# TODO

Build a grouped Transition Network Analysis Model

Description

This function constructs a transition network analysis (TNA) model for each cluster from a given sequence, wide-formatted dataframe, or a mixture Markov model.

Usage

group_model(x, group, ...)

## Default S3 method:
group_model(x, group, ...)

## S3 method for class 'mhmm'
group_model(x, ...)

Arguments

x

An stslist object describing a sequence of events or states to be used for building the Markov model. The argument x also accepts a data.frame object in wide format. (each column is a time point with no extra columns). Alternatively, the function accepts a mixture Markov model from the library seqHMM.

group

A vector indicating the cluster assignment of each row of the data / sequence. Must have the same length as the number of rows/sequences of x.

...

Ignored.

Value

An object of class group_tna which is a list containing one element per cluster. Each element is a tna object.

See Also

Cluster-related functions bootstrap(), centralities(), cliques(), communities(), deprune(), estimate_cs(), hist.group_tna(), mmm_stats(), plot.group_tna(), plot.group_tna_centralities(), plot.group_tna_cliques(), plot.group_tna_communities(), plot.group_tna_stability(), print.group_tna(), print.group_tna_bootstrap(), print.group_tna_centralities(), print.group_tna_cliques(), print.group_tna_communities(), print.group_tna_stability(), print.summary.group_tna(), print.summary.group_tna_bootstrap(), prune(), pruning_details(), rename_groups(), reprune(), summary.group_tna(), summary.group_tna_bootstrap()

Cluster-related functions bootstrap(), centralities(), cliques(), communities(), deprune(), estimate_cs(), hist.group_tna(), mmm_stats(), plot.group_tna(), plot.group_tna_centralities(), plot.group_tna_cliques(), plot.group_tna_communities(), plot.group_tna_stability(), print.group_tna(), print.group_tna_bootstrap(), print.group_tna_centralities(), print.group_tna_cliques(), print.group_tna_communities(), print.group_tna_stability(), print.summary.group_tna(), print.summary.group_tna_bootstrap(), prune(), pruning_details(), rename_groups(), reprune(), summary.group_tna(), summary.group_tna_bootstrap()

Cluster-related functions bootstrap(), centralities(), cliques(), communities(), deprune(), estimate_cs(), hist.group_tna(), mmm_stats(), plot.group_tna(), plot.group_tna_centralities(), plot.group_tna_cliques(), plot.group_tna_communities(), plot.group_tna_stability(), print.group_tna(), print.group_tna_bootstrap(), print.group_tna_centralities(), print.group_tna_cliques(), print.group_tna_communities(), print.group_tna_stability(), print.summary.group_tna(), print.summary.group_tna_bootstrap(), prune(), pruning_details(), rename_groups(), reprune(), summary.group_tna(), summary.group_tna_bootstrap()

Examples

group <- c(rep("High", 100), rep("Low", 100))
model <- group_model(engagement, group = group)

Example data on group regulation

Description

Students' regulation during collaborative learning. Students' interactions were coded as: "adapt", "cohesion", "consensus", "coregulate", "discuss", "emotion", "monitor", "plan", "synthesis"

Usage

group_regulation

Format

A data.frame object.

Source

The data was generated synthetically.

See Also

Other examples: engagement, engagement_mmm


Plot a Histogram of Edge Weights for a group_tna Object.

Description

Plot a Histogram of Edge Weights for a group_tna Object.

Usage

## S3 method for class 'group_tna'
hist(x, ...)

Arguments

x

A group_tna object.

...

Additional arguments passed to graphics::hist().

Value

A list (invisibly) of histogram objects of the edge weights of each cluster.

See Also

Cluster-related functions bootstrap(), centralities(), cliques(), communities(), deprune(), estimate_cs(), group_model(), mmm_stats(), plot.group_tna(), plot.group_tna_centralities(), plot.group_tna_cliques(), plot.group_tna_communities(), plot.group_tna_stability(), print.group_tna(), print.group_tna_bootstrap(), print.group_tna_centralities(), print.group_tna_cliques(), print.group_tna_communities(), print.group_tna_stability(), print.summary.group_tna(), print.summary.group_tna_bootstrap(), prune(), pruning_details(), rename_groups(), reprune(), summary.group_tna(), summary.group_tna_bootstrap()

Examples

model <- group_model(engagement_mmm)
hist(model)

Plot a Histogram of Edge Weights in the Network

Description

Plot a Histogram of Edge Weights in the Network

Usage

## S3 method for class 'tna'
hist(x, breaks, col = "lightblue", main, xlab, border = "white", ...)

Arguments

x

a vector of values for which the histogram is desired.

breaks

one of:

  • a vector giving the breakpoints between histogram cells,

  • a function to compute the vector of breakpoints,

  • a single number giving the number of cells for the histogram,

  • a character string naming an algorithm to compute the number of cells (see ‘Details’),

  • a function to compute the number of cells.

In the last three cases the number is a suggestion only; as the breakpoints will be set to pretty values, the number is limited to 1e6 (with a warning if it was larger). If breaks is a function, the x vector is supplied to it as the only argument (and the number of breaks is only limited by the amount of available memory).

col

a colour to be used to fill the bars.

main

A character string defining the title of the plot.

xlab

A character string defining the vertical axis label.

border

the color of the border around the bars. The default is to use the standard foreground color.

...

Additional arguments passed to graphics::hist().

Value

A histogram object of edge weights.

Examples

model <- tna(engagement)
hist(model)

Retrieve statistics from a mixture Markov model (MMM)

Description

Retrieve statistics from a mixture Markov model (MMM)

Usage

mmm_stats(x, use_t_dist = TRUE, level = 0.05)

Arguments

x

An mhmm object.

use_t_dist

A logical value. If TRUE (the default), the t-distribution is used to compute confidence intervals.

level

A numeric value representing the significance level for hypothesis testing and confidence intervals. Defaults to 0.05.

Value

A data.frame object.

See Also

Cluster-related functions bootstrap(), centralities(), cliques(), communities(), deprune(), estimate_cs(), group_model(), hist.group_tna(), plot.group_tna(), plot.group_tna_centralities(), plot.group_tna_cliques(), plot.group_tna_communities(), plot.group_tna_stability(), print.group_tna(), print.group_tna_bootstrap(), print.group_tna_centralities(), print.group_tna_cliques(), print.group_tna_communities(), print.group_tna_stability(), print.summary.group_tna(), print.summary.group_tna_bootstrap(), prune(), pruning_details(), rename_groups(), reprune(), summary.group_tna(), summary.group_tna_bootstrap()

Examples

mmm_stats(engagement_mmm)

Compare Two Networks from Sequence Data Using Permutation Tests

Description

This 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, p-values, and confidence intervals.

Usage

permutation_test(
  x,
  y,
  iter = 1000,
  paired = FALSE,
  level = 0.05,
  measures = character(0),
  ...
)

Arguments

x

A tna object containing sequence data for the first tna model.

y

A tna object containing sequence data for the second tna model.

iter

An integer giving the number of permutations to perform. The default is 1000.

paired

A logical value. If TRUE, perform paired permutation tests; if FALSE, perform unpaired tests. The default is FALSE.

level

A numeric value giving the significance level for the permutation tests. The default is 0.05.

measures

A character vector of centrality measures to test. See centralities() for a list of available centrality measures.

...

Additional arguments passed to centralities().

Value

A tna_permutation object which is a list with two elements: edges and centralities, both containing the following elements

  • stats: A data.frame of original differences and p-values for each edge or centrality measure

  • diffs_true: A matrix of differences in the data.

  • diffs_sig: A matrix showing the significant differences.

See Also

Evaluation and validation functions bootstrap(), prune(), pruning_details()

Examples

model_x <- tna(group_regulation[1:200, ])
model_y <- tna(group_regulation[1001:1200, ])
# Small number of iterations for CRAN
permutation_test(model_x, model_y, iter = 20)

Plot the difference network between two models

Description

Plots the difference network between model x and model y. The edges are computed from subtracting the two models. The pie chart is the difference in initial probabilities between model x and model y. Green color indicates that xis greater than yand red indicates otherwise.

Usage

plot_compare(x, y, ...)

Arguments

x

An object of class tna. It will be the principal model.

y

An object of class tna. It will be the model subtracted from the principal model.

...

Additional arguments passed to qgraph::qgraph().

Value

A qgraph object displaying the difference network between the two models.

See Also

Core functions build_model(), centralities(), plot.tna(), plot.tna_centralities()

Examples

model_x <- tna(engagement[engagement[, 1] == "Active", ])
model_y <- tna(engagement[engagement[, 1] != "Active", ])
plot_compare(model_x, model_y)

Plot a Transition Network Model from a Matrix of Edge Weights

Description

Plot a Transition Network Model from a Matrix of Edge Weights

Usage

plot_model(
  x,
  labels,
  colors,
  edge.labels = TRUE,
  layout = "circle",
  mar = rep(5, 4),
  theme = "colorblind",
  ...
)

Arguments

x

A square matrix of edge weights.

labels

See qgraph::qgraph().

colors

See qgraph::qgraph().

edge.labels

See qgraph::qgraph().

layout

One of the following:

  • A character string describing a qgraph layout.

  • A matrix of node positions to use, with a row for each node and x and y columns for the node positions.

  • A layout function from igraph.

mar

See qgraph::qgraph().

theme

See qgraph::qgraph().

...

Additional arguments passed to qgraph::qgraph().

Value

See plot.tna().

Examples

m <- matrix(rexp(25), 5, 5)
plot_model(m)

Plot a grouped Transition Network Analysis Model

Description

Plots a transition network of each cluster using qgraph.

Usage

## S3 method for class 'group_tna'
plot(x, title, ...)

Arguments

x

A group_model object.

title

A title for each plot. It can be a single string (the same one will be used for all plots) or a list (one per group)

...

Same as plot.tna().

Value

NULL (invisibly).

See Also

Cluster-related functions bootstrap(), centralities(), cliques(), communities(), deprune(), estimate_cs(), group_model(), hist.group_tna(), mmm_stats(), plot.group_tna_centralities(), plot.group_tna_cliques(), plot.group_tna_communities(), plot.group_tna_stability(), print.group_tna(), print.group_tna_bootstrap(), print.group_tna_centralities(), print.group_tna_cliques(), print.group_tna_communities(), print.group_tna_stability(), print.summary.group_tna(), print.summary.group_tna_bootstrap(), prune(), pruning_details(), rename_groups(), reprune(), summary.group_tna(), summary.group_tna_bootstrap()

Examples

model <- group_model(engagement_mmm)
plot(model)

Plot Centrality Measures

Description

Plot Centrality Measures

Usage

## S3 method for class 'group_tna_centralities'
plot(
  x,
  reorder = TRUE,
  ncol = 4,
  scales = c("free_x", "fixed"),
  colors,
  labels = TRUE,
  ...
)

Arguments

x

A group_tna_centralities object.

reorder

A logical value indicating whether to reorder the values for each centrality in a descending order. The default is TRUE.

ncol

Number of columns to use for the facets. The default is 3.

scales

Either "fixed" or "free_x" (the default). If "free_x", the horizontal axis is scaled individually in each facet. If "fixed", the same values are used for all axes.

colors

The colors for each node (default is the model colors if the tna model object is passed, otherwise "black").

labels

A logical value indicating whether to show the centrality numeric values. The default is TRUE.

...

Ignored.

Value

A ggplot object displaying a line chart for each centrality with one line per cluster.

See Also

Cluster-related functions bootstrap(), centralities(), cliques(), communities(), deprune(), estimate_cs(), group_model(), hist.group_tna(), mmm_stats(), plot.group_tna(), plot.group_tna_cliques(), plot.group_tna_communities(), plot.group_tna_stability(), print.group_tna(), print.group_tna_bootstrap(), print.group_tna_centralities(), print.group_tna_cliques(), print.group_tna_communities(), print.group_tna_stability(), print.summary.group_tna(), print.summary.group_tna_bootstrap(), prune(), pruning_details(), rename_groups(), reprune(), summary.group_tna(), summary.group_tna_bootstrap()

Examples

model <- group_model(engagement_mmm)
cm <- centralities(model)
plot(cm)

Plot Found Cliques

Description

Plot Found Cliques

Usage

## S3 method for class 'group_tna_cliques'
plot(x, title, ...)

Arguments

x

A group_tna_cliques object.

title

A character vector of titles to use for each plot.

...

Arguments passed to plot.tna_cliques().

Value

A list (invisibly) with one element per cluster. Each element contains a qgraph plot when only one clique is present per cluster, otherwise the element is NULL.

See Also

Cluster-related functions bootstrap(), centralities(), cliques(), communities(), deprune(), estimate_cs(), group_model(), hist.group_tna(), mmm_stats(), plot.group_tna(), plot.group_tna_centralities(), plot.group_tna_communities(), plot.group_tna_stability(), print.group_tna(), print.group_tna_bootstrap(), print.group_tna_centralities(), print.group_tna_cliques(), print.group_tna_communities(), print.group_tna_stability(), print.summary.group_tna(), print.summary.group_tna_bootstrap(), prune(), pruning_details(), rename_groups(), reprune(), summary.group_tna(), summary.group_tna_bootstrap()

Examples

model <- group_model(engagement_mmm)
cliq <- cliques(model, size = 2)
plot(cliq)

Plot Found Communities

Description

Plot Found Communities

Usage

## S3 method for class 'group_tna_communities'
plot(x, title = names(x), colors, ...)

Arguments

x

A group_tna_communities object.

title

A character vector of titles to use for each plot.

colors

A character vector of colors to use.

...

Arguments passed to plot.tna_communities().

Value

A list (invisibly) of qgraph objects in which the nodes are colored by community for each cluster.

See Also

Cluster-related functions bootstrap(), centralities(), cliques(), communities(), deprune(), estimate_cs(), group_model(), hist.group_tna(), mmm_stats(), plot.group_tna(), plot.group_tna_centralities(), plot.group_tna_cliques(), plot.group_tna_stability(), print.group_tna(), print.group_tna_bootstrap(), print.group_tna_centralities(), print.group_tna_cliques(), print.group_tna_communities(), print.group_tna_stability(), print.summary.group_tna(), print.summary.group_tna_bootstrap(), prune(), pruning_details(), rename_groups(), reprune(), summary.group_tna(), summary.group_tna_bootstrap()

Examples

model <- group_model(engagement_mmm)
comm <- communities(model)
plot(comm)

Plot Centrality Stability Results

Description

Plot Centrality Stability Results

Usage

## S3 method for class 'group_tna_stability'
plot(x, ...)

Arguments

x

A group_tna_stability object.

...

Arguments passed to plot.tna_stability().

Value

A list (invisibly) of ggplot objects displaying the stability analysis plot.

See Also

Cluster-related functions bootstrap(), centralities(), cliques(), communities(), deprune(), estimate_cs(), group_model(), hist.group_tna(), mmm_stats(), plot.group_tna(), plot.group_tna_centralities(), plot.group_tna_cliques(), plot.group_tna_communities(), print.group_tna(), print.group_tna_bootstrap(), print.group_tna_centralities(), print.group_tna_cliques(), print.group_tna_communities(), print.group_tna_stability(), print.summary.group_tna(), print.summary.group_tna_bootstrap(), prune(), pruning_details(), rename_groups(), reprune(), summary.group_tna(), summary.group_tna_bootstrap()

Examples

model <- group_model(engagement_mmm)
# Low number of iterations for CRAN
stability <- estimate_cs(
  model,
  drop_prop = c(0.3, 0.5, 0.7, 0.9),
  iter = 10
)
plot(stability)

Plot a Transition Network Analysis Model

Description

This function plots a transition network analysis (TNA) model using the qgraph package. The nodes in the graph represent states, with node sizes corresponding to initial state probabilities. Edge labels represent the edge weights of the network.

Usage

## S3 method for class 'tna'
plot(
  x,
  labels,
  colors,
  pie,
  edge.labels = TRUE,
  layout = "circle",
  layout_args = list(),
  mar = rep(5, 4),
  theme = "colorblind",
  ...
)

Arguments

x

A tna object from tna().

labels

See qgraph::qgraph().

colors

See qgraph::qgraph().

pie

See qgraph::qgraph().

edge.labels

See qgraph::qgraph().

layout

One of the following:

  • A character string describing a qgraph layout.

  • A matrix of node positions to use, with a row for each node and x and y columns for the node positions.

  • A layout function from igraph.

layout_args

A list of arguments to pass to the igraph layout function when layout is a function.

mar

See qgraph::qgraph().

theme

See qgraph::qgraph().

...

Additional arguments passed to qgraph::qgraph().

Value

A qgraph plot of the transition network.

See Also

Core functions build_model(), centralities(), plot.tna_centralities(), plot_compare()

Examples

model <- tna(engagement)
plot(model)

Plot Centrality Measures

Description

Plots the centrality measures of a tna_centralities object as a lollipop chart. The resulting plot includes facets for each centrality measure, showing the values for each state. The returned plot is a ggplot2 object, so it can be easily modified and styled. See centralities() for details on the centrality measures.

Usage

## S3 method for class 'tna_centralities'
plot(
  x,
  reorder = TRUE,
  ncol = 3,
  scales = c("free_x", "fixed"),
  colors,
  labels = TRUE,
  ...
)

Arguments

x

An object of class tna_centralities.

reorder

A logical value indicating whether to reorder the values for each centrality in a descending order. The default is TRUE.

ncol

Number of columns to use for the facets. The default is 3.

scales

Either "fixed" or "free_x" (the default). If "free_x", the horizontal axis is scaled individually in each facet. If "fixed", the same values are used for all axes.

colors

The colors for each node (default is the model colors if the tna model object is passed, otherwise "black").

labels

A logical value indicating whether to show the centrality numeric values. The default is TRUE.

...

Ignored.

Value

A ggplot object displaying the lollipop charts for each centrality measure.

See Also

Core functions build_model(), centralities(), plot.tna(), plot_compare()

Examples

tna_model <- tna(engagement)
cm <- centralities(tna_model)
plot(cm, ncol = 4, reorder = TRUE)

Plot Cliques of a TNA Network

Description

Plot Cliques of a TNA Network

Usage

## S3 method for class 'tna_cliques'
plot(
  x,
  n = 6,
  first = 1,
  show_loops = FALSE,
  minimum = 1e-05,
  mar = rep(5, 4),
  ask = TRUE,
  ...
)

Arguments

x

A tna_cliques object.

n

An integer defining the maximum number of cliques to show. The defaults is 6.

first

An integer giving the index of the first clique to show. The default index is 1.

show_loops

A logical value indicating whether to include loops in the plots or not.

minimum

See qgraph::qgraph().

mar

See qgraph::qgraph().

ask

A logical value. When TRUE, show plots one by one and asks to plot the next plot in interactive mode.

...

Ignored.

Value

NULL (invisibly).

Examples

model <- tna(engagement)
cliq <- cliques(model, size = 2)
plot(cliq, n = 1)

Plot Communities

Description

This function visualizes the communities detected within a tna object based on different community detection algorithms and their corresponding color mappings.

Usage

## S3 method for class 'tna_communities'
plot(x, cluster = 1L, colors, method = "spinglass", ...)

Arguments

x

A communities object generated by the find_communities method. Each community detection method maps nodes or points in to a specific communities.

cluster

An integer index of the cluster for which to produce the plot. Defaults to the first cluster.

colors

A character vector of color values used for visualizing community assignments.

method

A character string naming a community detection method to use for coloring the plot. This can be one of the following:

...

Additional arguments passed to qgraph::qgraph.

  • "walktrap": A community detection method using short random walks.

  • "fast_greedy": A method based on modularity optimization.

  • "label_prop": A method that uses label propagation.

  • "infomap": A method that uses information flow to detect communities.

  • "edge_betweenness": A method that uses edge betweenness to find communities.

  • "leading_eigen": A method using the leading eigenvector of the modularity matrix.

  • "spinglass": A method based on the spinglass model.

Value

A qgraph object in which the nodes are colored by community.

See Also

Pattern-finding functions communities()

Examples

model <- tna(group_regulation)
comm <- communities(model)
plot(comm, method = "leading_eigen")

Plot the Significant Differences from a Permutation Test

Description

Plot the Significant Differences from a Permutation Test

Usage

## S3 method for class 'tna_permutation'
plot(x, ...)

Arguments

x

A tna_permutation object.

...

Arguments passed to plot_model().

Value

A qgraph object containing only the significant edges according to the permutation test.

Examples

model_x <- tna(group_regulation[1:200, ])
model_y <- tna(group_regulation[1001:1200, ])
# Small number of iterations for CRAN
perm <- permutation_test(model_x, model_y, iter = 20)
plot(perm)

Plot Centrality Stability Results

Description

This function visualizes the centrality stability results produced by the estimate_centrality_stability function. It shows how different centrality measures' correlations change as varying proportions of cases are dropped, along with their confidence intervals (CIs).

Usage

## S3 method for class 'tna_stability'
plot(x, level = 0.05, ...)

Arguments

x

A tna_stability object produced by estimate_cs.

level

A numeric value representing the significance level for the confidence intervals. Defaults to 0.05.

...

Ignored.

Details

The function aggregates the results for each centrality measure across multiple proportions of dropped cases (e.g., 0.1, 0.2, ..., 0.9) and calculates the mean and the desired quantiles for each proportion. The confidence intervals (CIs) are computed based on the quantiles and displayed in the plot.

If no valid data is available for a centrality measure (e.g., missing or NA values), the function skips that measure with a warning.

The plot includes:

  • The mean correlation for each centrality measure as a function of the proportion of dropped cases.

  • Shaded confidence intervals representing CIs for each centrality measure.

  • A horizontal dashed line at the threshold value used for calculating the CS-coefficient.

  • A subtitle listing the CS-coefficients for each centrality measure.

Value

A ggplot object displaying the stability analysis plot.

Examples

model <- tna(engagement)
cs <- estimate_cs(model, iter = 10)
plot(cs)

Print a group_tna Object

Description

Print a group_tna Object

Usage

## S3 method for class 'group_tna'
print(x, ...)

Arguments

x

A group_tna object.

...

Arguments passed to print.tna().

Value

x (invisibly).

See Also

Cluster-related functions bootstrap(), centralities(), cliques(), communities(), deprune(), estimate_cs(), group_model(), hist.group_tna(), mmm_stats(), plot.group_tna(), plot.group_tna_centralities(), plot.group_tna_cliques(), plot.group_tna_communities(), plot.group_tna_stability(), print.group_tna_bootstrap(), print.group_tna_centralities(), print.group_tna_cliques(), print.group_tna_communities(), print.group_tna_stability(), print.summary.group_tna(), print.summary.group_tna_bootstrap(), prune(), pruning_details(), rename_groups(), reprune(), summary.group_tna(), summary.group_tna_bootstrap()

Examples

model <- group_model(engagement_mmm)
print(model)

Print group_tna Bootstrap Results

Description

Print group_tna Bootstrap Results

Usage

## S3 method for class 'group_tna_bootstrap'
print(x, ...)

Arguments

x

A group_tna_bootstrap object.

...

Arguments passed to print.tna_bootstrap().

Value

x (invisibly).

See Also

Cluster-related functions bootstrap(), centralities(), cliques(), communities(), deprune(), estimate_cs(), group_model(), hist.group_tna(), mmm_stats(), plot.group_tna(), plot.group_tna_centralities(), plot.group_tna_cliques(), plot.group_tna_communities(), plot.group_tna_stability(), print.group_tna(), print.group_tna_centralities(), print.group_tna_cliques(), print.group_tna_communities(), print.group_tna_stability(), print.summary.group_tna(), print.summary.group_tna_bootstrap(), prune(), pruning_details(), rename_groups(), reprune(), summary.group_tna(), summary.group_tna_bootstrap()

Examples

model <- group_model(engagement_mmm)
# Low number of iteration for CRAN
boot <- bootstrap(model, iter = 10)
print(boot)

Print Centrality Measures

Description

Print Centrality Measures

Usage

## S3 method for class 'group_tna_centralities'
print(x, ...)

Arguments

x

A group_tna_centralities object.

...

Ignored.

Value

x (invisibly).

See Also

Cluster-related functions bootstrap(), centralities(), cliques(), communities(), deprune(), estimate_cs(), group_model(), hist.group_tna(), mmm_stats(), plot.group_tna(), plot.group_tna_centralities(), plot.group_tna_cliques(), plot.group_tna_communities(), plot.group_tna_stability(), print.group_tna(), print.group_tna_bootstrap(), print.group_tna_cliques(), print.group_tna_communities(), print.group_tna_stability(), print.summary.group_tna(), print.summary.group_tna_bootstrap(), prune(), pruning_details(), rename_groups(), reprune(), summary.group_tna(), summary.group_tna_bootstrap()

Examples

model <- group_model(engagement_mmm)
cm <- centralities(model)
print(cm)

Print Found Cliques

Description

Print Found Cliques

Usage

## S3 method for class 'group_tna_cliques'
print(x, ...)

Arguments

x

A group_tna_cliques object.

...

Arguments passed to print.tna_cliques().

Value

x (invisibly).

See Also

Cluster-related functions bootstrap(), centralities(), cliques(), communities(), deprune(), estimate_cs(), group_model(), hist.group_tna(), mmm_stats(), plot.group_tna(), plot.group_tna_centralities(), plot.group_tna_cliques(), plot.group_tna_communities(), plot.group_tna_stability(), print.group_tna(), print.group_tna_bootstrap(), print.group_tna_centralities(), print.group_tna_communities(), print.group_tna_stability(), print.summary.group_tna(), print.summary.group_tna_bootstrap(), prune(), pruning_details(), rename_groups(), reprune(), summary.group_tna(), summary.group_tna_bootstrap()

Examples

model <- group_model(engagement_mmm)
cliq <- cliques(model, size = 2)
print(cliq)

Print Detected Communities

Description

Print Detected Communities

Usage

## S3 method for class 'group_tna_communities'
print(x, ...)

Arguments

x

A group_tna_communities object.

...

Arguments passed to print.tna_communities().

Value

x (invisibly).

See Also

Cluster-related functions bootstrap(), centralities(), cliques(), communities(), deprune(), estimate_cs(), group_model(), hist.group_tna(), mmm_stats(), plot.group_tna(), plot.group_tna_centralities(), plot.group_tna_cliques(), plot.group_tna_communities(), plot.group_tna_stability(), print.group_tna(), print.group_tna_bootstrap(), print.group_tna_centralities(), print.group_tna_cliques(), print.group_tna_stability(), print.summary.group_tna(), print.summary.group_tna_bootstrap(), prune(), pruning_details(), rename_groups(), reprune(), summary.group_tna(), summary.group_tna_bootstrap()

Examples

model <- group_model(engagement_mmm)
comm <- communities(model)
print(comm)

Print Centrality Stability Results

Description

Print Centrality Stability Results

Usage

## S3 method for class 'group_tna_stability'
print(x, ...)

Arguments

x

A group_tna_stability object.

...

Arguments passed to print.tna_stability().

Value

x (invisibly).

See Also

Cluster-related functions bootstrap(), centralities(), cliques(), communities(), deprune(), estimate_cs(), group_model(), hist.group_tna(), mmm_stats(), plot.group_tna(), plot.group_tna_centralities(), plot.group_tna_cliques(), plot.group_tna_communities(), plot.group_tna_stability(), print.group_tna(), print.group_tna_bootstrap(), print.group_tna_centralities(), print.group_tna_cliques(), print.group_tna_communities(), print.summary.group_tna(), print.summary.group_tna_bootstrap(), prune(), pruning_details(), rename_groups(), reprune(), summary.group_tna(), summary.group_tna_bootstrap()

Examples

model <- group_model(engagement_mmm)
# Low number of iterations for CRAN
stability <- estimate_cs(
  model,
  drop_prop = c(0.3, 0.5, 0.7, 0.9),
  iter = 10
)
print(stability)

Print the summary of a grouped Transition Network Analysis Model

Description

Print the summary of a grouped Transition Network Analysis Model

Usage

## S3 method for class 'summary.group_tna'
print(x, ...)

Arguments

x

A summary.group_tna object.

...

Arguments passed to print.summary.tna().

Value

x (invisibly).

See Also

Cluster-related functions bootstrap(), centralities(), cliques(), communities(), deprune(), estimate_cs(), group_model(), hist.group_tna(), mmm_stats(), plot.group_tna(), plot.group_tna_centralities(), plot.group_tna_cliques(), plot.group_tna_communities(), plot.group_tna_stability(), print.group_tna(), print.group_tna_bootstrap(), print.group_tna_centralities(), print.group_tna_cliques(), print.group_tna_communities(), print.group_tna_stability(), print.summary.group_tna_bootstrap(), prune(), pruning_details(), rename_groups(), reprune(), summary.group_tna(), summary.group_tna_bootstrap()

Examples

model <- group_model(engagement_mmm)
print(summary(model))

Print Bootstrap Summary for a Grouped Transition Network

Description

Print Bootstrap Summary for a Grouped Transition Network

Usage

## S3 method for class 'summary.group_tna_bootstrap'
print(x, ...)

Arguments

x

A summary.group_tna_bootstrap object.

...

Arguments passed to the generic print method.

Value

x (invisibly).

See Also

Cluster-related functions bootstrap(), centralities(), cliques(), communities(), deprune(), estimate_cs(), group_model(), hist.group_tna(), mmm_stats(), plot.group_tna(), plot.group_tna_centralities(), plot.group_tna_cliques(), plot.group_tna_communities(), plot.group_tna_stability(), print.group_tna(), print.group_tna_bootstrap(), print.group_tna_centralities(), print.group_tna_cliques(), print.group_tna_communities(), print.group_tna_stability(), print.summary.group_tna(), prune(), pruning_details(), rename_groups(), reprune(), summary.group_tna(), summary.group_tna_bootstrap()

Examples

model <- group_model(engagement_mmm)
# Low number of iteration for CRAN
boot <- bootstrap(model, iter = 10)
print(summary(boot))

Print a TNA Summary

Description

Print a TNA Summary

Usage

## S3 method for class 'summary.tna'
print(x, ...)

Arguments

x

A summary.tna object.

...

Ignored.

Value

A summary.tna object (invisibly) containing the TNA model network metrics and values.

Examples

model <- tna(engagement)
print(summary(model))

Print Bootstrap Summary

Description

Print Bootstrap Summary

Usage

## S3 method for class 'summary.tna_bootstrap'
print(x, ...)

Arguments

x

A summary.tna_bootstrap object.

...

Arguments passed to the generic print method.

Value

A summary.tna_bootstrap object (invisibly) containing the weight, p-value and confidence interval of each edge.

Examples

model <- tna(engagement)
# Small number of iterations for CRAN
boot <- bootstrap(model, iter = 10)
print(summary(boot))

Print a tna object

Description

Print a tna object

Usage

## S3 method for class 'tna'
print(x, digits = getOption("digits"), generic = FALSE, ...)

Arguments

x

A tna object.

digits

An integer giving the number of significant digits to print.

generic

A logical value. If TRUE, use generic print method instead. Defaults to FALSE.

...

Ignored.

Value

The tna object passed as argument x (invisibly).

Examples

model <- tna(engagement)
print(model)

Print Bootstrap Results

Description

Print Bootstrap Results

Usage

## S3 method for class 'tna_bootstrap'
print(x, digits = getOption("digits"), type = "both", ...)

Arguments

x

A tna_bootstrap object.

digits

An integer giving the minimal number of significant digits to print.

type

A character vector giving the type of edges to print. The default option "both" prints both statistically significant and non-significant edges, "sig" prints only significant edges, and "nonsig" prints only the non-significant edges.

...

Ignored.

Value

x (invisibly).

Examples

model <- tna(engagement)
# Small number of iterations for CRAN
boot <- bootstrap(model, iter = 10)
print(boot)

Print Centrality Measures

Description

Print Centrality Measures

Usage

## S3 method for class 'tna_centralities'
print(x, ...)

Arguments

x

A centralities object.

...

Ignored.

Value

x (invisibly).

Examples

model <- tna(engagement)
cm <- centralities(model)
print(cm)

Print Found Cliques of a TNA Network

Description

Print Found Cliques of a TNA Network

Usage

## S3 method for class 'tna_cliques'
print(x, n = 6, first = 1, digits = getOption("digits"), ...)

Arguments

x

A tna_cliques object.

n

An integer defining the maximum number of cliques to show. The defaults is 6.

first

An integer giving the index of the first clique to show. The default index is 1.

digits

An integer giving the minimal number of significant digits to print.

...

Ignored.

Value

x (invisibly).

Examples

model <- tna(engagement)
cliq <- cliques(model, size = 2)
print(cliq)

Print Detected Communities

Description

Print Detected Communities

Usage

## S3 method for class 'tna_communities'
print(x, ...)

Arguments

x

A tna_communities object.

...

Ignored.

Value

x (invisibly).

Examples

model <- tna(engagement)
comm <- communities(model)
print(comm)

Print Permutation Test Results

Description

Print Permutation Test Results

Usage

## S3 method for class 'tna_permutation'
print(x, ...)

Arguments

x

A tna_permutation object.

...

Additional arguments passed to the tibble print method.

Value

x (invisibly).

Examples

model_x <- tna(group_regulation[1:200, ])
model_y <- tna(group_regulation[1001:1200, ])
# Small number of iterations for CRAN
perm <- permutation_test(model_x, model_y, iter = 20)
print(perm)

Print Centrality Stability Results

Description

Print Centrality Stability Results

Usage

## S3 method for class 'tna_stability'
print(x, ...)

Arguments

x

A tna_stability object.

...

Ignored.

Value

x (invisibly).

Examples

model <- tna(engagement)
# Small number of iterations and drop proportions for CRAN
cs <- estimate_cs(
  model,
  measures = c("InStrength", "OutStrength"),
  drop_prop = seq(0.3, 0.9, by = 0.2),
  iter = 10
)
print(cs)

Prune a tna network based on transition probabilities

Description

Prunes a network represented by a tna object by removing edges based on a specified threshold, lowest percent of non-zero edge weights, or the disparity filter algorithm (Serrano et al., 2009). It ensures the network remains weakly connected.

Prunes a network represented by a tna object by removing edges based on a specified threshold, lowest percent of non-zero edge weights, or the disparity filter algorithm (Serrano et al., 2009). It ensures the network remains weakly connected.

Usage

prune(x, ...)

## S3 method for class 'tna'
prune(
  x,
  method = "threshold",
  threshold = 0.1,
  lowest = 0.05,
  level = 0.5,
  boot = NULL,
  ...
)

## S3 method for class 'group_tna'
prune(x, ...)

Arguments

x

An object of class tna or group_tna

...

Arguments passed to bootstrap() when using method = "bootstrap" and when a tna_bootstrap is not supplied.

method

A character string describing the pruning method. The available options are "threshold", "lowest", "bootstrap" and "disparity", corresponding to the methods listed in Details. The default is "threshold".

threshold

A numeric value specifying the edge weight threshold. Edges with weights below or equal to this threshold will be considered for removal.

lowest

A numeric value specifying the lowest percentage of non-zero edges. This percentage of edges with the lowest weights will be considered for removal. The default is 0.05.

level

A numeric value representing the significance level for the disparity filter. Defaults to 0.5.

boot

A tna_bootstrap object to be used for pruning with method "boot". The method argument is ignored if this argument is supplied.

Value

A pruned tna or group_tna object. Details on the pruning can be viewed with pruning_details(). The original model can be restored with deprune().

See Also

Evaluation and validation functions bootstrap(), permutation_test(), pruning_details()

Evaluation and validation functions bootstrap(), permutation_test(), pruning_details()

Cluster-related functions bootstrap(), centralities(), cliques(), communities(), deprune(), estimate_cs(), group_model(), hist.group_tna(), mmm_stats(), plot.group_tna(), plot.group_tna_centralities(), plot.group_tna_cliques(), plot.group_tna_communities(), plot.group_tna_stability(), print.group_tna(), print.group_tna_bootstrap(), print.group_tna_centralities(), print.group_tna_cliques(), print.group_tna_communities(), print.group_tna_stability(), print.summary.group_tna(), print.summary.group_tna_bootstrap(), pruning_details(), rename_groups(), reprune(), summary.group_tna(), summary.group_tna_bootstrap()

Examples

model <- tna(group_regulation)
pruned_threshold <- prune(model, method = "threshold", threshold = 0.1)
pruned_percentile <- prune(model, method = "lowest", lowest = 0.05)
pruned_disparity <- prune(model, method = "disparity", level = 0.5)

Print Detailed Information on the Pruning Results

Description

Print Detailed Information on the Pruning Results

Usage

pruning_details(x, ...)

## S3 method for class 'tna'
pruning_details(x, ...)

## S3 method for class 'group_tna'
pruning_details(x, ...)

Arguments

x

A tna or group_tna object.

...

Ignored.

Value

A data.frame containing the removed edges if x is a tna object, or a list of data.frame objects in the case of group_tna object.

See Also

Evaluation and validation functions bootstrap(), permutation_test(), prune()

Cluster-related functions bootstrap(), centralities(), cliques(), communities(), deprune(), estimate_cs(), group_model(), hist.group_tna(), mmm_stats(), plot.group_tna(), plot.group_tna_centralities(), plot.group_tna_cliques(), plot.group_tna_communities(), plot.group_tna_stability(), print.group_tna(), print.group_tna_bootstrap(), print.group_tna_centralities(), print.group_tna_cliques(), print.group_tna_communities(), print.group_tna_stability(), print.summary.group_tna(), print.summary.group_tna_bootstrap(), prune(), rename_groups(), reprune(), summary.group_tna(), summary.group_tna_bootstrap()

Examples

model <- tna(group_regulation)
pruned_threshold <- prune(model, method = "threshold", threshold = 0.1)
pruning_details(pruned_threshold)

Rename clusters

Description

Rename clusters

Usage

rename_groups(x, new_names)

Arguments

x

A group_tna object.

new_names

A vector containing one name per cluster.

Value

A renamed group_tna object.

See Also

Cluster-related functions bootstrap(), centralities(), cliques(), communities(), deprune(), estimate_cs(), group_model(), hist.group_tna(), mmm_stats(), plot.group_tna(), plot.group_tna_centralities(), plot.group_tna_cliques(), plot.group_tna_communities(), plot.group_tna_stability(), print.group_tna(), print.group_tna_bootstrap(), print.group_tna_centralities(), print.group_tna_cliques(), print.group_tna_communities(), print.group_tna_stability(), print.summary.group_tna(), print.summary.group_tna_bootstrap(), prune(), pruning_details(), reprune(), summary.group_tna(), summary.group_tna_bootstrap()

Examples

model <- group_model(engagement_mmm)
model_renamed <- rename_groups(model, c("A", "B", "C"))

Restore Previous Pruning of a Transition Network Analysis Model

Description

Restore Previous Pruning of a Transition Network Analysis Model

Usage

reprune(x, ...)

## S3 method for class 'group_tna'
reprune(x, ...)

Arguments

x

A tna or group_tna object.

...

Ignored.

Value

A tna or group_tna object that has not been pruned. The previous pruning result can be reactivated with reprune().

See Also

Cluster-related functions bootstrap(), centralities(), cliques(), communities(), deprune(), estimate_cs(), group_model(), hist.group_tna(), mmm_stats(), plot.group_tna(), plot.group_tna_centralities(), plot.group_tna_cliques(), plot.group_tna_communities(), plot.group_tna_stability(), print.group_tna(), print.group_tna_bootstrap(), print.group_tna_centralities(), print.group_tna_cliques(), print.group_tna_communities(), print.group_tna_stability(), print.summary.group_tna(), print.summary.group_tna_bootstrap(), prune(), pruning_details(), rename_groups(), summary.group_tna(), summary.group_tna_bootstrap()

Examples

model <- tna(engagement)
pruned_model <- prune(model, method = "threshold", threshold = 0.1)
depruned_model <- deprune(pruned_model) # restore original model
repruned_model <- reprune(depruned_model) # reapply the previous pruning

Calculate Summary of Network Metrics for a grouped Transition Network

Description

This function calculates a variety of network metrics for a tna object. It computes key metrics such as node and edge counts, network density, mean distance, strength measures, degree centrality, and reciprocity.

Usage

## S3 method for class 'group_tna'
summary(object, combined = TRUE, ...)

Arguments

object

A group_tna object.

combined

A logical indicating whether the summary results should be combined into a single data frame for all clusters (defaults to TRUE)

...

Ignored

Details

The function extracts the igraph network for each cluster and computes the following network metrics:

  • Node count: Total number of nodes in the network.

  • Edge count: Total number of edges in the network.

  • Network density: Proportion of possible edges that are present in the network.

  • Mean distance: The average shortest path length between nodes.

  • Mean and standard deviation of out-strength and in-strength: Measures of the total weight of outgoing and incoming edges for each node.

  • Mean and standard deviation of out-degree: The number of outgoing edges from each node.

  • Centralization of out-degree and in-degree: Measures of how centralized the network is based on the degrees of nodes.

  • Reciprocity: The proportion of edges that are reciprocated (i.e., mutual edges between nodes).

Value

A summary.group_tna object which is a list of lists or a combined data.frame containing the following network metrics:

  • node_count: The total number of nodes.

  • edge_count: The total number of edges.

  • network_Density: The density of the network.

  • mean_distance: The mean shortest path length.

  • mean_out_strength: The mean out-strength of nodes.

  • sd_out_strength: The standard deviation of out-strength.

  • mean_in_strength: The mean in-strength of nodes.

  • sd_in_strength: The standard deviation of in-strength.

  • mean_out_degree: The mean out-degree of nodes.

  • sd_out_degree: The standard deviation of out-degree.

  • centralization_out_degree: The centralization of out-degree.

  • centralization_in_degree: The centralization of in-degree.

  • reciprocity: The reciprocity of the network.

See Also

Cluster-related functions bootstrap(), centralities(), cliques(), communities(), deprune(), estimate_cs(), group_model(), hist.group_tna(), mmm_stats(), plot.group_tna(), plot.group_tna_centralities(), plot.group_tna_cliques(), plot.group_tna_communities(), plot.group_tna_stability(), print.group_tna(), print.group_tna_bootstrap(), print.group_tna_centralities(), print.group_tna_cliques(), print.group_tna_communities(), print.group_tna_stability(), print.summary.group_tna(), print.summary.group_tna_bootstrap(), prune(), pruning_details(), rename_groups(), reprune(), summary.group_tna_bootstrap()

Examples

group <- c(rep("High", 100), rep("Low", 100))
model <- group_model(engagement, group = group)
summary(model)

Summarize Bootstrap Results for a Grouped Transition Network

Description

Summarize Bootstrap Results for a Grouped Transition Network

Usage

## S3 method for class 'group_tna_bootstrap'
summary(object, ...)

Arguments

object

A group_tna_bootstrap object from bootstrap().

...

Ignored.

Value

A summary.group_tna_bootstrap object containing the weight, p-value and confidence interval of each edge for each cluster.

See Also

Cluster-related functions bootstrap(), centralities(), cliques(), communities(), deprune(), estimate_cs(), group_model(), hist.group_tna(), mmm_stats(), plot.group_tna(), plot.group_tna_centralities(), plot.group_tna_cliques(), plot.group_tna_communities(), plot.group_tna_stability(), print.group_tna(), print.group_tna_bootstrap(), print.group_tna_centralities(), print.group_tna_cliques(), print.group_tna_communities(), print.group_tna_stability(), print.summary.group_tna(), print.summary.group_tna_bootstrap(), prune(), pruning_details(), rename_groups(), reprune(), summary.group_tna()

Examples

model <- group_tna(engagement_mmm)
# Small number of iterations for CRAN
boot <- bootstrap(model, iter = 10)
summary(boot)

Calculate Summary of Network Metrics for a Transition Network

Description

This function calculates a variety of network metrics for a tna object. It computes key metrics such as node and edge counts, network density, mean distance, strength measures, degree centrality, and reciprocity.

Usage

## S3 method for class 'tna'
summary(object, ...)

Arguments

object

A tna object.

...

Ignored

Details

The function extracts the igraph network and computes the following network metrics:

  • Node count: Total number of nodes in the network.

  • Edge count: Total number of edges in the network.

  • Network density: Proportion of possible edges that are present in the network.

  • Mean distance: The average shortest path length between nodes.

  • Mean and standard deviation of out-strength and in-strength: Measures of the total weight of outgoing and incoming edges for each node.

  • Mean and standard deviation of out-degree: The number of outgoing edges from each node.

  • Centralization of out-degree and in-degree: Measures of how centralized the network is based on the degrees of nodes.

  • Reciprocity: The proportion of edges that are reciprocated (i.e., mutual edges between nodes).

A summary of the metrics is printed to the console.

Value

A named list containing the following network metrics (invisibly):

  • node_count: The total number of nodes.

  • edge_count: The total number of edges.

  • network_Density: The density of the network.

  • mean_distance: The mean shortest path length.

  • mean_out_strength: The mean out-strength of nodes.

  • sd_out_strength: The standard deviation of out-strength.

  • mean_in_strength: The mean in-strength of nodes.

  • sd_in_strength: The standard deviation of in-strength.

  • mean_out_degree: The mean out-degree of nodes.

  • sd_out_degree: The standard deviation of out-degree.

  • centralization_out_degree: The centralization of out-degree.

  • centralization_in_degree: The centralization of in-degree.

  • reciprocity: The reciprocity of the network.

Examples

model <- tna(engagement)
summary(model)

Summarize Bootstrap Results

Description

Summarize Bootstrap Results

Usage

## S3 method for class 'tna_bootstrap'
summary(object, ...)

Arguments

object

A tna_bootstrap object from bootstrap().

...

Ignored.

Value

A summary.tna_bootstrap object containing the weight, p-value and confidence interval of each edge.

Examples

model <- tna(engagement)
# Small number of iterations for CRAN
boot <- bootstrap(model, iter = 50)
summary(boot)