Skip to content

Commit

Permalink
Fix issues with LOGNO family (#899)
Browse files Browse the repository at this point in the history
* Fix issues with LOGNO family

* fix

* fix

* styler

* fix
  • Loading branch information
strengejacke authored Jul 4, 2024
1 parent de9c471 commit 90906be
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 16 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: insight
Title: Easy Access to Model Information for Various Model Objects
Version: 0.20.1.10
Version: 0.20.1.11
Authors@R:
c(person(given = "Daniel",
family = "Lüdecke",
Expand Down
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@
* `null_model()` now correctly handles zero-inflated models from package
*glmmTMB*.

* Fixed issues in `link_inverse()` and `link_function()` for models of class
`gamlss` from `LOGNO()` family.

# insight 0.20.1

## Bug fixes
Expand Down
19 changes: 12 additions & 7 deletions R/link_function.R
Original file line number Diff line number Diff line change
Expand Up @@ -606,13 +606,18 @@ link_function.glmm <- function(x, ...) {
link_function.gamlss <- function(x, what = c("mu", "sigma", "nu", "tau"), ...) {
what <- match.arg(what)
faminfo <- get(x$family[1], asNamespace("gamlss"))()
switch(what,
mu = faminfo$mu.linkfun,
sigma = faminfo$sigma.linkfun,
nu = faminfo$nu.linkfun,
tau = faminfo$tau.linkfun,
faminfo$mu.linkfun
)
# exceptions
if (faminfo$family[1] == "LOGNO") {
function(mu) log(mu)
} else {
switch(what,
mu = faminfo$mu.linkfun,
sigma = faminfo$sigma.linkfun,
nu = faminfo$nu.linkfun,
tau = faminfo$tau.linkfun,
faminfo$mu.linkfun
)
}
}


Expand Down
19 changes: 12 additions & 7 deletions R/link_inverse.R
Original file line number Diff line number Diff line change
Expand Up @@ -643,13 +643,18 @@ link_inverse.brmsfit <- function(x, ...) {
link_inverse.gamlss <- function(x, what = c("mu", "sigma", "nu", "tau"), ...) {
what <- match.arg(what)
faminfo <- get(x$family[1], asNamespace("gamlss"))()
switch(what,
mu = faminfo$mu.linkinv,
sigma = faminfo$sigma.linkinv,
nu = faminfo$nu.linkinv,
tau = faminfo$tau.linkinv,
faminfo$mu.linkinv
)
# exceptions
if (faminfo$family[1] == "LOGNO") {
function(eta) pmax(exp(eta), .Machine$double.eps)
} else {
switch(what,
mu = faminfo$mu.linkinv,
sigma = faminfo$sigma.linkinv,
nu = faminfo$nu.linkinv,
tau = faminfo$tau.linkinv,
faminfo$mu.linkinv
)
}
}


Expand Down
7 changes: 7 additions & 0 deletions tests/testthat/test-gamlss.R
Original file line number Diff line number Diff line change
Expand Up @@ -154,3 +154,10 @@ test_that("find_formula works with namespace colons", {
ignore_attr = TRUE
)
})

test_that("link_inv for LOGNO", {
data(abdom, package = "gamlss.data")
m1 <- gamlss::gamlss(y ~ x, family = "LOGNO", data = abdom)
expect_equal(link_inverse(m1)(0.2), exp(0.2), tolerance = 1e-4)
expect_equal(link_function(m1)(0.2), log(0.2), tolerance = 1e-4)
})
2 changes: 1 addition & 1 deletion tests/testthat/test-svylme.R
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ withr::with_environment(
find_formula(m1),
list(
conditional = api00 ~ ell + mobility + api99,
random = ~1 + api99 | dnum
random = ~ 1 + api99 | dnum
),
ignore_attr = TRUE
)
Expand Down

0 comments on commit 90906be

Please sign in to comment.