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

https://github.com/sonsoleslp/tna

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

Last synced: 4 months ago
JSON representation

Transition Network Analys 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%",
dpi = 200,
fig.width = 5,
fig.height = 5,
fig.align = "center",
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)

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

## 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("devtools")
install.packages("tna")
devtools::install_github("sonsoleslp/tna")
```

## Example

Load the library
```{r}
library("tna")
```

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

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

```{r, eval = F}
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}
plot(tna_model, cut = 0.3)
```
Calculate the centrality measures
```{r}
cent <- centralities(tna_model)
```

```{r, echo=FALSE}
cent |>
gt::gt() |>
gt::tab_options(table.font.size = 8) |>
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 = F}
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()
```