tests/testthat/test-extra.R

test_that("npconmode basic functionality works", {
  data("faithful")
  # Use small subset
  # npconmode needs a conditional density bandwidth object
  # where ydat is discrete.
  y <- factor(ifelse(faithful$eruptions[1:50] > 3, "long", "short"))
  x <- faithful$waiting[1:50]
  # bws[1] is for ydat (discrete), bws[2] is for xdat (continuous)
  bw <- npcdensbw(xdat=x, ydat=y, 
                  bws=c(0.1, 5), bandwidth.compute=FALSE)
  
  mode_fit <- npconmode(bws=bw)
  
  expect_s3_class(mode_fit, "conmode")
  expect_type(fitted(mode_fit), "double")
})

test_that("npquantile basic functionality works", {
  data("faithful")
  x <- faithful$waiting[1:50]
  bw <- npudistbw(dat=x, bws=5, bandwidth.compute=FALSE)
  
  # npquantile is for unconditional quantile
  q <- npquantile(x, bws=bw, tau=c(0.25, 0.5, 0.75))
  
  expect_type(q, "double")
  expect_length(q, 3)
})

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.