MyNixOS website logo
Description

Fitting, Comparing, and Visualizing Networks Based on Time Series Data.

Fit, compare, and visualize Bayesian graphical vector autoregressive (GVAR) network models using 'Stan'. These models are commonly used in psychology to represent temporal and contemporaneous relationships between multiple variables in intensive longitudinal data. Fitted models can be compared with a test based on matrix norm differences of posterior point estimates to quantify the differences between two estimated networks. See also Siepe, Kloft & Heck (2024) <doi:10.31234/osf.io/uwfjc>.

tsnet

R-CMD-check

The goal of tsnet is to include helpful functions for dynamic network modelling in psychology and surrounding fields. The package contains functionality to estimate Bayesian GVAR models in Stan, as well as a test for network comparison. Additionally, the package includes functions to plot posterior estimates and centrality indices. More information is provided in the associated preprint Siepe et al. (2024).

Installation

You can install the released version of tsnet from CRAN with:

install.packages("tsnet")

You can install the development version of tsnet from GitHub with:

# install.packages("devtools")
devtools::install_github("bsiepe/tsnet")

The installation may take some time as the models are compiled upon installation.

Getting Started

Estimating Network Models with Stan

The package includes the stan_gvar function that can be used to estimate a GVAR model with Stan. We use rstan as a backend. More details are included in the package documentation and the associated preprint.

library(tsnet)

# Load example data
data(ts_data)

# use data of first individual
data <- subset(ts_data, id == "ID1")

# Estimate network
fit_stan <- stan_gvar(data[,-7],
                 cov_prior = "IW",
                 iter_warmup = 500,
                 iter_sampling = 500,
                 n_chains = 4)

# print summary
print(fit_stan)

Comparing Network Models

This is an example of how to use the package to compare two network models. We use here BGGM to estimate the networks, but the stan_gvar function can be used as well.

library(tsnet)

# Load simulated time series data of two individuals
data(ts_data)
data_1 <- subset(ts_data, id == "ID1")
data_2 <- subset(ts_data, id == "ID2")

# Estimate networks
# (should perform detrending etc. in a real use case)
net_1 <- stan_gvar(data_1[,-7],
                   iter_sampling = 1000,
                   n_chains = 4)
net_2 <- stan_gvar(data_2[,-7],
                   iter_sampling = 1000,
                   n_chains = 4)

# Plot individual temporal network estimates
post_plot_1 <- posterior_plot(net_1)

You can then compare these networks, summarize the results and plot the test results. In this case, the test is significant for both the temporal and the contemporaneous network.

# Compare networks
compare_13 <- compare_gvar(net_1, 
                           net_2,
                           return_all = TRUE,
                           n_draws = 1000)

# Print summary of results
print(compare_13)

# Plot test results
test_plot_13 <- plot(compare_13,
                     name_a = "Model A",
                     name_b = "Model B")

References

If you use the package, please cite the preprint that introduces the package and the test:

Siepe, B.S., Kloft, M. & Heck, D.W. (2024). Bayesian Estimation and Comparison of Idiographic Network Models. (https://osf.io/preprints/psyarxiv/uwfjc/)

Metadata

Version

0.1.0

License

Unknown

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows