kgcm: Kernel generalised covariance measure test

View source: R/kgcm.R

kgcmR Documentation

Kernel generalised covariance measure test

Description

Kernel generalised covariance measure test

Usage

kgcm(
  Y,
  X,
  Z,
  reg_YonZ = "rf",
  reg_XonZ = "rf",
  args_YonZ = NULL,
  args_XonZ = NULL,
  B = 499L,
  return_fitted_models = FALSE,
  multivariate = c("none", "XonZ"),
  bandwidth = NULL,
  ...
)

Arguments

Y

Vector of response values.

X

Matrix or data.frame of covariates.

Z

Matrix or data.frame of covariates.

reg_YonZ

Character string or function specifying the regression for Y on Z. See ?regressions for more detail.

reg_XonZ

Character string or function specifying the regression for X on Z. See ?regressions for more detail.

args_YonZ

A list of named arguments passed to reg_YonZ.

args_XonZ

A list of named arguments passed to reg_XonZ.

B

Number of wild bootstrap samples.

return_fitted_models

Logical; whether to return the fitted regressions (default is FALSE).

multivariate

Character; specifying which regression can handle multivariate outcomes ("none", or "XonZ"). If "none", then the regression is run using each column in X as the response.

bandwidth

Numeric; value of the bandwidth for the Gaussian kernel. Defaults to NULL, corresponding to the median heuristic.

...

Currently ignored

Details

The kernelized generalised covariance measure test tests whether the weighted conditional covariance of Y and X given Z is zero.

Value

Object of class 'kgcm' and 'htest' with the following components:

statistic

The value of the test statistic.

p.value

The p-value for the hypothesis

parameter

In case X is multidimensional, this is the degrees of freedom used for the chi-squared test.

hypothesis

String specifying the null hypothesis.

null.value

String specifying the null hypothesis.

method

The string "Generalised covariance measure test".

data.name

A character string giving the name(s) of the data.

rY

Residuals for the Y on Z regression.

rX

Residuals for the X on Z regression.

models

List of fitted regressions if return_fitted_models is TRUE.

References

Fernández, T., & Rivera, N. (2024). A general framework for the analysis of kernel-based tests. Journal of Machine Learning Research, 25(95), 1-40.

Examples

n <- 1e2
X <- matrix(rnorm(2 * n), ncol = 2)
colnames(X) <- c("X1", "X2")
Z <- matrix(rnorm(2 * n), ncol = 2)
colnames(Z) <- c("Z1", "Z2")
Y <- X[, 2]^2 + Z[, 2] + rnorm(n)
(gcm1 <- kgcm(Y, X, Z))


comets documentation built on Nov. 5, 2025, 5:09 p.m.

Related to kgcm in comets...