Description Usage Arguments Value Author(s) References Examples
knnAUC : k-nearest neighbors AUC test. Testing dependence/correlation of two variables is one of the fundamental tasks in statistics. In this work, we proposed a new way of testing nonlinear dependence between one continuous variable (X) and one binary variable (Y). We addressed this research question by using R package 'knnAUC'. In the knnAUC framework, we first calculated the AUC estimator based on a k-nearest neighbors classifier, and then evaluate the significance of the AUC based statistic (Alternative hypothesis: AUC > 0.5, that is to say, X has prediction power for Y).
1 | knnAUC(x, y, ratio = 0.46, k = 100)
|
x |
A vector containing values of a continuous variable (X). |
y |
A vector containing values of a binary (0 or 1) discrete variable (Y). |
ratio |
A number, the training sample size ratio. |
kmax |
A positive integer, we'll automatically find the best parameter for knn between 1 and number kmax. |
result A list of AUC estimator and pvalue of knnAUC test.
Yi Li, liyistat@gmail.com
Yi Li, Xiaoyu Liu, et al. knnAUC : k-nearest neighbors AUC test.BMC Bioinformatics. 2018.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | #Example1
#Generate random variable X and random binary variable Y
set.seed(1234)
x<-rnorm(100, mean = 0, sd = 1)
y<-rbinom(100, size = 1, prob = 0.5)
#Test whether X and Y are independent or not using knnAUC method
#Calculate the average AUC estimator and pvalue of knnAUC method
#Set the parameters:ratio=0.5, k=50; And show the running time of knnAUC
start.time <- Sys.time()
library(knnAUC)
knnAUC(x,y,ratio=0.5,k=50)
end.time <- Sys.time()
end.time - start.time
#Example2
#Generate random variables X and Y from logistic regression simulation
set.seed(1234)
N <- 100
intercept <- 1
beta <- 1
x <- rnorm(N,mean=0,sd=1)
linpred <- intercept + (x*beta)
prob <- exp(linpred)/(1 + exp(linpred))
runis <- runif(N,0,1)
y <- ifelse(runis < prob,1,0)
#Test whether X and Y are independent or not using knnAUC method
#Calculate the average AUC estimator and pvalue of knnAUC method
#Set the parameters:ratio=0.46, k=100; And show the running time of knnAUC
library(knnAUC)
start.time <- Sys.time()
knnAUC(x,y,ratio=0.46,k=100)
end.time <- Sys.time()
end.time - start.time
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.