tests/testthat/test-choose_uk_FALSE.R

#context("choose_uk")

# For inc_cens = FALSE -----

# Check that calling choose_uk() with vector arguments u and k gives
# the same results as calling kgaps repeatedly with scalar arguments

u <- stats::quantile(newlyn, probs = c(0.1, 0.90))
k_vals <- 1:3
cres <- choose_uk(newlyn, u = u, k = k_vals, inc_cens = FALSE)
n_u <- length(u)
comp <- function(i, j) {
  return((i - 1) * n_u + j)
}
for (i in 1:length(k_vals)) {
  for (j in 1:length(u)) {
    res <- kgaps(newlyn, u[j], k_vals[i], inc_cens = FALSE)
    temp <- cres$theta[[comp(i, j)]]
    # The calls will be different1
    temp$call <- res$call <- NULL
    test_that("choose_uk agrees with kgaps", {
      testthat::expect_equal(temp, res)
    })
  }
}

# =============================== plot.choose_uk ==============================

# Check that plot.choose_uk works

# S&P 500 index
u <- quantile(sp500, probs = seq(0.1, 0.9, by = 0.1))
imt_theta <- choose_uk(sp500, u = u, k = 1:5, inc_cens = FALSE)

ukplot <- plot(imt_theta)
test_that("plot.choose_uk works", {
  testthat::expect_identical(ukplot, NULL)
})
ukplot <- plot(imt_theta, y = "theta", ylim = c(0, 1), xlab = "my xlab", lwd = 2,
               col = 1:5)
test_that("plot.choose_uk works, user plot args", {
  testthat::expect_identical(ukplot, NULL)
})

# One run parameter K, many thresholds u
u <- quantile(sp500, probs = seq(0.1, 0.9, by = 0.1))
imt_theta <- choose_uk(sp500, u = u, k = 1, inc_cens = FALSE)
ukplot <- plot(imt_theta)
test_that("plot.choose_uk works", {
  testthat::expect_identical(ukplot, NULL)
})
ukplot <- plot(imt_theta, y = "theta", ylim = c(0, 1), xlab = "my xlab", lwd = 2,
               col = 1:5)
test_that("plot.choose_uk works, user plot args", {
  testthat::expect_identical(ukplot, NULL)
})

# One threshold u, many run parameters K
u <- quantile(sp500, probs = 0.9)
imt_theta <- choose_uk(sp500, u = u, k = 1:5, inc_cens = FALSE)
test_that("plot.choose_uk works", {
  testthat::expect_identical(ukplot, NULL)
})
ukplot <- plot(imt_theta, y = "theta", ylim = c(0, 1), xlab = "my xlab", lwd = 2,
               col = 1:5)
test_that("plot.choose_uk works, user plot args", {
  testthat::expect_identical(ukplot, NULL)
})

Try the exdex package in your browser

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

exdex documentation built on May 29, 2024, 2:15 a.m.