英文:
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][1]][1]
How can I round
the metrics? Regression coefficients are rounded to 3 digits whereas Wu Hausman is 13 digits.
英文:
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")
How can I round
the metrics? Regression coefficients are rounded to 3 digits whereas Wu Hausman is 13 digits.
答案1
得分: 4
你可以使用gof_map
为非标准统计量添加映射,例如将两者都舍入到小数点后3位:
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)
这将格式化最后两行如下:
如果需要,您还可以更改gm
的第二列以提供更漂亮的格式化名称。
英文:
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:
You could also change the second column of gm
to give nicer formatted names if you want.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论