I wish to compute transfer entropy in a JupyterLab notebook by calling R's RTransferEntropy package using rpy2 but am encountering problems doing so.
I'm using Anaconda with Python 3.7 and have RStudio installed as one of my environments. Within RStudio I've successfully implemented an example found in the RTransferEntropy package:
install.packages('RTransferEntropy')
library(RTransferEntropy)
set.seed(12345)
n <- 2500
x <- rep(0, n + 1)
y <- rep(0, n + 1)
for (i in 2:(n + 1)) {
x[i] <- 0.2 * x[i - 1] + rnorm(1, 0, 2)
y[i] <- x[i - 1] + rnorm(1, 0, 2)}
x <- x[-1]
y <- y[-1]
library(future)
plan(multiprocess)
set.seed(12345)
shannon_te <- transfer_entropy(x, y)
shannon_te
Everything works find and I'm able to obtain the correct results shown in the documentation.
Now I wish to use rpy2. Here's what I enter in my Jupyter notebook:
from rpy2.robjects.packages import importr
base = importr('base')
utils = importr('utils')
te=rpackages.importr('RTransferEntropy')
I've tried importing just the first two R packages, and have done so with no difficulty. However, when trying to import RTransferEntropy, I receive a lengthy error message, the last few lines being as follows:
RRuntimeError: Error in loadNamespace(name) :
there is no package called ‘RTransferEntropy’
Calls: <Anonymous> ... tryCatch -> tryCatchList -> tryCatchOne ->
<Anonymous>
I'm not sure what's causing the error. Is it perhaps because RTransferEntropy is not in the correct directory?
Also, I do realize there exist transfer entropy computation methods for direct use in Python, e.g. NPEET and JIDT. However, I've been unsuccessful in getting them up and running.