1

How can I get the weak instrument F-test statistic in modelsummary?

data(mtcars)
library(ivreg)

iv_model <- ivreg(mpg ~ qsec + cyl + drat | disp | wt, data = mtcars)
summary(iv_model, diagnostics = TRUE)

Call:
ivreg(formula = mpg ~ qsec + cyl + drat | disp | wt, data = mtcars)


Coefficients:
            Estimate Std. Error t value Pr(>|t|)   
(Intercept) 23.28560   20.84029   1.117  0.27370   
disp        -0.05730    0.02053  -2.791  0.00953 **
qsec         0.20443    0.59223   0.345  0.73263   
cyl          0.88477    1.52033   0.582  0.56542   
drat         0.25095    2.19015   0.115  0.90962   

Diagnostic tests:
                 df1 df2 statistic  p-value    
Weak instruments   1  27     19.96 0.000127 ***
Wu-Hausman         1  26     13.87 0.000956 ***
Sargan             0  NA        NA       NA    
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

The metrics = "all" option does show the Wu-Hausman and Sargan test by default.

library(modelsummary)
modelsummary(iv_model, metrics = "all")
Marco
  • 2,368
  • 6
  • 22
  • 48
  • The goodness-of-fit statistics are extracted by the `performance` package. You could open a feature request on [their Github repository](https://github.com/easystats/performance) to ask for this. Alternatively, you can easily add new statistics in `modelsummary` by following the detailed instructions in the vignette: https://vincentarelbundock.github.io/modelsummary/articles/modelsummary.html#new-models-and-custom-statistics – Vincent Mar 16 '23 at 13:31
  • Can you point me to the specific section? Is this Adding new information to existing models ? – Marco Mar 29 '23 at 09:48
  • See my answer with cool new changes to the development version which makes this much easier. Hope it helps. – Vincent Mar 29 '23 at 13:33

1 Answers1

1

modelsummary includes a simple mechanism to add any goodness-of-fit statistics to tables. Search for glance_custom on this page for detailed instructions and examples: https://vincentarelbundock.github.io/modelsummary/articles/modelsummary.html

In the specific case of ivreg, a contributor just added functionality to the performance and modelsummary packages to make this much easier. Install the development versions of both packages:

library(remotes)
install_github("easystats/performance")
install_github("vincentarelbundock/modelsummary")

Restart R completely for the change to take effect. Then,

library(ivreg)
library(modelsummary)

iv_model <- ivreg(mpg ~ qsec + cyl + drat | disp | wt, data = mtcars)

gm <- transform(modelsummary::gof_map, omit = FALSE)
modelsummary(iv_model, gof_map = gm, metrics = "all")
(1)
(Intercept) 23.286
(20.840)
disp -0.057
(0.021)
qsec 0.204
(0.592)
cyl 0.885
(1.520)
drat 0.251
(2.190)
Num.Obs. 32
R2 0.655
R2 Adj. 0.604
AIC 182.7
BIC 191.5
RMSE 3.48
Weak IV F-stat 20.0
Weak IV p 0.000
Sigma 3.793
Wu-Hausman 13.869
Wu-Hausman (p) 0.001
Vincent
  • 15,809
  • 7
  • 37
  • 39
  • Vincent did something change? I tried this again on another computer and it didn't work anymore (install from github + restart R). I get a `Sigma` but no F-stat or Wu-Hausman with the exact same code. – Marco Apr 17 '23 at 11:32
  • No, nothing should have changed. What version does `sessionInfo()` tell you is loaded? – Vincent Apr 17 '23 at 12:03
  • modelsummary_1.3.0 and performance_0.10.3 – Marco Apr 17 '23 at 12:12
  • 1
    Right, that's not the development version from github, which has a number like 1.3.0.9008. Your install didn't work. – Vincent Apr 17 '23 at 12:51