tests/testthat/test-npreg-formula-response-name-contract.R

test_that("npreg formula fits preserve the response name for plotting metadata", {
  set.seed(42)
  n <- 60L
  dat <- data.frame(x = runif(n, -1, 1))
  dat$y <- dat$x^2 + rnorm(n, sd = 0.25 * stats::sd(dat$x))

  fit <- np::npreg(
    y ~ x,
    data = dat,
    nmulti = 1,
    regtype = "lp",
    degree = 1,
    bwtype = "adaptive_nn"
  )

  expect_identical(fit$bws$ynames, "y")

  path <- tempfile(fileext = ".png")
  grDevices::png(path, width = 800, height = 600)
  on.exit({
    grDevices::dev.off()
    unlink(path)
  }, add = TRUE)

  expect_no_error(
    plot(fit, plot.errors.method = "asymptotic", view = "fixed")
  )
})

Try the np package in your browser

Any scripts or data that you put into this service are public.

np documentation built on May 3, 2026, 1:07 a.m.