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

fixest: Incorrect standard errors and error #1040

Merged
merged 6 commits into from
Nov 7, 2024
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
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: parameters
Title: Processing of Model Parameters
Version: 0.23.0.6
Version: 0.23.0.7
Authors@R:
c(person(given = "Daniel",
family = "Lüdecke",
Expand Down Expand Up @@ -113,6 +113,7 @@ Suggests:
coxme,
cplm,
dbscan,
did,
distributional,
domir (>= 0.2.0),
drc,
Expand Down
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
* Fixed bug when extracting 'pretty labels' for model parameters, which could
fail when predictors were character vectors.

* Fixed bug with inaccurate standard errors for models from package *fixest*
that used the `sunab()` function in the formula.

# parameters 0.23.0

## Breaking Changes
Expand Down
4 changes: 3 additions & 1 deletion R/methods_fixest.R
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,10 @@ standard_error.fixest <- function(model, vcov = NULL, vcov_args = NULL, ...) {
params <- insight::get_parameters(model)

if (is.null(vcov)) {
# get standard errors from summary
# see https://github.com/easystats/parameters/issues/1039
stats <- summary(model)
SE <- as.vector(stats$se)
SE <- as.vector(stats$coeftable[, "Std. Error"])
} else {
# we don't want to wrap this in a tryCatch because the `fixest` error is
# informative when `vcov` is wrong.
Expand Down
18 changes: 18 additions & 0 deletions tests/testthat/test-model_parameters.fixest.R
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,21 @@ test_that("robust standard errors", {
expect_error(parameters(mod, vcov = "hetero"), NA)
expect_error(parameters(mod, vcov = "iid"), NA)
})


test_that("standard errors, Sun and Abraham", {
skip_if_not_installed("did")
data(mpdta, package = "did")
m <- fixest::feols(
lemp ~ sunab(first.treat, year, ref.p = -1:-4, att = TRUE) | countyreal + year,
data = mpdta,
cluster = ~countyreal
)
out <- model_parameters(m)
expect_equal(out$SE, m$coeftable[, "Std. Error"], tolerance = 1e-4, ignore_attr = TRUE)

data(base_stagg, package = "fixest")
m <- fixest::feols(y ~ x1 + sunab(year_treated, year) | id + year, base_stagg)
out <- model_parameters(m)
expect_equal(out$SE, m$coeftable[, "Std. Error"], tolerance = 1e-4, ignore_attr = TRUE)
})
Loading