An open API service indexing awesome lists of open source software.

https://github.com/sonsoleslp/tna

Transition Network Analysis R package
https://github.com/sonsoleslp/tna

cran-r educational-data-mining learning-analytics markov-model r temporal-analysis

Last synced: 9 months ago
JSON representation

Transition Network Analysis R package

Awesome Lists containing this project

README

          

---
output: github_document
---

```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "60%",
fig.width = 5,
fig.height = 5,
fig.align = "center",
dev = "svg",
fig.ext = "svg",
out.extra = "style='text-align: center; display: block; margin: auto;'"
)
```

# `tna`: An R package for Transition Network Analysis

[![Project Status: Active – The project has reached a stable, usable state and is being actively developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active)
[![R-CMD-check](https://github.com/sonsoleslp/tna/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/sonsoleslp/tna/actions/workflows/R-CMD-check.yaml)
[![Codecov test coverage](https://codecov.io/gh/sonsoleslp/tna/graph/badge.svg)](https://app.codecov.io/gh/sonsoleslp/tna)
[![tna CRAN badge](https://www.r-pkg.org/badges/version/tna)](https://cran.r-project.org/package=tna)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

`tna` is an R package for the analysis of relational dynamics through
Transition Network Analysis (TNA). TNA provides tools for building TNA models,
plotting transition networks, calculating centrality measures, and identifying
dominant events and patterns. TNA statistical techniques (e.g., bootstrapping
and permutation tests) ensure the reliability of observed insights and confirm
that identified dynamics are meaningful. See [(Saqr et al., 2025)](https://doi.org/10.1145/3706468.3706513) for more details on TNA.

![](man/figures/method.png)

## Resources

Check out our tutorials:

- [Basics of TNA](https://lamethods.org/book2/chapters/ch15-tna/ch15-tna.html)
- [Frequency-based TNA](https://lamethods.org/book2/chapters/ch16-ftna/ch16-ftna.html)
- [Clustering](https://lamethods.org/book2/chapters/ch17-tna-clusters/ch17-tna-clusters.html)

You can also try our [Shiny app](https://sonsoleslp.shinyapps.io/tna-app/).

## Installation

You can install the most recent stable version of `tna` from [CRAN](https://cran.r-project.org/package=tna) or the development version from [GitHub](https://github.com/) by running one of the following:

```{r, eval = FALSE}
install.packages("tna")

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

## Example

Load the package
```{r, echo=FALSE}
suppressPackageStartupMessages(library("tna"))
```
```{r, eval=FALSE}
library("tna")
```

Example data
```{r}
data("group_regulation", package = "tna")
```

Build a Markov model
```{r}
tna_model <- tna(group_regulation)
```

```{r, eval=FALSE}
summary(tna_model)
```
```{r, echo=FALSE}
summary(tna_model) |>
gt::gt() |>
gt::fmt_number(decimals = 2) |>
gt::as_raw_html()
```

Plot the transition network
```{r tnaplot}
# Default plot
plot(tna_model)
# Optimized plot
plot(
tna_model, cut = 0.2, minimum = 0.05,
edge.label.position = 0.8, edge.label.cex = 0.7
)
```
Calculate the centrality measures
```{r}
cent <- centralities(tna_model)
```

```{r, echo=FALSE}
cent |>
gt::gt() |>
gt::tab_options(table.font.size = 8) |>
gt::fmt_number(decimals = 3) |>
gt::as_raw_html()
```

Plot the centrality measures

```{r centralitiesplot, fig.width=12, fig.height=8, out.width="90%"}
plot(cent, ncol = 3)
```

Estimate centrality stability
```{r}
estimate_centrality_stability(tna_model)
```

Identify and plot communities
```{r}
coms <- communities(tna_model)
plot(coms)
```

Find and plot cliques
```{r, eval = F}
cqs <- cliques(tna_model, threshold = 0.12)
plot(cqs)
```

```{r, out.width="100%", fig.width=6, fig.height=2, echo = FALSE}
layout(t(1:3))
cqs <- cliques(tna_model, threshold = 0.12)
plot(cqs, vsize = 30, edge.label.cex = 3)
```

Compare high achievers (first 1000) with low achievers (last 1000)
```{r}
tna_model_start_high <- tna(group_regulation[1:1000, ])
tna_model_start_low <- tna(group_regulation[1001:2000, ])
comparison <- permutation_test(
tna_model_start_high,
tna_model_start_low,
measures = c("InStrength")
)
```

Simple comparison vs. permutation test comparison
```{r, fig.width=10, fig.height=5, out.width="100%", echo = 2:3}
layout(t(1:2))
plot_compare(tna_model_start_high, tna_model_start_low)
plot(comparison)
```

Compare centralities
```{r, eval = FALSE}
print(comparison$centralities$stats)
```

```{r, echo = FALSE}
comparison$centralities$stats |>
gt::gt() |>
gt::as_raw_html()
```