From 736714079bcae81dbaf6b1b5a47ba6b5e1a991ba Mon Sep 17 00:00:00 2001 From: Daniel Date: Tue, 26 Nov 2024 08:22:16 +0100 Subject: [PATCH] Fix model_info.averaging --- DESCRIPTION | 4 +++- NEWS.md | 2 ++ R/model_info.R | 4 ++-- tests/testthat/test-phylolm.R | 38 +++++++++++++++++++++++++++++++++++ 4 files changed, 45 insertions(+), 3 deletions(-) create mode 100644 tests/testthat/test-phylolm.R diff --git a/DESCRIPTION b/DESCRIPTION index 818f65abf..2bc82fe1b 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -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", @@ -86,6 +86,7 @@ Suggests: AER, afex, aod, + ape, BayesFactor, bayestestR, bbmle, @@ -175,6 +176,7 @@ Suggests: parsnip, pbkrtest, performance, + phylolm, plm, poorman, PROreg (>= 1.3.0), diff --git a/NEWS.md b/NEWS.md index 3f29b20bb..f7fc952f0 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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 diff --git a/R/model_info.R b/R/model_info.R index 6fe261773..edcc1948c 100644 --- a/R/model_info.R +++ b/R/model_info.R @@ -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]]) } diff --git a/tests/testthat/test-phylolm.R b/tests/testthat/test-phylolm.R new file mode 100644 index 000000000..9d26cf06e --- /dev/null +++ b/tests/testthat/test-phylolm.R @@ -0,0 +1,38 @@ +skip_if_not_installed("phylolm") +skip_if_not_installed("ape") +skip_on_cran() + +test_that("MuMIn link functions", { + 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) +})