Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issues with LOGNO family #899

Merged
merged 5 commits into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading