Skip to content

Commit

Permalink
Fix model_info.averaging (#975)
Browse files Browse the repository at this point in the history
* Fix model_info.averaging

* test

* lintr
  • Loading branch information
strengejacke authored Nov 26, 2024
1 parent 49bf202 commit d746747
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 3 deletions.
4 changes: 3 additions & 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.99.0.22
Version: 0.99.0.23
Authors@R:
c(person(given = "Daniel",
family = "Lüdecke",
Expand Down Expand Up @@ -86,6 +86,7 @@ Suggests:
AER,
afex,
aod,
ape,
BayesFactor,
bayestestR,
bbmle,
Expand Down Expand Up @@ -175,6 +176,7 @@ Suggests:
parsnip,
pbkrtest,
performance,
phylolm,
plm,
poorman,
PROreg (>= 1.3.0),
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@
* Fixed edge case in `find_transformation()` for simple log-transformation of
the response variable.

* Fixed issue for `model_info.averaging()`.

# insight 0.20.5

## General
Expand Down
4 changes: 2 additions & 2 deletions R/model_info.R
Original file line number Diff line number Diff line change
Expand Up @@ -892,10 +892,10 @@ model_info.summary.lm <- model_info.Arima
#' @export
model_info.averaging <- function(x, ...) {
if (is.null(attributes(x)$modelList)) {
format_warning("Can't calculate covariance matrix. Please use 'fit = TRUE' in 'model.avg()'.")
format_warning("Can't access model information. Please use 'fit = TRUE' in 'model.avg()'.")
return(NULL)
}
model_info.default(x = attributes(x)$modelList[[1]])
model_info(x = attributes(x)$modelList[[1]])
}


Expand Down
51 changes: 51 additions & 0 deletions tests/testthat/test-phylolm.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
skip_if_not_installed("phylolm")
skip_if_not_installed("ape")
skip_if_not_installed("MuMIn")
skip_if_not_installed("withr")
skip_on_cran()

withr::with_options(
list(na.action = "na.fail"),
test_that("phylolm modelinfo", {
set.seed(123456)
tre <- ape::rcoal(60)
taxa <- sort(tre$tip.label)
b0 <- 0
b1 <- 1

x <- phylolm::rTrait(
n = 1,
phy = tre,
model = "BM",
parameters = list(ancestral.state = 0, sigma2 = 10)
)
y <- b0 + b1 * x +
phylolm::rTrait(
n = 1,
phy = tre,
model = "lambda",
parameters = list(
ancestral.state = 0,
sigma2 = 1,
lambda = 0.5
)
)
dat <- data.frame(trait = y[taxa], pred = x[taxa])
mod <- phylolm::phylolm(
trait ~ pred,
data = dat,
phy = tre,
model = "lambda"
)
out <- model_info(mod)
expect_true(out$is_linear)

library(MuMIn) # nolint
mod.d <- MuMIn::dredge(mod, rank = "AICc")
mod.avg.fit <- MuMIn::model.avg(mod.d, revised.var = TRUE, fit = TRUE)
out <- model_info(mod.avg.fit)
expect_true(out$is_linear)
})
)

unloadNamespace("MuMIn")

0 comments on commit d746747

Please sign in to comment.