Learn R Programming

roclab (version 0.1.4)

auc.roclearn: Compute AUC for a fitted linear model

Description

Estimate the AUC (Area Under the ROC Curve) for a fitted linear model on new data.

Usage

# S3 method for roclearn
auc(object, newdata, y, ...)

Value

A numeric scalar giving the estimated AUC.

Arguments

object

A fitted model object of class "roclearn" (linear model).

newdata

A matrix or data.frame of test predictors. Must have the same structure as the training data (categorical variables are dummy-aligned automatically).

y

Response vector of test labels ({-1, 1} or convertible).

...

Not used.

Examples

Run this code
set.seed(123)

n_train <- 100
n_pos <- round(0.2 * n_train)
n_neg <- n_train - n_pos

X_train <- rbind(
  matrix(rnorm(2 * n_neg, mean = -1), ncol = 2),
  matrix(rnorm(2 * n_pos, mean =  1), ncol = 2)
)
y_train <- c(rep(-1, n_neg), rep(1, n_pos))

n_test <- 10
n_pos_test <- round(0.2 * n_test)
n_neg_test <- n_test - n_pos_test

X_test <- rbind(
  matrix(rnorm(2 * n_neg_test, mean = -1), ncol = 2),
  matrix(rnorm(2 * n_pos_test, mean =  1), ncol = 2)
)
y_test <- c(rep(-1, n_neg_test), rep(1, n_pos_test))

fit <- roclearn(X_train, y_train, lambda = 0.1, approx=TRUE)

auc(fit, X_test, y_test)

Run the code above in your browser using DataLab