Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
strengejacke committed Sep 10, 2023
1 parent f12c0cf commit 925e7fa
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 28 deletions.
13 changes: 10 additions & 3 deletions R/find_statistic.R
Original file line number Diff line number Diff line change
Expand Up @@ -289,12 +289,19 @@ find_statistic <- function(x, ...) {
# ambiguous cases -----------------------------------------------------------

if (model_class %in% unclear.mods) {
# special handling for fixest, see
# https://github.com/easystats/parameters/issues/892#issuecomment-1712645841
# and https://github.com/lrberge/fixest/blob/c14c55917897478d996f80bd3392d2e7355b1f29/R/ESTIMATION_FUNS.R#L2903
if (model_class == "fixest") {
col_names <- colnames(as.data.frame(summary(x)$coeftable))
} else {
col_names <- colnames(as.data.frame(summary(x)$coefficients))
if (m_info$family %in% c("binomial", "poisson")) {
return("z-statistic")
} else {
return("t-statistic")
}
}

col_names <- colnames(as.data.frame(summary(x)$coefficients))

t_names <- c(
"t",
"t-value",
Expand Down
41 changes: 16 additions & 25 deletions tests/testthat/test-fixest.R
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
skip_on_os("mac")
skip_if(getRversion() < "3.6.0")
skip_if_not_installed("fixest")
skip_if_not_installed("carData")

# avoid warnings
fixest::setFixest_nthreads(1)

data(trade, package = "fixest")
data(Greene, package = "carData")

m1 <- fixest::femlm(Euros ~ log(dist_km) | Origin + Destination + Product, data = trade)
m2 <- fixest::femlm(log1p(Euros) ~ log(dist_km) | Origin + Destination + Product, data = trade, family = "gaussian")
m3 <- fixest::feglm(Euros ~ log(dist_km) | Origin + Destination + Product, data = trade, family = "poisson")
Expand All @@ -14,7 +17,6 @@ m4 <- fixest::feols(
data = iris
)


test_that("robust variance-covariance", {
mod <- fixest::feols(mpg ~ hp + drat | cyl, data = mtcars)
# default is clustered
Expand Down Expand Up @@ -254,30 +256,19 @@ test_that("is_multivariate", {
})

test_that("find_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")
}
# see https://github.com/easystats/parameters/issues/892#issuecomment-1712645841
# and https://github.com/lrberge/fixest/blob/c14c55917897478d996f80bd3392d2e7355b1f29/R/ESTIMATION_FUNS.R#L2903
d <- Greene
d$dv <- as.numeric(Greene$decision == "yes")
m5 <- feglm(dv ~ language | judge,
data = d,
cluster = "judge", family = "logit"
)
expect_identical(find_statistic(m1), "z-statistic")
expect_identical(find_statistic(m2), "t-statistic")
expect_identical(find_statistic(m3), "z-statistic")
expect_identical(find_statistic(m4), "t-statistic")
expect_identical(find_statistic(m5), "z-statistic")
})

test_that("get_statistic", {
Expand Down

0 comments on commit 925e7fa

Please sign in to comment.