-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathREADME.Rmd
More file actions
133 lines (95 loc) · 4.03 KB
/
README.Rmd
File metadata and controls
133 lines (95 loc) · 4.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# tsnet
<!-- badges: start -->
[](https://github.com/bsiepe/tsnet/actions/workflows/R-CMD-check.yaml)
<!-- badges: end -->
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 paper [Siepe et al. (2024)](https://doi.org/10.1037/met0000672) (Preprint available [here](https://osf.io/preprints/psyarxiv/uwfjc/)).
## Installation
You can install the released version of `tsnet` from [CRAN](https://CRAN.R-project.org) with:
``` r
install.packages("tsnet")
```
You can install the development version of `tsnet` from [GitHub](https://github.com/bsiepe/tsnet) with:
``` r
# 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.
```{r example-fit, eval = FALSE}
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 here use `BGGM` to estimate the networks, but the `stan_gvar` function can be used as well.
```{r example-test, eval = FALSE}
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.
```{r compare, eval = FALSE}
# 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 paper that introduces the package and the test:
Siepe, B. S., Kloft, M., & Heck, D. W. (2024). Bayesian estimation and comparison of idiographic network models. *Psychological Methods*. Advance online publication. https://doi.org/10.1037/met0000672
As a BiBTeX entry:
```BiBTeX
@article{siepe2024bayesian,
title={Bayesian estimation and comparison of idiographic network models},
author={Siepe, Björn S. and Kloft, Matthias and Heck, Daniel W.},
journal={Psychological Methods},
issue={Advance online publication},
year={2024},
doi={10.1037/met0000672}
}
```