nproc R quickstart: control false positives with Neyman–Pearson classification

A runnable R example that uses the Neyman–Pearson umbrella algorithm to control the class-0 error rate with nproc.

Which NP method should I use? · Original paper · CRAN package and manual

Use nproc::npc() when you want to detect as many class-1 cases as possible while limiting how often the classifier incorrectly calls a class-0 case positive. Label the class whose errors you want to control as 0, even if it is normally called the positive class in your application.

1. Install nproc

install.packages("nproc")

2. Fit and evaluate a classifier

This example uses simulated data and a logistic regression score. Set alpha = 0.05 for a 5% upper limit on the population false-positive rate and delta = 0.05 for a 5% upper limit on the probability, over repeated training samples, that the fitted rule exceeds that limit. Use one split: npc() trains the scoring model on part of the class-0 sample and uses the remaining class-0 scores to set the cutoff.

set.seed(2026)

# Class 0 is the class whose false alarms we want to limit.
draw <- function(n, shift) {
  cbind(signal = rnorm(n, mean = shift), noise = rnorm(n))
}

x <- rbind(draw(400, 0), draw(400, 2))
y <- rep(0:1, each = 400)

alpha <- 0.05  # Target population false-positive limit
delta <- 0.05  # Allowed probability of exceeding that limit

fit <- nproc::npc(
  x, y, method = "logistic", alpha = alpha, delta = delta,
  split = 1, split.ratio = 0.5, randSeed = 2026
)

# Evaluate once on an independent test set.
set.seed(2027)
x_test <- rbind(draw(2000, 0), draw(2000, 2))
y_test <- rep(0:1, each = 2000)
pred <- predict(fit, newx = x_test)$pred.label

rates <- c(
  false_positive = mean(pred[y_test == 0] == 1),
  false_negative = mean(pred[y_test == 1] == 0)
)
print(round(rates, 4))

3. Read the results

With R 4.5.0 and nproc 2.1.5, the example gives a test false-positive rate of 2.25% and a false-negative rate of 54.65%. The classifier meets the target on this test set, but misses many class-1 cases. This is the trade-off to check before using the model.

  • False-positive rate: among true class-0 test cases, the fraction predicted as class 1.
  • False-negative rate: among true class-1 test cases, the fraction predicted as class 0. Tighter false-positive limits can mean more missed class-1 cases.
  • Guarantee vs. measurement: the guarantee is about the unknown population rate under the paper’s sampling conditions, not the realized rate in a finite test set. It does not guarantee control if the class-0 distribution changes at deployment.

How much class-0 data do I need?

For the umbrella cutoff, the minimum number of held-out class-0 scores is ⌈log(δ) / log(1 − α)⌉. At 5% for both parameters, that is 59 calibration cases, separate from those used to fit the score or evaluate the classifier. This example uses 200. If you do not have enough, collect more class-0 data or reconsider the limits with the people who set them.

Cite the method

Tong, X., Feng, Y., and Li, J. J. (2018). Neyman–Pearson classification algorithms and NP receiver operating characteristics. Science Advances, 4(2), eaao1659. DOI: 10.1126/sciadv.aao1659. The paper page has a copyable BibTeX citation.