diff --git a/DESCRIPTION b/DESCRIPTION index 5e09f1997..5a233eb6c 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.19.3.3 +Version: 0.19.3.4 Authors@R: c(person(given = "Daniel", family = "Lüdecke", diff --git a/NEWS.md b/NEWS.md index dccea125e..87293ba19 100644 --- a/NEWS.md +++ b/NEWS.md @@ -13,6 +13,8 @@ * Fixed issue with invalid multibyte strings in `trim_ws()`. +* Fixed issue in `find_statistic()` for models from package *fixest*. + # insight 0.19.3 ## Breaking changes diff --git a/R/find_statistic.R b/R/find_statistic.R index 7631ab154..904b90a23 100644 --- a/R/find_statistic.R +++ b/R/find_statistic.R @@ -174,7 +174,6 @@ find_statistic <- function(x, ...) { "bam", "bigglm", "cgam", "cgamm", "eglm", "emmGrid", "emm_list", - "fixest", "gam", "glm", "Glm", "glmc", "glmerMod", "glmRob", "glmrob", "pseudoglm", "scam", @@ -191,7 +190,7 @@ find_statistic <- function(x, ...) { # pattern finding ---------------------------------------------------------- - unclear.mods <- "plm" + unclear.mods <- c("plm", "fixest") if (inherits(x, "glht")) { if (x$df == 0) { @@ -290,7 +289,11 @@ find_statistic <- function(x, ...) { # ambiguous cases ----------------------------------------------------------- if (model_class %in% unclear.mods) { - col_names <- colnames(as.data.frame(summary(x)$coefficients)) + if (model_class == "fixest") { + col_names <- colnames(as.data.frame(summary(x)$coeftable)) + } else { + col_names <- colnames(as.data.frame(summary(x)$coefficients)) + } t_names <- c( "t", diff --git a/tests/testthat/test-fixest.R b/tests/testthat/test-fixest.R index 9b6af082a..0612b8724 100644 --- a/tests/testthat/test-fixest.R +++ b/tests/testthat/test-fixest.R @@ -1,7 +1,6 @@ skip_on_os("mac") skip_if(getRversion() < "3.6.0") skip_if_not_installed("fixest") -skip_if_not_installed("fixest") # avoid warnings fixest::setFixest_nthreads(1) @@ -147,13 +146,12 @@ test_that("get_data", { skip_if_not_installed("parameters") test_that("get_df", { - expect_equal(get_df(m1, type = "residual"), 38290, ignore_attr = TRUE) + expect_equal(get_df(m1, type = "residual"), fixest::degrees_freedom(m1, type = "resid"), ignore_attr = TRUE) expect_equal(get_df(m1, type = "normal"), Inf, ignore_attr = TRUE) - ## TODO: check if statistic is z or t for this model - expect_equal(get_df(m1, type = "wald"), 14, ignore_attr = TRUE) + ## statistic is t for this model + expect_equal(get_df(m1, type = "wald"), fixest::degrees_freedom(m1, type = "t"), ignore_attr = TRUE) }) - test_that("find_formula", { expect_length(find_formula(m1), 2) expect_equal( @@ -256,15 +254,42 @@ test_that("is_multivariate", { }) test_that("find_statistic", { - expect_identical(find_statistic(m1), "z-statistic") - expect_identical(find_statistic(m2), "t-statistic") + out <- capture.output(summary(m1)) + if (any(grepl("t value", out, fixed = TRUE))) { + expect_identical(find_statistic(m1), "t-statistic") + } else { + expect_identical(find_statistic(m1), "z-statistic") + } + out <- capture.output(summary(m2)) + if (any(grepl("t value", out, fixed = TRUE))) { + expect_identical(find_statistic(m2), "t-statistic") + } else { + expect_identical(find_statistic(m2), "z-statistic") + } + out <- capture.output(summary(m3)) + if (any(grepl("t value", out, fixed = TRUE))) { + expect_identical(find_statistic(m3), "t-statistic") + } else { + expect_identical(find_statistic(m3), "z-statistic") + } + out <- capture.output(summary(m4)) + if (any(grepl("t value", out, fixed = TRUE))) { + expect_identical(find_statistic(m4), "t-statistic") + } else { + expect_identical(find_statistic(m4), "z-statistic") + } }) test_that("get_statistic", { stat <- get_statistic(m1) - expect_equal(stat$Statistic, -13.212695, tolerance = 1e-3) + out <- as.data.frame(summary(m1)$coeftable) + expect_equal(stat$Statistic, out[, "t value"], tolerance = 1e-3, ignore_attr = TRUE) stat <- get_statistic(m2) - expect_equal(stat$Statistic, -14.065336, tolerance = 1e-3) + out <- as.data.frame(summary(m2)$coeftable) + expect_equal(stat$Statistic, out[, "t value"], tolerance = 1e-3, ignore_attr = TRUE) + stat <- get_statistic(m3) + out <- as.data.frame(summary(m3)$coeftable) + expect_equal(stat$Statistic, out[, "t value"], tolerance = 1e-3, ignore_attr = TRUE) }) test_that("get_predicted", {