Skip to content

Commit

Permalink
Adding unit tests for check for infinite (and NaN) likelihood values
Browse files Browse the repository at this point in the history
  • Loading branch information
Admin_mschuemi authored and Admin_mschuemi committed Nov 9, 2023
1 parent c8a8089 commit 6527620
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions tests/testthat/test-profileLikelihood.R
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,31 @@ start, length, event, x1, x2
expect_equal(coef(fit)["x1"], argMax)
})

test_that("Check adapative profiling likelihood, other covariate is perfect predictor", {

test <- read.table(header=T, sep = ",", text = "
start, length, event, x1, x2
0, 4, 1,0,1
0, 4,1,2,1
0, 4, 0,0,0
0, 4,1,0,1
0, 4, 1,1,1
0, 4,0,1,0
0, 4, 1,1,1
")
data <- createCyclopsData(event ~ x1 + x2, data = test,
modelType = "cpr")

# Recreating combination of circumstances that lead to infinite log likelihood
# Note: infinite variance would have been selected by cross-validation if we had enough data:
fit <- fitCyclopsModel(data,
prior = createPrior("laplace", variance = Inf, exclude = "x1"))
expect_warning(getCyclopsProfileLogLikelihood(fit, "x1", bounds = c(0, 2), initialGridSize = 10),
"Failing to compute likelihood at entire initial grid")

# This just produces NaN likelihood:
fit <- fitCyclopsModel(data)
expect_warning(getCyclopsProfileLogLikelihood(fit, "x1", bounds = c(0, 2), initialGridSize = 10),
"Failing to compute likelihood at entire initial grid")
})

0 comments on commit 6527620

Please sign in to comment.