Description Usage Arguments Value Examples
View source: R/transferentropy.R
Compute the local or average transfer entropy from one time series ys
to another xs
with target history length k
conditioned on the
background ws
.
1 | transfer_entropy(ys, xs, ws = NULL, k, local = FALSE)
|
ys |
Vector or matrix specifying one or more source time series. |
xs |
Vector or matrix specifying one or more destination time series. |
ws |
Vector or matrix specifying one or more background time series. |
k |
Integer giving the history length. |
local |
Boolean specifying whether to compute the local transfer entropy. |
Numeric giving the average transfer entropy or a vector giving the local transfer entropy.
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 | ######################################################################
# The typical usage is to provide the time series and the history length.
xs <- c(0, 0, 1, 1, 1, 1, 0, 0, 0)
ys <- c(0, 1, 1, 1, 1, 0, 0, 0, 1)
transfer_entropy(ys, xs, k = 1) # 0.8112781
transfer_entropy(ys, xs, k = 2) # 0.6792696
transfer_entropy(xs, ys, k = 1) # 0.2169172
transfer_entropy(xs, ys, k = 2) # 0
# [1] 0.4150375, 2.0, 0.4150375, 0.4150375, 0.4150375, 2.0, 0.4150375,
# 0.4150375
transfer_entropy(ys, xs, k = 1, local = TRUE)
# [1] 1.0, 0.0, 0.5849625, 0.5849625, 1.5849625, 0.0, 1.0
transfer_entropy(ys, xs, k = 2, local = TRUE)
# [1] 0.4150375, 0.4150375, -0.169925, -0.169925, 0.4150375, 1.0,
# -0.5849625, 0.4150375
transfer_entropy(xs, ys, k = 1, local = TRUE)
# [1] 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0
transfer_entropy(xs, ys, k = 2, local = TRUE)
# Multiple Initial Conditions
xs <- matrix(0, nrow = 9, ncol = 2)
xs[, 1] <- c(0, 0, 1, 1, 1, 1, 0, 0, 0)
xs[, 2] <- c(1, 0, 0, 0, 0, 1, 1, 1, 0)
ys <- matrix(0, nrow = 9, ncol = 2)
ys[, 1] <- c(1, 0, 0, 0, 0, 1, 1, 1, 1)
ys[, 2] <- c(1, 1, 1, 1, 0, 0, 0, 1, 1)
transfer_entropy(ys, xs, k = 1) # 0.8828561
transfer_entropy(ys, xs, k = 2) # 0.6935361
transfer_entropy(xs, ys, k = 1) # 0.1596973
transfer_entropy(xs, ys, k = 2) # 0.0
# [, 1] 0.4150375, 2.0, 0.67807191, 0.67807191, 0.67807191, 1.4150375,
# 0.4150375, 0.4150375
# [, 2] 1.4150375, 0.4150375, 0.4150375, 0.4150375, 2.0, 0.67807191,
# 0.67807191, 1.4150375
transfer_entropy(ys, xs, k = 1, local = TRUE)
# [, 1] 1.32192809, 0.0, 0.73696559, 0.73696559, 1.32192809, 0.0,
# 0.73696559
# [, 2] 0.0, 0.73696559, 0.73696559, 1.32192809, 0.0, 0.73696559,
# 1.32192809
transfer_entropy(ys, xs, k = 2, local = TRUE)
# [, 1] 0.5849625, 0.48542683, -0.25153877, -0.25153877, 0.48542683,
# 0.36257008, -0.22239242, -0.22239242
# [, 2] 0.36257008, -0.22239242, -0.22239242, 0.5849625, 0.48542683,
# -0.25153877, 0.48542683, 0.36257008
transfer_entropy(xs, ys, k = 1, local = TRUE)
# [, 1] 0.000000e+00, -2.220446e-16, -2.220446e-16, -2.220446e-16,
# 0.000000e+00, -2.220446e-16, -2.220446e-16
# [, 2] -2.220446e-16, -2.220446e-16, -2.220446e-16, 0.000000e+00,
# -2.220446e-16, -2.220446e-16, 0.000000e+00
transfer_entropy(xs, ys, k = 2, local = TRUE)
# With a background process
xs <- c(0, 1, 1, 1, 1, 0, 0, 0, 0)
ys <- c(0, 0, 1, 1, 1, 1, 0, 0, 0)
ws <- matrix(c(1, 0, 1, 0, 1, 1, 1, 1, 1,
1, 1, 0, 1, 0, 1, 1, 1, 1), ncol = 2)
transfer_entropy(xs, ys, ws, k = 2) # 0
# [, 1] 0, 0, 0, 0, 0, 0, 0, 0, 0
te <- transfer_entropy(xs, ys, ws, k = 2, local = TRUE)
t(te)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.