Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
strengejacke committed Oct 22, 2024
1 parent 003c8da commit 9192fca
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
5 changes: 4 additions & 1 deletion R/get_loglikelihood.R
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ get_loglikelihood_adjustment <- function(x, weights = NULL) {
.ll_jacobian_adjustment(x, weights)
}
},
warning = function(e) {
NULL
},
error = function(e) {
NULL
}
Expand Down Expand Up @@ -518,7 +521,7 @@ get_loglikelihood.phyloglm <- get_loglikelihood.phylolm

if (is.null(ll_adjustment) && isTRUE(verbose)) {
format_warning("Could not compute corrected log-likelihood for models with transformed response. Log-likelihood value is probably inaccurate.") # nolint
} else {
} else if (!is.null(ll_adjustment)) {
out[1] <- out[1] + ll_adjustment
if (isTRUE(list(...)$REML) && isTRUE(verbose)) {
format_warning("Log-likelihood is corrected for models with transformed response. However, this ignores `REML=TRUE`. Log-likelihood value is probably inaccurate.") # nolint
Expand Down
13 changes: 13 additions & 0 deletions tests/testthat/test-get_loglikelihood.R
Original file line number Diff line number Diff line change
Expand Up @@ -223,3 +223,16 @@ test_that("get_loglikelihood - Bernoulli with inversed levels", {
expect_equal(logLik(ml_ones), get_loglikelihood(ml_ones), ignore_attr = TRUE)
expect_equal(get_loglikelihood(ml_zero), get_loglikelihood(ml_ones), ignore_attr = TRUE)
})

test_that("get_loglikelihood - fails for negative values for some transformation", {
data(mtcars)
dafr <- data.frame(y = mtcars$mpg * -1, x = mtcars$hp)
m <- lm(y^2 ~ x, data = dafr)
expect_warning(get_loglikelihood(m, check_response = TRUE), regex = "Could not")
expect_equal(
get_loglikelihood(m, check_response = TRUE, verbose = FALSE),
get_loglikelihood(m, verbose = FALSE),
tolerance = 1e-4
)
expect_null(get_loglikelihood_adjustment(m))
})

0 comments on commit 9192fca

Please sign in to comment.