ResidualPredictionTest {CondIndTests} | R Documentation |
Residual prediction test.
Description
Tests the null hypothesis that Y and E are independent given X.
Usage
ResidualPredictionTest(Y, E, X, alpha = 0.05, verbose = FALSE,
degree = 4, basis = c("nystrom", "nystrom_poly", "fourier",
"polynomial", "provided")[1], resid_type = "OLS", XBasis = NULL,
noiseMat = NULL, getnoiseFct = function(n, ...) { rnorm(n) },
argsGetNoiseFct = NULL, nSim = 100, funcOfRes = function(x) {
abs(x) }, useX = TRUE, returnXBasis = FALSE,
nSub = ceiling(NROW(X)/4), ntree = 100, nodesize = 5,
maxnodes = NULL)
Arguments
Y |
An n-dimensional vector. |
E |
An n-dimensional vector or an nxq dimensional matrix or dataframe. |
X |
A matrix or dataframe with n rows and p columns. |
alpha |
Significance level. Defaults to 0.05. |
verbose |
If |
degree |
Degree of polynomial to use if |
basis |
Can be one of |
resid_type |
Can be |
XBasis |
Basis if |
noiseMat |
Matrix with simulated noise. Defaults to NULL in which case the simulation is performed inside the function. |
getnoiseFct |
Function to use to generate the noise matrix. Defaults to |
argsGetNoiseFct |
Arguments for |
nSim |
Number of simulations to use. Defaults to 100. |
funcOfRes |
Function of residuals to use in addition to predicting the
conditional mean. Defaults to |
useX |
Set to |
returnXBasis |
Set to |
nSub |
Number of random features to use if |
ntree |
Random forest parameter: Number of trees to grow. Defaults to 500. |
nodesize |
Random forest parameter: Minimum size of terminal nodes. Defaults to 5. |
maxnodes |
Random forest parameter: Maximum number of terminal nodes trees in the forest can have. Defaults to NULL. |
Value
A list with the following entries:
-
pvalue
The p-value for the null hypothesis that Y and E are independent given X. -
XBasis
Basis expansion ifreturnXBasis
was set toTRUE
. -
fctBasisExpansion
Function used to create basis expansion if basis is not"provided"
.
Examples
# Example 1
n <- 100
E <- rbinom(n, size = 1, prob = 0.2)
X <- 4 + 2 * E + rnorm(n)
Y <- 3 * (X)^2 + rnorm(n)
ResidualPredictionTest(Y, as.factor(E), X)
# Example 2
E <- rbinom(n, size = 1, prob = 0.2)
X <- 4 + 2 * E + rnorm(n)
Y <- 3 * E + rnorm(n)
ResidualPredictionTest(Y, as.factor(E), X)
# not run:
# # Example 3
# E <- rnorm(n)
# X <- 4 + 2 * E + rnorm(n)
# Y <- 3 * (X)^2 + rnorm(n)
# ResidualPredictionTest(Y, E, X)
# ResidualPredictionTest(Y, X, E)