2

I enjoy the option metrics="all" in modelsummary package that gives excellent summary statistics of instrument variable models (e.g. ivreg), namely the Wu-Hausman test.

data(mtcars)
library(ivreg)

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

library(modelsummary)
modelsummary(iv_model, metrics = "all")

enter image description here

How can I round the metrics? Regression coefficients are rounded to 3 digits whereas Wu Hausman is 13 digits.

zephryl
  • 14,633
  • 3
  • 11
  • 30
Marco
  • 2,368
  • 6
  • 22
  • 48
  • 2
    Use the `gof_map` argument. This is well documented in `?modelsummary` and there are examples on the website: https://vincentarelbundock.github.io/modelsummary/articles/modelsummary.html#gof_map – Vincent Mar 15 '23 at 12:28

1 Answers1

4

You can add a mapping for non-standard statistics using gof_map e.g. to round both to 3 decimal places:

library(tibble)
gm <- tribble(
  ~raw,        ~clean,      ~fmt,
  "wu.hausman", "wu.hausman", 3,
  "wu.hausman.p", "wu.hausman.p", 3)
modelsummary(iv_model, metrics = "all", gof_map = gm)  

which formats the last two rows as:

enter image description here

You could also change the second column of gm to give nicer formatted names if you want.

nrennie
  • 1,877
  • 1
  • 4
  • 14