tests/testthat/test-bw.F.SBC.cv.R

test_that("bw.F.SBC.cv() returns a valid bandwidth", {
  bw <- bw.F.SBC.cv(biased_models[[1]], nh = 25L, plot = FALSE)

  expect_type(bw, "double")
  expect_gt(bw, 0)
})

test_that("bw.F.SBC.cv() correctly handles different kernels", {
  bw_values <- sapply(kernels, function(k) {
    bw.F.SBC.cv(biased_models[[1]], nh = 25L, kernel = k, plot = FALSE)
  })

  expect_false(all(duplicated(bw_values)),
    info = "Different kernels should produce different bandwidths"
  )
})

test_that("bw.F.SBC.cv() produces stable plots", {
  skip_on_os(os = c("windows", "linux"))

  lapply(seq_along(biased_models), function(i) {
    lapply(kernels, function(k) {
      vdiffr::expect_doppelganger(
        paste0("bw.F.SBC.cv_model_", i, "_kernel_", k),
        function() {
          bw.F.SBC.cv(biased_models[[i]],
            nh = 25L, kernel = k, plot = TRUE
          )
        }
      )
    })
  })
})

test_that("cdf.bd() with bw.F.SBC.cv() produces stable plots", {
  skip_on_os(os = c("windows", "linux"))

  lapply(seq_along(biased_models), function(i) {
    lapply(kernels, function(k) {
      vdiffr::expect_doppelganger(
        paste0("cdf.bd_bw.F.SBC.cv_model_", i, "_kernel_", k),
        function() {
          cdf.bd(biased_models[[i]],
            bw = "bw.F.SBC.cv",
            nh = 25L,
            kernel = k, plot = TRUE
          )
          suppressWarnings(curve(
            {
              \(.)  cdf_list[[i]](.)
            }(x),
            col = "magenta",
            add = TRUE
          ))
        }
      )
    })
  })
})

Try the WData package in your browser

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

WData documentation built on Nov. 2, 2026, 1:10 a.m.