rmodelsummaryivreg

How can I round metrics in modelsummary package?


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.


Solution

  • 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.