From d2cca2ad1d10422d77e781f8b4655e952a9852bc Mon Sep 17 00:00:00 2001 From: SpatLyu Date: Mon, 9 Nov 2026 00:00:01 +0800 Subject: [PATCH 1/9] fix potential bug of kocmi --- R/kocmi.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/kocmi.R b/R/kocmi.R index 524df89..66de928 100644 --- a/R/kocmi.R +++ b/R/kocmi.R @@ -46,7 +46,7 @@ kocmi = \(data, target, agent, conds, knockoff, null_knockoff = NULL, type = match.arg(type) mat = .convert2mat(data, contain_type = FALSE) knockoff = .convert2mat(knockoff, contain_type = FALSE) - null_knockoff = .convert2mat(null_knockoff, contain_type = FALSE) + if (!is.null(null_knockoff)) null_knockoff = .convert2mat(null_knockoff, contain_type = FALSE) return(RcppKOCMI(mat, abs(target), abs(agent), abs(conds), knockoff, null_knockoff, type, nboots, k, 0, threads, seed, base, method, contain_null)) } From 7c0cb6ee0bd2461901307541ecb7406b88b306cd Mon Sep 17 00:00:00 2001 From: SpatLyu Date: Mon, 9 Nov 2026 00:00:01 +0800 Subject: [PATCH 2/9] polish kocmi docs --- R/kocmi.R | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/R/kocmi.R b/R/kocmi.R index 66de928..db073cc 100644 --- a/R/kocmi.R +++ b/R/kocmi.R @@ -4,10 +4,8 @@ #' #' @inheritParams surd #' @param conds Integer vector of column indices for the conditioning variables. -#' @param knockoff Knockoff realizations constructed for the `agent` variable -#' while keeping the `target` variable unchanged. Each column corresponds to -#' one Monte Carlo knockoff sample generated using the remaining variables -#' except the target. +#' @param knockoff Knockoff realizations for the `agent` variable. Each column is +#' a Monte Carlo realization generated using the `agent` and `conds` variables. #' @param 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 `contain_null = FALSE`, From a7833abdabb38c17d07c020f6a13dfc355a8eb72 Mon Sep 17 00:00:00 2001 From: SpatLyu Date: Mon, 9 Nov 2026 00:00:01 +0800 Subject: [PATCH 3/9] polish kocmi docs --- R/kocmi.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/kocmi.R b/R/kocmi.R index db073cc..fdded5b 100644 --- a/R/kocmi.R +++ b/R/kocmi.R @@ -5,7 +5,7 @@ #' @inheritParams surd #' @param conds Integer vector of column indices for the conditioning variables. #' @param knockoff Knockoff realizations for the `agent` variable. Each column is -#' a Monte Carlo realization generated using the `agent` and `conds` variables. +#' a Monte Carlo realization generated using the `agent` and `conds` variables. #' @param 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 `contain_null = FALSE`, From 7722813be772593849385b787a3c82012696aa39 Mon Sep 17 00:00:00 2001 From: SpatLyu Date: Mon, 9 Nov 2026 00:00:01 +0800 Subject: [PATCH 4/9] polish kocmi docs --- R/kocmi.R | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/R/kocmi.R b/R/kocmi.R index fdded5b..342bf8b 100644 --- a/R/kocmi.R +++ b/R/kocmi.R @@ -6,10 +6,10 @@ #' @param conds Integer vector of column indices for the conditioning variables. #' @param knockoff Knockoff realizations for the `agent` variable. Each column is #' a Monte Carlo realization generated using the `agent` and `conds` variables. -#' @param 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 `contain_null = FALSE`, -#' this argument can be `NULL`. +#' @param null_knockoff (optional) Knockoff realizations generated under the null +#' setting where all variables (`target`, `agent`, `conds`) are jointly used to +#' construct knockoffs. Each column represents one Monte Carlo realization. Must +#' be `NULL` if `contain_null = FALSE`. #' @param type (optional) Estimation method: `"disc"` for discrete mutual information #' or `"cont"` for continuous mutual information (KSG estimator). #' @param nboots (optional) Number of permutations used in the sign-flipping permutation From 5e74f198c84a7d0461db9e68e69651b06d5b6aa6 Mon Sep 17 00:00:00 2001 From: SpatLyu Date: Mon, 9 Nov 2026 00:00:01 +0800 Subject: [PATCH 5/9] polish kocmi docs --- R/kocmi.R | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/R/kocmi.R b/R/kocmi.R index 342bf8b..0305b73 100644 --- a/R/kocmi.R +++ b/R/kocmi.R @@ -15,16 +15,12 @@ #' @param nboots (optional) Number of permutations used in the sign-flipping permutation #' test for evaluating the significance of the mean information difference. ##' @param k (optional) For `type = "cont"`, the number of nearest neighbors used by -#' the continuous conditional mutual information estimator. -#' For `type = "disc"`, the number of bins used for discretization. +#' the continuous conditional mutual information estimator. For `type = "disc"`, the +#' number of bins used for discretization. #' @param seed (optional) Random seed used for permutation test. #' @param contain_null (optional) Logical. If `TRUE`, the test statistic is -#' computed using knockoffs generated under the null model (provided in -#' `null_knockoff`). In this case the difference is defined as -#' \eqn{I(Y; X_{null} | Z) - I(Y; X_{knockoff} | Z)}. -#' If `FALSE`, the original conditional mutual information -#' \eqn{I(Y; X | Z)} is used instead and compared against the knockoff -#' estimates \eqn{I(Y; X_{knockoff} | Z)}. +#' computed as $I(Y; X_{null} | Z) - I(Y; X_{knockoff} | Z)$. +#' If `FALSE`, it is computed as $I(Y; X | Z) - I(Y; X_{knockoff} | Z)$. #' #' @returns A named numeric vector. #' @export From 39fc85637545d457dd6da471ba0e1220ce627bda Mon Sep 17 00:00:00 2001 From: SpatLyu Date: Mon, 9 Nov 2026 00:00:01 +0800 Subject: [PATCH 6/9] polish kocmi docs --- man/kocmi.Rd | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/man/kocmi.Rd b/man/kocmi.Rd index 86d4f84..4e7fb49 100644 --- a/man/kocmi.Rd +++ b/man/kocmi.Rd @@ -30,15 +30,13 @@ kocmi( \item{conds}{Integer vector of column indices for the conditioning variables.} -\item{knockoff}{Knockoff realizations constructed for the \code{agent} variable -while keeping the \code{target} variable unchanged. Each column corresponds to -one Monte Carlo knockoff sample generated using the remaining variables -except the target.} +\item{knockoff}{Knockoff realizations for the \code{agent} variable. Each column is +a Monte Carlo realization generated using the \code{agent} and \code{conds} variables.} -\item{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 \code{contain_null = FALSE}, -this argument can be \code{NULL}.} +\item{null_knockoff}{(optional) Knockoff realizations generated under the null +setting where all variables (\code{target}, \code{agent}, \code{conds}) are jointly used to +construct knockoffs. Each column represents one Monte Carlo realization. Must +be \code{NULL} if \code{contain_null = FALSE}.} \item{type}{(optional) Estimation method: \code{"disc"} for discrete mutual information or \code{"cont"} for continuous mutual information (KSG estimator).} @@ -47,8 +45,8 @@ or \code{"cont"} for continuous mutual information (KSG estimator).} test for evaluating the significance of the mean information difference.} \item{k}{(optional) For \code{type = "cont"}, the number of nearest neighbors used by -the continuous conditional mutual information estimator. -For \code{type = "disc"}, the number of bins used for discretization.} +the continuous conditional mutual information estimator. For \code{type = "disc"}, the +number of bins used for discretization.} \item{threads}{(optional) Number of threads used.} @@ -62,12 +60,8 @@ Defaults to \code{exp(1)} (nats). Use \code{2} for bits or \code{10} for dits.} \verb{"natural("jenks")"}, or \code{"headtail"("headtails")}.} \item{contain_null}{(optional) Logical. If \code{TRUE}, the test statistic is -computed using knockoffs generated under the null model (provided in -\code{null_knockoff}). In this case the difference is defined as -\eqn{I(Y; X_{null} | Z) - I(Y; X_{knockoff} | Z)}. -If \code{FALSE}, the original conditional mutual information -\eqn{I(Y; X | Z)} is used instead and compared against the knockoff -estimates \eqn{I(Y; X_{knockoff} | Z)}.} +computed as $I(Y; X_{null} | Z) - I(Y; X_{knockoff} | Z)$. +If \code{FALSE}, it is computed as $I(Y; X | Z) - I(Y; X_{knockoff} | Z)$.} } \value{ A named numeric vector. From 6e361f59fe2c814bf85fefae048c0af0002fe28c Mon Sep 17 00:00:00 2001 From: SpatLyu Date: Mon, 9 Nov 2026 00:00:01 +0800 Subject: [PATCH 7/9] polish kocmi docs --- R/kocmi.R | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/R/kocmi.R b/R/kocmi.R index 0305b73..2f0026b 100644 --- a/R/kocmi.R +++ b/R/kocmi.R @@ -18,9 +18,9 @@ #' the continuous conditional mutual information estimator. For `type = "disc"`, the #' number of bins used for discretization. #' @param seed (optional) Random seed used for permutation test. -#' @param contain_null (optional) Logical. If `TRUE`, the test statistic is -#' computed as $I(Y; X_{null} | Z) - I(Y; X_{knockoff} | Z)$. -#' If `FALSE`, it is computed as $I(Y; X | Z) - I(Y; X_{knockoff} | Z)$. +#' @param contain_null (optional) Logical. If `TRUE`, the test statistic is computed as +#' \eqn{I(Y; X_{null} | Z) - I(Y; X_{knockoff} | Z)}. If `FALSE`, it is computed as +#' \eqn{I(Y; X | Z) - I(Y; X_{knockoff} | Z)}. #' #' @returns A named numeric vector. #' @export From 61936bcbb9e36065934a36f6505c53e3896b1185 Mon Sep 17 00:00:00 2001 From: SpatLyu Date: Mon, 9 Nov 2026 00:00:01 +0800 Subject: [PATCH 8/9] polish kocmi docs --- man/kocmi.Rd | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/man/kocmi.Rd b/man/kocmi.Rd index 4e7fb49..dc2fcef 100644 --- a/man/kocmi.Rd +++ b/man/kocmi.Rd @@ -59,9 +59,9 @@ Defaults to \code{exp(1)} (nats). Use \code{2} for bits or \code{10} for dits.} \code{"sd"}, \code{"equal"}, \code{"geometric"}, \code{"quantile"}, \verb{"natural("jenks")"}, or \code{"headtail"("headtails")}.} -\item{contain_null}{(optional) Logical. If \code{TRUE}, the test statistic is -computed as $I(Y; X_{null} | Z) - I(Y; X_{knockoff} | Z)$. -If \code{FALSE}, it is computed as $I(Y; X | Z) - I(Y; X_{knockoff} | Z)$.} +\item{contain_null}{(optional) Logical. If \code{TRUE}, the test statistic is computed as +\eqn{I(Y; X_{null} | Z) - I(Y; X_{knockoff} | Z)}. If \code{FALSE}, it is computed as +\eqn{I(Y; X | Z) - I(Y; X_{knockoff} | Z)}.} } \value{ A named numeric vector. From f0294009a4df83ad4d811bef5c6abfcf525f23d4 Mon Sep 17 00:00:00 2001 From: SpatLyu Date: Mon, 9 Nov 2026 00:00:01 +0800 Subject: [PATCH 9/9] polish kocmi docs --- R/kocmi.R | 2 +- man/kocmi.Rd | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/R/kocmi.R b/R/kocmi.R index 2f0026b..6e31042 100644 --- a/R/kocmi.R +++ b/R/kocmi.R @@ -35,7 +35,7 @@ #' infoxtr::kocmi(mat, 1, 2, 3, kn1, kn2) #' kocmi = \(data, target, agent, conds, knockoff, null_knockoff = NULL, - type = c("cont", "disc"), nboots = 1e4, k = 3, threads = 1, + type = c("cont", "disc"), nboots = 1e2, k = 3, threads = 1, seed = 42, base = exp(1), method = "equal", contain_null = TRUE) { type = match.arg(type) mat = .convert2mat(data, contain_type = FALSE) diff --git a/man/kocmi.Rd b/man/kocmi.Rd index dc2fcef..e0cfb62 100644 --- a/man/kocmi.Rd +++ b/man/kocmi.Rd @@ -12,7 +12,7 @@ kocmi( knockoff, null_knockoff = NULL, type = c("cont", "disc"), - nboots = 10000, + nboots = 100, k = 3, threads = 1, seed = 42,