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

Use t-distribution for coefplot/iplot CIs #408

Merged
merged 2 commits into from
Sep 13, 2023

Conversation

grantmcdermott
Copy link
Contributor

@grantmcdermott grantmcdermott commented Apr 3, 2023

Almost all of the dedicated fixest methods that yield confidence intervals do so using a t-distribution. (See also #362 (comment).) A notable exception can be found in the coefplot/iplot functions, which currently use a normal distribution:

fixest/R/coefplot.R

Lines 1660 to 1661 in d8fb28a

# We compute the CI
nb = abs(qnorm((1 - ci_level)/2))

The importance of this difference obviously diminishes with the size of the dataset (since DoF -> Inf). But it does create an awkward situation where the figures from coefplot/iplot don't necessarily correspond to the results from, say, etable.

This PR brings the CIs from coefplot and iplot into alignment with the other fixest methods. I've tried to include some catches so that, if it can't extract the right DoF from the model object for some reason, it will default to Inf and thus effectively revert back to a normal distribution.

Here is the current behaviour (fixest 0.11.1):

library(fixest)

base = setNames(iris, c("y", "x1", "x2", "x3", "species"))
est = feols(y ~ x1 + x2 | species, base)

confint(est)
#>         2.5 %   97.5 %
#> x1 -0.2618362 1.126271
#> x2  0.2311479 1.320111
coefplot(est, only.params = TRUE)$prms[, 2:3]
#>       ci_low   ci_high
#> x1 0.1160589 0.7483756
#> x2 0.5276048 1.0236542

Created on 2023-04-02 with reprex v2.0.2

And the same code following this PR:

devtools::load_all("~/Documents/Projects/fixest")
#> ℹ Loading fixest

base = setNames(iris, c("y", "x1", "x2", "x3", "species"))
est = feols(y ~ x1 + x2 | species, base)

confint(est)
#>         2.5 %   97.5 %
#> x1 -0.2618362 1.126271
#> x2  0.2311479 1.320111
coefplot(est, only.params = TRUE)$prms[, 2:3]
#>        ci_low  ci_high
#> x1 -0.2618362 1.126271
#> x2  0.2311479 1.320111

Created on 2023-04-02 with reprex v2.0.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants