| Title: | Information-Theoretic Measures for Revealing Variable Interactions |
|---|---|
| Description: | Implements information-theoretic measures to explore variable interactions, including KSG mutual information estimation for continuous variables from Kraskov et al. (2004) <doi:10.1103/PhysRevE.69.066138>, knockoff conditional mutual information described in Zhang & Chen (2025) <doi:10.1126/sciadv.adu6464>, synergistic-unique-redundant decomposition introduced by Martinez-Sanchez et al. (2024) <doi:10.1038/s41467-024-53373-4>, and information imbalance gain following Del Tatto et al. (2024) <doi:10.1073/pnas.2317256121>, allowing detection of complex and diverse relationships among variables. |
| Authors: | Wenbo Lyu [aut, cre, cph] (ORCID: <https://orcid.org/0009-0002-6003-3800>) |
| Maintainer: | Wenbo Lyu <[email protected]> |
| License: | GPL-3 |
| Version: | 0.4 |
| Built: | 2026-10-03 08:35:37 UTC |
| Source: | https://github.com/stscl/infoxtr |
Conditional Entropy
ce(data, target, conds, base = exp(1), type = c("cont", "disc"), k = 3)ce(data, target, conds, base = exp(1), type = c("cont", "disc"), k = 3)
data |
Observation data. |
target |
Integer vector of column indices for the target variables. |
conds |
Integer vector of column indices for the conditioning variables. |
base |
(optional) Logarithm base of the entropy.
Defaults to |
type |
(optional) Estimation method:
|
k |
(optional) Number of nearest neighbors used by the continuous estimator.
Ignored when |
A numerical value.
infoxtr::ce(matrix(1:100,ncol=2),1,2)infoxtr::ce(matrix(1:100,ncol=2),1,2)
Conditional Mutual Information
cmi( data, target, interact, conds, base = exp(1), type = c("cont", "disc"), k = 3, normalize = FALSE )cmi( data, target, interact, conds, base = exp(1), type = c("cont", "disc"), k = 3, normalize = FALSE )
data |
Observation data. |
target |
Integer vector of column indices for the target variables. |
interact |
Integer vector of column indices for the interacting variables. |
conds |
Integer vector of column indices for the conditioning variables. |
base |
(optional) Logarithm base of the entropy.
Defaults to |
type |
(optional) Estimation method:
|
k |
(optional) Number of nearest neighbors used by the continuous estimator.
Ignored when |
normalize |
(optional) Logical; if |
A numerical value.
set.seed(42) infoxtr::cmi(matrix(stats::rnorm(99,1,10),ncol=3),1,2,3)set.seed(42) infoxtr::cmi(matrix(stats::rnorm(99,1,10),ncol=3),1,2,3)
Discretization
discretize( x, n = 5, method = "natural", large = 3000, prop = 0.15, seed = 42, thr = 0.4, iter = 100, bps = NULL, right_closed = TRUE )discretize( x, n = 5, method = "natural", large = 3000, prop = 0.15, seed = 42, thr = 0.4, iter = 100, bps = NULL, right_closed = TRUE )
x |
A vector. |
n |
(optional) Number of classes. |
method |
(optional) Discretization method. One of
|
large |
(optional) Threshold sample size for natural breaks sampling. |
prop |
(optional) Sampling proportion used when |
seed |
(optional) Random seed used for sampling in natural breaks. |
thr |
(optional) Threshold used in the head/tail breaks algorithm. |
iter |
(optional) Maximum number of iterations for head/tail breaks. |
bps |
(optional) Numeric vector of manual breakpoints used when
|
right_closed |
(optional) Logical. If |
A discretized integer vector.
If x is not numeric, or if the number of unique non-NA values
is less than or equal to n (except for the "headtail"("headtails") method),
the function falls back to integer encoding via as.factor().
In all cases, missing values (NA/NaN) are ignored and returned as class 0.
set.seed(42) infoxtr::discretize(stats::rnorm(99,1,10))set.seed(42) infoxtr::discretize(stats::rnorm(99,1,10))
Shannon Entropy
entropy(vec, base = exp(1), type = c("cont", "disc"), k = 3)entropy(vec, base = exp(1), type = c("cont", "disc"), k = 3)
vec |
A vector. |
base |
(optional) Logarithm base of the entropy.
Defaults to |
type |
(optional) Estimation method:
|
k |
(optional) Number of nearest neighbors used by the continuous estimator.
Ignored when |
A numerical value.
set.seed(42) infoxtr::entropy(stats::rnorm(100), type = "cont") infoxtr::entropy(sample(letters[1:5], 100, TRUE), base = 2, type = "disc")set.seed(42) infoxtr::entropy(stats::rnorm(100), type = "cont") infoxtr::entropy(sample(letters[1:5], 100, TRUE), base = 2, type = "disc")
Imbalance Gain
imbalance_gain( mx, my, alpha = seq(0, 1, 0.1), lib = NULL, pred = NULL, h = 1, k = 3, threads = 1, method = "euclidean" )imbalance_gain( mx, my, alpha = seq(0, 1, 0.1), lib = NULL, pred = NULL, h = 1, k = 3, threads = 1, method = "euclidean" )
mx |
Numeric matrix of hypothesised driving variable measurements. |
my |
Numeric matrix of hypothesised response variable measurements. |
alpha |
(optional) Scaling parameter weighting the putative driver measurements. |
lib |
(optional) Library indices. |
pred |
(optional) Prediction indices. |
h |
(optional) Prediction horizon. |
k |
(optional) Number of nearest neighbors when estimating ranks. |
threads |
(optional) Number of parallel threads. |
method |
(optional) Distance measure to be used: |
A numeric vector.
Del Tatto, V., Fortunato, G., Bueti, D., Laio, A., 2024. Robust inference of causality in high-dimensional dynamical processes from the Information Imbalance of distance ranks. Proceedings of the National Academy of Sciences 121.
set.seed(42) mx = embed(rnorm(100), 3) my = embed(rnorm(100), 3) infoxtr::imbalance_gain(mx, my)set.seed(42) mx = embed(rnorm(100), 3) my = embed(rnorm(100), 3) infoxtr::imbalance_gain(mx, my)
Information Imbalance
info_imbalance( mx, my, lib = NULL, pred = NULL, k = 1, threads = 1, method = "euclidean" )info_imbalance( mx, my, lib = NULL, pred = NULL, k = 1, threads = 1, method = "euclidean" )
mx |
Numeric matrix of hypothesised driving variable measurements. |
my |
Numeric matrix of hypothesised response variable measurements. |
lib |
(optional) Library indices. |
pred |
(optional) Prediction indices. |
k |
(optional) Number of nearest neighbors when estimating ranks. |
threads |
(optional) Number of parallel threads. |
method |
(optional) Distance measure to be used: |
A numeric value.
Glielmo, A., Zeni, C., Cheng, B., Csanyi, G., Laio, A., 2022. Ranking the information content of distance measures. PNAS Nexus 1.
set.seed(42) mx = embed(rnorm(100), 3) my = embed(rnorm(100), 3) infoxtr::info_imbalance(mx, my)set.seed(42) mx = embed(rnorm(100), 3) my = embed(rnorm(100), 3) infoxtr::info_imbalance(mx, my)
Joint Entropy
je(data, indices, base = exp(1), type = c("cont", "disc"), k = 3)je(data, indices, base = exp(1), type = c("cont", "disc"), k = 3)
data |
Observation data. |
indices |
Integer vector of column indices to include in joint entropy calculation. |
base |
(optional) Logarithm base of the entropy.
Defaults to |
type |
(optional) Estimation method:
|
k |
(optional) Number of nearest neighbors used by the continuous estimator.
Ignored when |
A numerical value.
infoxtr::je(matrix(1:100,ncol=2),1:2)infoxtr::je(matrix(1:100,ncol=2),1:2)
Knockoff Conditional Mutual Information
kocmi( data, target, agent, conds, knockoff, null_knockoff = NULL, type = c("cont", "disc"), nboots = 10000, k = 3, threads = 1, seed = 42, base = exp(1), method = "equal", contain_null = TRUE )kocmi( data, target, agent, conds, knockoff, null_knockoff = NULL, type = c("cont", "disc"), nboots = 10000, k = 3, threads = 1, seed = 42, base = exp(1), method = "equal", contain_null = TRUE )
data |
Observation data. |
target |
Integer vector of column indices for the target variables. |
agent |
Integer vector of column indices for the agent variables. |
conds |
Integer vector of column indices for the conditioning variables. |
knockoff |
Knockoff realizations constructed for the |
null_knockoff |
(optional) Knockoff realizations generated under the
null setting where all variables are jointly used to construct knockoffs.
Each column represents one Monte Carlo sample. If |
type |
(optional) Estimation method: |
nboots |
(optional) Number of permutations used in the sign-flipping permutation test for evaluating the significance of the mean information difference. |
k |
(optional) For |
threads |
(optional) Number of threads used. |
seed |
(optional) Random seed used for permutation test. |
base |
(optional) Logarithm base of the entropy.
Defaults to |
method |
(optional) Discretization method. One of
|
contain_null |
(optional) Logical. If |
A named numeric vector.
kocmi only support numeric data.
Zhang, X., Chen, L., 2025. Quantifying interventional causality by knockoff operation. Science Advances 11.
set.seed(42) kn1 = replicate(50, stats::rnorm(100)) kn2 = replicate(50, stats::rnorm(100)) mat = replicate(3, stats::rnorm(100)) infoxtr::kocmi(mat, 1, 2, 3, kn1, kn2)set.seed(42) kn1 = replicate(50, stats::rnorm(100)) kn2 = replicate(50, stats::rnorm(100)) mat = replicate(3, stats::rnorm(100)) infoxtr::kocmi(mat, 1, 2, 3, kn1, kn2)
Mutual Information
mi( data, target, interact, base = exp(1), type = c("cont", "disc"), k = 3, normalize = FALSE )mi( data, target, interact, base = exp(1), type = c("cont", "disc"), k = 3, normalize = FALSE )
data |
Observation data. |
target |
Integer vector of column indices for the target variables. |
interact |
Integer vector of column indices for the interacting variables. |
base |
(optional) Logarithm base of the entropy.
Defaults to |
type |
(optional) Estimation method:
|
k |
(optional) Number of nearest neighbors used by the continuous estimator.
Ignored when |
normalize |
(optional) Logical; if |
A numerical value.
infoxtr::mi(matrix(1:100,ncol=2),1,2)infoxtr::mi(matrix(1:100,ncol=2),1,2)
Synergistic-Unique-Redundant Decomposition
## S4 method for signature 'data.frame' surd( data, target, agent, lag = 1, bin = 5, method = "equal", max.order = 10, threads = 1, base = 2, normalize = TRUE ) ## S4 method for signature 'sf' surd( data, target, agent, lag = 1, bin = 5, method = "equal", max.order = 10, threads = 1, base = 2, normalize = TRUE, nb = NULL ) ## S4 method for signature 'SpatRaster' surd( data, target, agent, lag = 1, bin = 5, method = "equal", max.order = 10, threads = 1, base = 2, normalize = TRUE )## S4 method for signature 'data.frame' surd( data, target, agent, lag = 1, bin = 5, method = "equal", max.order = 10, threads = 1, base = 2, normalize = TRUE ) ## S4 method for signature 'sf' surd( data, target, agent, lag = 1, bin = 5, method = "equal", max.order = 10, threads = 1, base = 2, normalize = TRUE, nb = NULL ) ## S4 method for signature 'SpatRaster' surd( data, target, agent, lag = 1, bin = 5, method = "equal", max.order = 10, threads = 1, base = 2, normalize = TRUE )
data |
Observation data. |
target |
Integer vector of column indices for the target variables. |
agent |
Integer vector of column indices for the agent variables. |
lag |
(optional) Lag of the agent variables. |
bin |
(optional) Number of discretization bins. |
method |
(optional) Discretization method. One of
|
max.order |
(optional) Maximum combination order. |
threads |
(optional) Number of threads used. |
base |
(optional) Logarithm base of the entropy.
Defaults to |
normalize |
(optional) Logical; if |
nb |
(optional) Neighbours list. |
A list.
Character vector indicating the variable combination associated with each information component.
Character vector indicating the information type of each component.
Numeric vector giving the magnitude of each information component.
surd only supports numeric input data. Both bin and method
support variable-specific settings using R-style recycling:
length 1: applied to the target and all agent variables
length 2: first for the target, second for all agents
length > 2: first for the target, remaining values are recycled across agents
Martinez-Sanchez, A., Arranz, G., Lozano-Duran, A., 2024. Decomposing causality into its synergistic, unique, and redundant components. Nature Communications 15.
columbus = sf::read_sf(system.file("case/columbus.gpkg", package="spEDM")) infoxtr::surd(columbus, 1, 2:3)columbus = sf::read_sf(system.file("case/columbus.gpkg", package="spEDM")) infoxtr::surd(columbus, 1, 2:3)
Transfer Entropy
te( data, target, agent, lag_p = 3, lag_q = 3, base = exp(1), type = c("cont", "disc"), k = 3, normalize = FALSE, lag_single = FALSE )te( data, target, agent, lag_p = 3, lag_q = 3, base = exp(1), type = c("cont", "disc"), k = 3, normalize = FALSE, lag_single = FALSE )
data |
Observation data. |
target |
Integer vector of column indices for the target variables. |
agent |
Integer vector of column indices for the agent variables. |
lag_p |
(optional) Lag of the target variables. |
lag_q |
(optional) Lag of the agent variables. |
base |
(optional) Logarithm base of the entropy.
Defaults to |
type |
(optional) Estimation method:
|
k |
(optional) Number of nearest neighbors used by the continuous estimator.
Ignored when |
normalize |
(optional) Logical; if |
lag_single |
(optional) Logical; if |
A numerical value.
Schreiber, T., 2000. Measuring Information Transfer. Physical Review Letters 85, 461–464.
set.seed(42) infoxtr::te(matrix(stats::rnorm(100,1,10),ncol=2),1,2)set.seed(42) infoxtr::te(matrix(stats::rnorm(100,1,10),ncol=2),1,2)