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 in find_statistic for fixest #802

Merged
merged 3 commits into from
Sep 9, 2023
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.19.3.3
Version: 0.19.3.4
Authors@R:
c(person(given = "Daniel",
family = "Lüdecke",
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 6 additions & 3 deletions R/find_statistic.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
t = "t-statistic",
Z = "z-statistic",
`Quade F` = ,
`F` = "F-statistic",

Check warning on line 40 in R/find_statistic.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/find_statistic.R,line=40,col=9,[keyword_quote_linter] Only quote named arguments to functions if necessary, i.e., if the name is not a valid R symbol (see ?make.names).
`Bartlett's K-squared` = ,
`Fligner-Killeen:med chi-squared` = ,
`Friedman chi-squared` = ,
Expand Down Expand Up @@ -111,7 +111,7 @@

# z-value objects ----------------------------------------------------------

z.mods <- c(

Check warning on line 114 in R/find_statistic.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/find_statistic.R,line=114,col=3,[object_name_linter] Variable and function name style should match snake_case or symbols.
"aareg", "Arima", "averaging",
"betamfx", "betaor", "betareg", "bife", "bifeAPEs", "bglmerMod",
"boot_test_mediation", "bracl", "brglm", "brglmFit", "brmultinom", "btergm",
Expand Down Expand Up @@ -141,7 +141,7 @@

# F-value objects ----------------------------------------------------------

f.mods <- c(

Check warning on line 144 in R/find_statistic.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/find_statistic.R,line=144,col=3,[object_name_linter] Variable and function name style should match snake_case or symbols.
"afex_aov", "Anova.mlm", "aov", "aovlist", "anova",
"Gam",
"manova", "maov",
Expand All @@ -151,7 +151,7 @@

# chi-squared value objects ------------------------------------------------

chi.mods <- c(

Check warning on line 154 in R/find_statistic.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/find_statistic.R,line=154,col=3,[object_name_linter] Variable and function name style should match snake_case or symbols.
"anova.rms",
"coxph.penal",
"epi.2by2",
Expand All @@ -169,12 +169,11 @@

# models for which there is no clear t-or z-statistic
# which statistic to use will be decided based on the family used
g.mods <-

Check warning on line 172 in R/find_statistic.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/find_statistic.R,line=172,col=3,[object_name_linter] Variable and function name style should match snake_case or symbols.
c(
"bam", "bigglm",
"cgam", "cgamm",
"eglm", "emmGrid", "emm_list",
"fixest",
"gam", "glm", "Glm", "glmc", "glmerMod", "glmRob", "glmrob",
"pseudoglm",
"scam",
Expand All @@ -182,7 +181,7 @@
)

# t-statistic (otherwise z-statistic: "binomial", "poisson")
g.t.mods <-

Check warning on line 184 in R/find_statistic.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/find_statistic.R,line=184,col=3,[object_name_linter] Variable and function name style should match snake_case or symbols.
c(
"gaussian", "Gamma",
"quasi", "quasibinomial", "quasipoisson",
Expand All @@ -191,11 +190,11 @@

# pattern finding ----------------------------------------------------------

unclear.mods <- "plm"
unclear.mods <- c("plm", "fixest")

Check warning on line 193 in R/find_statistic.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/find_statistic.R,line=193,col=3,[object_name_linter] Variable and function name style should match snake_case or symbols.

if (inherits(x, "glht")) {
if (x$df == 0) {
z.mods <- c(z.mods, "glht")

Check warning on line 197 in R/find_statistic.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/find_statistic.R,line=197,col=7,[object_name_linter] Variable and function name style should match snake_case or symbols.
} else {
t.mods <- c(t.mods, "glht")
}
Expand All @@ -203,7 +202,7 @@

if (inherits(x, "coeftest")) {
if ("z value" %in% dimnames(x)[[2]]) {
z.mods <- c(z.mods, "coeftest")

Check warning on line 205 in R/find_statistic.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/find_statistic.R,line=205,col=7,[object_name_linter] Variable and function name style should match snake_case or symbols.
} else {
t.mods <- c(t.mods, "coeftest")
}
Expand All @@ -211,7 +210,7 @@

# no statistic -------------------------------------------------------------

unsupported.mods <- c(

Check warning on line 213 in R/find_statistic.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/find_statistic.R,line=213,col=3,[object_name_linter] Variable and function name style should match snake_case or symbols.
"bcplm", "BFBayesFactor", "brmsfit",
"gbm", "glmmEP",
"joint",
Expand Down Expand Up @@ -290,7 +289,11 @@
# 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",
Expand Down
43 changes: 34 additions & 9 deletions tests/testthat/test-fixest.R
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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", {
Expand Down
Loading