checkROC {nsROC} | R Documentation |
Check data to compute an ROC curve
Description
This internal function checks if the data introduced for building the curve is correct or not. It shows if there are some missing marker or response values and whether there are less or more than two levels at the response vector, D. It also splits the data into two groups: controls and cases, depending on the corresponding value in the response vector.
Usage
checkROC(X,D)
Arguments
X |
vector of (bio)marker values. It should be numeric. |
D |
vector of response values. It should contain at least two different levels. |
Details
The code will not run and an error will be showed in these cases:
X
orD
is missing,X
orD
is NULL or full of NA's,X
is not a numeric vector,D
has less than two different values, and/orX
andD
have different lengths.
If the response vector has more than two different levels, only the two first ones are considered as controls and cases, respectively.
If the user does not agree with the codification, it can be changed modifying the order of the levels using the factor
function; for instance, factor(D, levels=c("1","0"))
.
Value
If the marker and response vectors are correct a list with the following fields is returned:
levels |
levels in |
controls |
marker values for controls. |
cases |
marker values for cases. |
n0 |
number of controls. |
n1 |
number of cases. |
X |
marker values corresponding to controls and cases (in this order). |
D |
response vector consisting of |
Examples
# Basic example with full information
set.seed(123)
X <- c(rnorm(45), rnorm(30,2,1.5))
D <- c(rep(0,45), rep(1,30))
checkROC(X,D)
# Example with some missing values and more than two levels
X <- replace(c(rnorm(25), rnorm(30,2,1.5), rnorm(20,-3,1)), seq(1,75,5), NA)
D <- replace(c(rep(0,25), rep(1,30), rep(2,20)), seq(1,75,11), NA)
checkROC(X,D)