BZPaper / RTransferEntropy

Code to implement transfer entropy (Shannon and Renyi)
GNU General Public License v3.0
20 stars 10 forks source link

Error in transfer_entropy with bootstrap #60

Open jjantunes opened 7 months ago

jjantunes commented 7 months ago

Dear David, I'm encountering issues with the transfer entropy function, more specifically with the bootstrap. When I execute the function, I get the following response:

Error in sample.int(length(x), size, replace, prob) : invalid first argument

This same error was reported on StackOverflow (https://stackoverflow.com/questions/71013871/rtransferentropy-error-in-sample-intlengthx-size-replace-prob-invalid) and marked as resolved in issue #58 (https://github.com/BZPaper/RTransferEntropy/issues/58).

I did some tests and found that I get this error when I increase the number of lags to above 4. Another test showed that if I reduce the number of bootstraps to below 6, the function is able to execute.

The reproducible example is below.

Thank you for the help. Jorge Antunes

## library
library(RTransferEntropy)

##  Variable x
var_x <- c(0.07938148, 0.07993439, 0.08046067, 0.08096363, 0.08144655, 0.08191270, 0.08236533, 0.08280769,
           0.08324300, 0.08367448, 0.08410532, 0.08453873, 0.08497786, 0.08542368, 0.08586833, 0.08630178,
           0.08671404, 0.08709514, 0.08743517, 0.08772424, 0.08795247, 0.08810999, 0.08818694, 0.08817344,
           0.08805959, 0.08783702, 0.08750358, 0.08705864, 0.08650152, 0.08583151, 0.08504785, 0.08414978,
           0.08313651, 0.08200723, 0.08076117, 0.07939760, 0.07791583, 0.07631528, 0.07459552, 0.07275632,
           0.07079771, 0.06872012, 0.06652447, 0.06421236, 0.06178634, 0.05925017, 0.05660931, 0.05387155,
           0.05104787, 0.04815998, 0.04525974, 0.04240926, 0.03967389, 0.03712064, 0.03481509, 0.03281626,
           0.03116963, 0.02989927, 0.02900168, 0.02844409, 0.02816897, 0.02810258, 0.02816890, 0.02830953,
           0.02847068, 0.02863154, 0.02879209, 0.02895226, 0.02911202, 0.02927131, 0.02943010, 0.02958834,
           0.02974599, 0.02990301, 0.03005937, 0.03021505, 0.03037003, 0.03052429, 0.03067805, 0.03083184,
           0.03098528, 0.03113816, 0.03129031, 0.03144160, 0.03159194, 0.03174125, 0.03188948, 0.03203658,
           0.03218253, 0.03232733, 0.03247096, 0.03261344, 0.03275476, 0.03289494, 0.03303399, 0.03317193,
           0.03330877, 0.03344453, 0.03357928, 0.03371312, 0.03384611, 0.03397834, 0.03410988, 0.03424082,
           0.03437122, 0.03450115, 0.03463069, 0.03475990, 0.03488885) 

## Variable y
var_y <- c(0.6168736, 0.6168036, 0.6167335, 0.6166635, 0.6165934, 0.6165232, 0.6164531, 0.6163828, 0.6163126,
           0.6162422, 0.6161718, 0.6161013, 0.6160307, 0.6159600, 0.6158892, 0.6158184, 0.6157474, 0.6156764,
           0.6156054, 0.6155344, 0.6154633, 0.6153922, 0.6153211, 0.6152500, 0.6151789, 0.6151079, 0.6150370,
           0.6149664, 0.6148960, 0.6148261, 0.6147568, 0.6146880, 0.6146200, 0.6145528, 0.6144866, 0.6144214,
           0.6143573, 0.6142944, 0.6142329, 0.6141728, 0.6141142, 0.6140573, 0.6140021, 0.6139486, 0.6138972,
           0.6138477, 0.6138004, 0.6137552, 0.6137124, 0.6136720, 0.6136341, 0.6135988, 0.6135661, 0.6135361,
           0.6135088, 0.6134845, 0.6134630, 0.6134445, 0.6134291, 0.6134169, 0.6134078, 0.6134020, 0.6133996,
           0.6134006, 0.6134050, 0.6134130, 0.6134245, 0.6134397, 0.6134585, 0.6134811, 0.6135075, 0.6135378,
           0.6135721, 0.6136103, 0.6136526, 0.6136991, 0.6137500, 0.6138053, 0.6138651, 0.6139295, 0.6139987,
           0.6140728, 0.6141518, 0.6142359, 0.6143253, 0.6144199, 0.6145199, 0.6146255, 0.6147367, 0.6148536,
           0.6149765, 0.6151053, 0.6152402, 0.6153813, 0.6155287, 0.6156826, 0.6158431, 0.6160101, 0.6161839,
           0.6163644, 0.6165516, 0.6167455, 0.6169460, 0.6171534, 0.6173674, 0.6175882, 0.6178158, 0.6180501,
           0.6182912)

## transfer entropy
res_te <- transfer_entropy(x = var_x, y = var_y, lx = 6, ly = 6, nboot = 1000)