Skip to content

Commit

Permalink
fix., add test
Browse files Browse the repository at this point in the history
  • Loading branch information
strengejacke committed Oct 22, 2024
1 parent a3b40a4 commit 3e141f4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion R/get_loglikelihood.R
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ get_loglikelihood.phyloglm <- get_loglikelihood.phylolm
NULL
} else if (trans == "scale") {
scale_denominator <- .extract_scale_denominator(x)
.weighted_sum(log(1 / scale_denominator), w = model_weights)
.weighted_sum(log(1 / rep.int(scale_denominator, length(model_weights))), w = model_weights) # nolint
} else if (trans == "power") {
trans_power <- .extract_power_transformation(x)
.weighted_sum(log(trans_power * (get_response(x, as_proportion = TRUE)^(trans_power - 1))), w = model_weights) # nolint
Expand Down
4 changes: 4 additions & 0 deletions tests/testthat/test-get_loglikelihood.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ test_that("get_loglikelihood - lm", {
expect_equal(as.numeric(get_loglikelihood(x)), -385.6256, tolerance = 1e-3)
expect_equal(as.numeric(get_loglikelihood(x, check_response = TRUE)), -110.5192, tolerance = 1e-3)

# scale
x <- lm(mpg / 3.5 ~ wt, weights = wg, data = mtcars)
expect_equal(as.numeric(get_loglikelihood(x)), -41.94534, tolerance = 1e-3)
expect_equal(as.numeric(get_loglikelihood(x, check_response = TRUE)), -82.03376, tolerance = 1e-3)
})

test_that("get_loglikelihood - not supported", {
Expand Down

0 comments on commit 3e141f4

Please sign in to comment.