tests/testthat/test-verbose-fit-logging.R

test_that("early verbose FALSE prints concise start/finish and penalty selection counts", {
  set.seed(8601)
  N <- 40
  G <- matrix(rnorm(N * 3), nrow = N)
  Z <- matrix(rnorm(N * 5), nrow = N)
  Y <- rnorm(N)

  out <- suppressWarnings(capture.output(
    fit <- estimate_lucid(
      lucid_model = "early",
      G = G,
      Z = Z,
      Y = Y,
      family = "normal",
      K = 2,
      Rho_G = 0.01,
      max_itr = 6,
      max_tot.itr = 20,
      tol = 1e-2,
      seed = 8601,
      verbose = FALSE
    )
  ))

  expect_s3_class(fit, "early_lucid")
  expect_true(any(grepl("^Fitting LUCID early model", out)))
  expect_true(any(grepl("^Finished LUCID early model", out)))
  expect_true(any(grepl("Selected G:", out)))
  expect_false(any(grepl("^iteration\\s+[0-9]+", out)))
  expect_false(any(grepl("^\\.+$", out)))
})

test_that("parallel verbose TRUE prints iteration log-likelihood updates", {
  set.seed(8602)
  N <- 36
  G <- matrix(rnorm(N * 3), nrow = N)
  Z <- list(matrix(rnorm(N * 4), nrow = N), matrix(rnorm(N * 4), nrow = N))
  Y <- rnorm(N)

  out <- suppressWarnings(capture.output(
    fit <- estimate_lucid(
      lucid_model = "parallel",
      G = G,
      Z = Z,
      Y = Y,
      family = "normal",
      K = c(2, 2),
      max_itr = 4,
      max_tot.itr = 20,
      tol = 1e-2,
      seed = 8602,
      verbose = TRUE
    )
  ))

  expect_s3_class(fit, "lucid_parallel")
  expect_true(any(grepl("^Fitting LUCID in Parallel model", out)))
  expect_true(any(grepl("^iteration\\s+[0-9]+: log-likelihood", out)))
})

test_that("serial verbose FALSE prints concise stage-level progress", {
  set.seed(8603)
  N <- 36
  G <- matrix(rnorm(N * 3), nrow = N)
  Z <- list(
    matrix(rnorm(N * 4), nrow = N),
    matrix(rnorm(N * 4), nrow = N)
  )
  Y <- rnorm(N)

  out <- suppressWarnings(capture.output(
    fit <- estimate_lucid(
      lucid_model = "serial",
      G = G,
      Z = Z,
      Y = Y,
      family = "normal",
      K = list(2, 2),
      max_itr = 5,
      max_tot.itr = 20,
      tol = 1e-2,
      seed = 8603,
      verbose = FALSE
    )
  ))

  expect_s3_class(fit, "lucid_serial")
  expect_true(any(grepl("^Fitting LUCID serial model", out)))
  expect_true(any(grepl("^  Stage 1/2 \\(early\\) finished", out)))
  expect_true(any(grepl("^  Stage 2/2 \\(early\\) finished", out)))
  expect_true(any(grepl("^Finished LUCID serial model\\.", out)))
  expect_false(any(grepl("^iteration\\s+[0-9]+", out)))
})

Try the LUCIDus package in your browser

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

LUCIDus documentation built on March 11, 2026, 9:06 a.m.