Skip to content

Commit

Permalink
add a twlss example model and test fitted_values support for twlss
Browse files Browse the repository at this point in the history
  • Loading branch information
gavinsimpson committed Oct 17, 2023
1 parent 73cd3ba commit bd13a9c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
10 changes: 9 additions & 1 deletion tests/testthat/setup.R
Original file line number Diff line number Diff line change
Expand Up @@ -388,4 +388,12 @@ ziplss_data <- function(seed = 0) {
ziplss_df <- ziplss_data()
m_ziplss <- gam(list(y ~ s(x2) + x3,
~ s(x0) + x1), family = ziplss(), data = ziplss_df)


# TWLSS example from ?mgcv::twlss
twlss_df <- withr::with_seed(3, gamSim(1, n = 400, dist = "poisson",
scale = 0.2, verbose = FALSE) |>
mutate(y = mgcv::rTweedie(exp(.data$f), p = 1.3,
phi = 0.5))) ## Tweedie response
## Fit a fixed p Tweedie, with wrong link ...
m_twlss <- gam(list(y ~ s(x0) + s(x1) + s(x2) + s(x3), ~ 1, ~ 1),
family = twlss(), data = twlss_df)
7 changes: 7 additions & 0 deletions tests/testthat/test-fitted-values.R
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,13 @@ test_that("fitted values works for a gaulss model", {
expect_named(fv, expected = c(".row", ".parameter", fv_nms))
})

test_that("fitted values works for a twlss model", {
expect_silent(fv <- fitted_values(m_twlss))
expect_named(fv, expected = c(".row", ".parameter", fv_nms))
expect_identical(pull(fv, ".parameter") |> unique(),
c("location", "power", "scale"))
})

test_that("fitted values works for a gamm model", {
expect_silent(fv <- fitted_values(m_gamm))
expect_named(fv, expected = c(".row","x0", "x1", "x2", "x3", fv_nms))
Expand Down

0 comments on commit bd13a9c

Please sign in to comment.