Test for no adverse shift via class probabilities for two-sample comparison. The scores are out-of-bag predictions from random forests with the package ranger. The prefix cp stands for class probability, whether the instance belongs to the training or test set. The probability of belonging to the test set is the relevant notion of outlyingness.

cp_at(x_train, x_test, R = 1000, num_trees = 500, sub_ratio = 1/2)

Arguments

x_train

Training sample.

x_test

Test sample.

R

The number of permutations. May be ignored.

num_trees

The number of trees in random forests.

sub_ratio

Subsampling ratio for sample splitting. May be ignored.

Value

A named list or object of class outlier.test containing:

  • statistic: observed WAUC statistic

  • seq_mct: sequential Monte Carlo test, if applicable

  • p_value: p-value

  • outlier_scores: outlier scores from training and test set

Details

The suffix at refers to the asymptotic test statistic. This variant uses the asymptotic null distribution for the weighted AUC (WAUC), the test statistic. Li & Fine (2010) derives its null distribution. This approximation is reliable in large sample; otherwise, prefer permutations for inference. The example below uses datasets with small samples, which is generally not advisable, is for illustration only.

Notes

Please see references for the classifier two-sample test, the inspiration behind this approach. Note that Ciemencon et al. (2009) uses both sample splitting for inference and the AUC, rather than the WAUC. Most supervised method for binary classification can replace random forests, the default in this implementation.

References

Kamulete, V. M. (2021). Test for non-negligible adverse shifts. arXiv preprint arXiv:2107.02990.

Ciemencon, S., Depecker, M., & Vayatis, N. (2009, December). AUC optimization and the two-sample problem. In Proceedings of the 22nd International Conference on Neural Information Processing Systems (pp. 360-368).

Lopez-Paz, D., & Oquab, M. (2016). Revisiting classifier two-sample tests. arXiv preprint arXiv:1610.06545.

Friedman, J. (2004). On multivariate goodness-of-fit and two-sample testing.

Gandy, A. (2009). Sequential implementation of Monte Carlo tests with uniformly bounded resampling risk. Journal of the American Statistical Association, 104(488), 1504-1511.

Li, J., & Fine, J. P. (2010). Weighted area under the receiver operating characteristic curve and its application to gene selection. Journal of the Royal Statistical Society: Series C (Applied Statistics), 59(4), 673-692.

Rinaldo, A., Wasserman, L., & G'Sell, M. (2019). Bootstrapping and sample splitting for high-dimensional, assumption-lean inference. Annals of Statistics, 47(6), 3438-3469.

See also

[cp_ss()] for asymptotic p-value via sample splitting. [cp_pt()] for p-value approximation via permutations.

Other classifiers: cp_pt(), cp_ss()

Examples

# \donttest{ library(dsos) set.seed(12345) data(iris) x_train <- iris[1:50, 1:4] # Training sample: Species == 'setosa' x_test <- iris[51:100, 1:4] # Test sample: Species == 'versicolor' iris_test <- cp_at(x_train, x_test) # Can also use: cp_ss and cp_pt str(iris_test)
#> List of 3 #> $ statistic : num 1 #> $ p_value : num 0 #> $ outlier_scores:List of 2 #> ..$ train: num [1:50] 0 0 0 0 0 0 0 0 0 0 ... #> ..$ test : num [1:50] 1 1 1 1 1 1 1 1 1 1 ... #> - attr(*, "class")= chr "outlier.test"
# }