E: An n-dimensional vector. If test = propTestTargetE, E needs to be a factor.
X: A matrix or dataframe with n rows and p columns.
alpha: Significance level. Defaults to 0.05.
verbose: If TRUE, intermediate output is provided. Defaults to FALSE.
trainTestSplitFunc: Function to split sample. Defaults to stratified sampling using caTools::sample.split, assuming E is a factor.
argsTrainTestSplitFunc: Arguments for sampling splitting function.
test: Unconditional independence test that tests whether the out-of-sample prediction accuracy is the same when using X only vs. X and Y as predictors for E. Defaults to propTestTargetE.
mtry: Random forest parameter: Number of variables randomly sampled as candidates at each split. Defaults to sqrt(NCOL(X)).
ntree: Random forest parameter: Number of trees to grow. Defaults to 100.
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.
permute: Random forest parameter: If TRUE, model that would use X only for predicting Y also includes a random permutation of E. Defaults to TRUE.
returnModel: If TRUE, the fitted quantile regression forest model will be returned. Defaults to FALSE.
Returns
A list with the following entries:
pvalue The p-value for the null hypothesis that Y and E are independent given X.
model The fitted models if returnModel = TRUE.
Examples
# Example 1n <-1000E <- rbinom(n, size =1, prob =0.2)X <-4+2* E + rnorm(n)Y <-3*(X)^2+ rnorm(n)InvariantEnvironmentPrediction(Y, as.factor(E), X)# Example 2E <- rbinom(n, size =1, prob =0.2)X <-4+2* E + rnorm(n)Y <-3* E + rnorm(n)InvariantEnvironmentPrediction(Y, as.factor(E), X)# Example 3E <- rnorm(n)X <-4+2* E + rnorm(n)Y <-3*(X)^2+ rnorm(n)InvariantEnvironmentPrediction(Y, E, X, test = wilcoxTestTargetY)InvariantEnvironmentPrediction(Y, X, E, test = wilcoxTestTargetY)