diff --git a/tests/testthat/test-3-families.R b/tests/testthat/test-3-families.R index 7d295cf86..f8be4a512 100644 --- a/tests/testthat/test-3-families.R +++ b/tests/testthat/test-3-families.R @@ -431,3 +431,46 @@ test_that("Binomial simulation/residuals works with weights argument or cbind()" expect_equal(mean(dat$y), mean(s2), tolerance = 0.1) expect_equal(mean(apply(s2, 1, mean) - dat$y), 0, tolerance = 0.01) }) + +test_that("Generalized gamma works", { + d <- subset(pcod_2011, density > 0) + fit1 <- sdmTMB( + density ~ 1 + depth_scaled, + data = d, + spatial = "off", + family = lognormal(link = "log") + ) + fit2 <- sdmTMB( + density ~ 1 + depth_scaled, + data = d, + spatial = "off", + family = Gamma(link = "log") + ) + fit3 <- sdmTMB( + density ~ 1 + depth_scaled, + data = d, + spatial = "off", + family = gengamma(link = "log") + ) + expect_s3_class(fit2, "sdmTMB") + logLik(fit1) + logLik(fit2) + logLik(fit3) + get_df <- function(x) { + L <- logLik(x) + attr(L, "df") + } + df1 <- get_df(fit1) + df2 <- get_df(fit2) + df3 <- get_df(fit3) + expect_identical(df1, 3L) + expect_identical(df3, 4L) + + b <- as.list(fit3$sd_report, "Estimate") + expect_equal(b$gengamma_Q, 0.04212623, tolerance = 0.001) + AIC(fit1) + AIC(fit2) + AIC(fit3) + + expect_error(residuals(fit3), regexp = "supported") +})