-
Notifications
You must be signed in to change notification settings - Fork 303
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
glance.ivreg fails with multiple endogenous regressors #599
Comments
Here is a reprex for the issue mentioned above- set.seed(123)
library(broom)
library(AER)
#> Loading required package: car
#> Loading required package: carData
#> Loading required package: lmtest
#> Loading required package: zoo
#>
#> Attaching package: 'zoo'
#> The following objects are masked from 'package:base':
#>
#> as.Date, as.Date.numeric
#> Loading required package: sandwich
#> Loading required package: survival
# Works
glance(ivreg(mpg ~ hp | qsec + am, data = mtcars), diagnostics = TRUE)
#> # A tibble: 1 x 13
#> r.squared adj.r.squared sigma statistic p.value df statistic.Sargan
#> <dbl> <dbl> <dbl> <dbl> <dbl> <int> <dbl>
#> 1 0.592 0.578 3.92 38.5 7.92e-7 2 12.8
#> # ... with 6 more variables: p.value.Sargan <dbl>,
#> # statistic.Wu.Hausman <dbl>, p.value.Wu.Hausman <dbl>,
#> # statistic.weakinst <dbl>, p.value.weakinst <dbl>, df.residual <int>
# Fails
glance(ivreg(mpg ~ hp + wt | qsec + am, data = mtcars), diagnostics = TRUE)
#> Error in diagnostics["Weak instruments", "statistic"]: subscript out of bounds And traceback- > traceback()
9: eval_tidy(xs[[i]], unique_output)
8: lst_quos(xs, transform = expand_lst)
7: tibble(statistic.Sargan = diagnostics["Sargan", "statistic"],
p.value.Sargan = diagnostics["Sargan", "p-value"], statistic.Wu.Hausman = diagnostics["Wu-Hausman",
"statistic"], p.value.Wu.Hausman = diagnostics["Wu-Hausman",
"p-value"], statistic.weakinst = diagnostics["Weak instruments",
"statistic"], p.value.weakinst = diagnostics["Weak instruments",
"p-value"])
6: eval(substitute(expr), data, enclos = parent.frame())
5: eval(substitute(expr), data, enclos = parent.frame())
4: with.default(s, tibble(statistic.Sargan = diagnostics["Sargan",
"statistic"], p.value.Sargan = diagnostics["Sargan", "p-value"],
statistic.Wu.Hausman = diagnostics["Wu-Hausman", "statistic"],
p.value.Wu.Hausman = diagnostics["Wu-Hausman", "p-value"],
statistic.weakinst = diagnostics["Weak instruments", "statistic"],
p.value.weakinst = diagnostics["Weak instruments", "p-value"]))
3: with(s, tibble(statistic.Sargan = diagnostics["Sargan", "statistic"],
p.value.Sargan = diagnostics["Sargan", "p-value"], statistic.Wu.Hausman = diagnostics["Wu-Hausman",
"statistic"], p.value.Wu.Hausman = diagnostics["Wu-Hausman",
"p-value"], statistic.weakinst = diagnostics["Weak instruments",
"statistic"], p.value.weakinst = diagnostics["Weak instruments",
"p-value"]))
2: glance.ivreg(ivreg(mpg ~ hp + wt | qsec + am, data = mtcars),
diagnostics = TRUE)
1: glance(ivreg(mpg ~ hp + wt | qsec + am, data = mtcars), diagnostics = TRUE) |
I'm interested in taking this issue on. After talking with @alexpghayes, one possible solution is to not return the F-stat as part of |
Closed in #641! |
This issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with a reprex: https://reprex.tidyverse.org) and link to this issue. |
glance::ivreg(., diagnostics = TRUE)
will fail if the 2SLS has multiple endogenous regressors. This is due to the fact thatsummary.ivreg(., diagnostics = TRUE)
will return a diagnostics matrix that has no row named "Weak instruments", which is required in the following line:broom/R/aer-tidiers.R
Line 123 in 66411c4
As you can see in the latter case if you do
summary(ivreg(mpg ~ hp + wt | qsec + am, data = mtcars))
, the diagnostics have two rows named"Weak instruments (hp)"
and"Weak instruments (wt)"
instead of"Weak instruments"
, because the first-stage fstat is separate for each endogenous regressor.This crash should be avoided by either a workaround that fails to return the f-stats or a solution that returns them all. Of course, returning them all means having an unexpected number of columns in the return, which is undesirable.
Thoughts? I encountered this while looking at mimicking
glance.ivreg
inestimatr::glance.iv_robust
.The text was updated successfully, but these errors were encountered: