RTransferEntropy
Code to implement transfer entropy (Shannon and Renyi)
Science Score: 33.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
○CITATION.cff file
-
○codemeta.json file
-
○.zenodo.json file
-
✓DOI references
Found 3 DOI reference(s) in README -
✓Academic publication links
Links to: sciencedirect.com -
✓Committers with academic emails
1 of 6 committers (16.7%) from academic institutions -
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (15.9%) to scientific vocabulary
Last synced: 10 months ago
·
JSON representation
Repository
Code to implement transfer entropy (Shannon and Renyi)
Basic Info
Statistics
- Stars: 23
- Watchers: 3
- Forks: 10
- Open Issues: 3
- Releases: 0
Created over 8 years ago
· Last pushed over 3 years ago
Metadata Files
Readme
License
README.Rmd
---
output: github_document
---
[](https://github.com/BZPaper/RTransferEntropy/actions)
[](https://cran.r-project.org/package=RTransferEntropy)
[](https://cran.r-project.org/package=RTransferEntropy)
[](https://doi.org/10.1016/j.softx.2019.100265)
```{r, echo = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-"
)
```
# RTransferEntropy
The goal of `RTransferEntropy` is to implement the calculation of the transfer entropy metric using Shannon's or the Renyi's methodology.
A short introduction can be found below, for a more thorough introduction to the transfer entropy methodology and the `RTransferEntropy` package, see the [vignette](https://cran.r-project.org/package=RTransferEntropy/vignettes/transfer-entropy.html) and the [`RTransferEntropy` paper](https://www.sciencedirect.com/science/article/pii/S2352711019300779).
If you use the package in academic work, please make sure to cite us, see also `citation("RTransferEntropy")`.
The authors of the [`TransferEntropy`](https://CRAN.R-project.org/package=TransferEntropy) package no longer develop their package, which is deprecated as of 2018-08-10, and recommend the use of this package.
## Installation
You can install `RTransferEntropy` with
```{r, eval = FALSE}
install.packages("RTransferEntropy")
```
or the development version from github with
```{r gh_installation, eval = FALSE}
# install.packages("devtools")
devtools::install_github("BZPaper/RTransferEntropy")
```
## Example using simulated data
Simulate a simple model to obtain two time series that are not independent (see simulation study in Dimpfl and Peter (2013)),
i.e. one time series is lag of the other plus noise. In this case, one expects significant information flow from x to y
and none from y to x.
### Simulating a Time-Series
```{r}
library(RTransferEntropy)
library(future)
# enable parallel processing
plan(multisession)
set.seed(20180108)
n <- 2000
x <- rep(0, n + 1)
y <- rep(0, n + 1)
for (i in seq(n)) {
x[i + 1] <- 0.2 * x[i] + rnorm(1, 0, 2)
y[i + 1] <- x[i] + rnorm(1, 0, 2)
}
x <- x[-1]
y <- y[-1]
```
### Visualisation
```{r contemp_plot, message=FALSE, warning=FALSE}
library(ggplot2)
library(gridExtra)
theme_set(theme_light())
# Lagged X-Plot
p1 <- ggplot(data.frame(x = c(NA, x[1:(length(x) - 1)]), y = y), aes(x, y)) +
geom_smooth() +
geom_point(alpha = 0.5, size = 0.5) +
labs(x = expression(X[t - 1]), y = expression(Y[t])) +
coord_fixed(1) +
scale_x_continuous(limits = range(x)) +
scale_y_continuous(limits = range(y))
# X-Y Plot
p2 <- ggplot(data.frame(x = x, y = y), aes(x, y)) +
geom_smooth() +
geom_point(alpha = 0.5, size = 0.5) +
labs(x = expression(X[t]), y = expression(Y[t])) +
coord_fixed(1) +
scale_x_continuous(limits = range(x)) +
scale_y_continuous(limits = range(y))
# Lagged Y Plot
p3 <- ggplot(data.frame(x = x, y = c(NA, y[1:(length(y) - 1)])), aes(x, y)) +
geom_smooth() +
geom_point(alpha = 0.5, size = 0.5) +
labs(x = expression(X[t]), y = expression(Y[t - 1])) +
coord_fixed(1) +
scale_x_continuous(limits = range(x)) +
scale_y_continuous(limits = range(y))
a <- grid.arrange(p1, p2, p3, ncol = 3)
```
### Shannon Transfer Entropy
```{r}
set.seed(20180108 + 1)
shannon_te <- transfer_entropy(x = x, y = y)
shannon_te
summary(shannon_te)
```
Alternatively, you can calculate only the transfer entropy or the effective transfer entropy with
```{r}
calc_te(x, y)
calc_te(y, x)
calc_ete(x, y)
calc_ete(y, x)
```
### Renyi Transfer Entropy
```{r}
set.seed(20180108 + 1)
renyi_te <- transfer_entropy(x = x, y = y, entropy = "renyi", q = 0.5)
renyi_te
calc_te(x, y, entropy = "renyi", q = 0.5)
calc_te(y, x, entropy = "renyi", q = 0.5)
calc_ete(x, y, entropy = "renyi", q = 0.5)
calc_ete(y, x, entropy = "renyi", q = 0.5)
```
# Function Verbosity aka `quiet = TRUE`
To disable the verbosity of a function you can use the argument `quiet`. Note that we have set `nboot = 0` as we don't need bootstrapped quantiles for this example.
```{r}
te <- transfer_entropy(x, y, nboot = 0, quiet = T)
te
```
If you want to disable feedback from `transfer_entropy` functions, you can do so by using `set_quiet(TRUE)`
```{r}
set_quiet(TRUE)
te <- transfer_entropy(x, y, nboot = 0)
te
# revert back with
set_quiet(FALSE)
te <- transfer_entropy(x, y, nboot = 0)
```
# Parallel Programming
Using the `future` package and its `plan`s we can execute all computations in parallel like so
```{r, warning=F}
library(future)
plan(multisession)
te <- transfer_entropy(x, y, nboot = 100)
# revert to sequential mode
plan(sequential)
te <- transfer_entropy(x, y, nboot = 100)
# close multisession, see also ?plan
plan(sequential)
```
Owner
- Name: BZPaper
- Login: BZPaper
- Kind: organization
- Repositories: 1
- Profile: https://github.com/BZPaper
GitHub Events
Total
- Watch event: 3
Last Year
- Watch event: 3
Issues and Pull Requests
Last synced: 11 months ago
All Time
- Total issues: 53
- Total pull requests: 7
- Average time to close issues: about 2 months
- Average time to close pull requests: about 18 hours
- Total issue authors: 13
- Total pull request authors: 2
- Average comments per issue: 2.89
- Average comments per pull request: 0.14
- Merged pull requests: 7
- Bot issues: 0
- Bot pull requests: 0
Past Year
- Issues: 0
- Pull requests: 0
- Average time to close issues: N/A
- Average time to close pull requests: N/A
- Issue authors: 0
- Pull request authors: 0
- Average comments per issue: 0
- Average comments per pull request: 0
- Merged pull requests: 0
- Bot issues: 0
- Bot pull requests: 0
Top Authors
Issue Authors
- LeeHaoyu (18)
- DavZim (12)
- dimpflth (11)
- caioestevao (2)
- Abigail575 (2)
- aurelio05 (1)
- xixi911 (1)
- HenrikBengtsson (1)
- dizcza (1)
- jjantunes (1)
- Bharathi-A-7 (1)
- emabe (1)
- dmattek (1)
Pull Request Authors
- DavZim (6)
- LeeHaoyu (1)
Top Labels
Issue Labels
bug (2)
enhancement (1)
Pull Request Labels
Packages
- Total packages: 1
-
Total downloads:
- cran 823 last-month
- Total docker downloads: 21,154
- Total dependent packages: 1
- Total dependent repositories: 2
- Total versions: 7
- Total maintainers: 1
cran.r-project.org: RTransferEntropy
Measuring Information Flow Between Time Series with Shannon and Renyi Transfer Entropy
- Homepage: https://github.com/BZPaper/RTransferEntropy
- Documentation: http://cran.r-project.org/web/packages/RTransferEntropy/RTransferEntropy.pdf
- License: GPL-3
-
Latest release: 0.2.21
published over 3 years ago
Rankings
Forks count: 7.3%
Docker downloads count: 12.6%
Stargazers count: 12.9%
Average: 15.2%
Dependent packages count: 18.1%
Dependent repos count: 19.3%
Downloads: 20.9%
Maintainers (1)
Last synced:
11 months ago
Dependencies
DESCRIPTION
cran
- R >= 3.1.2 depends
- Rcpp * imports
- future >= 1.19.0 imports
- future.apply * imports
- data.table * suggests
- ggplot2 * suggests
- gridExtra * suggests
- knitr * suggests
- quantmod * suggests
- rmarkdown * suggests
- testthat * suggests
- vars * suggests
- xts * suggests
- zoo * suggests
.github/workflows/R-CMD-check.yaml
actions
- actions/cache v2 composite
- actions/checkout v2 composite
- actions/upload-artifact main composite
- r-lib/actions/setup-pandoc v1 composite
- r-lib/actions/setup-r v1 composite