Skip to content

Commit

Permalink
Add gengamma unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
seananderson committed Jan 6, 2024
1 parent 2092929 commit 8db4a92
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions tests/testthat/test-3-families.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")
})

0 comments on commit 8db4a92

Please sign in to comment.