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
- Host: GitHub
- URL: https://github.com/sonsoleslp/tna
- Owner: sonsoleslp
- License: other
- Created: 2024-05-19T19:28:33.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-02-10T12:56:46.000Z (4 months ago)
- Last Synced: 2025-02-10T13:39:42.333Z (4 months ago)
- Language: R
- Size: 10.2 MB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.Rmd
- Changelog: NEWS.md
- License: LICENSE
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
[](https://www.repostatus.org/#active)
[](https://github.com/sonsoleslp/tna/actions/workflows/R-CMD-check.yaml)
[](https://app.codecov.io/gh/sonsoleslp/tna)
[](https://cran.r-project.org/package=tna)
[](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()
```