[英]How to change digits of numbers in the export_summs() table
我使用安裝在名為jtools
和huxtable
的 package 中的export-summs()
得到回歸 output 表。
我的代碼是: export_summs(model1, model2, scale = TRUE)
和
────────────────────────────────────────────────────
Model 1 Model 2
───────────────────────────────────
(Intercept) 0.28 ** 0.00
(0.10) (0.02)
educ 0.09 ***
(0.01)
exper 0.00 *
(0.00)
tenure 0.02 ***
(0.00)
xtilde 0.09 ***
(0.01)
───────────────────────────────────
N 526 526
R2 0.32 0.23
────────────────────────────────────────────────────
*** p < 0.001; ** p < 0.01; * p < 0.05.
有沒有辦法讓所有的數字變成 3 個十進制數字?
將export_summs()
調用的結果分配給 object,並使用huxtable::set_number_format()
操作特定行和列的格式。 這是一個例子:
set.seed(123)
df = data.frame(x=rnorm(100), y = rnorm(100), g = sample(c(1:3),100, replace=T))
model1 = lm(y~x,data=df)
model2 = lm(y~x+factor(g), data=df)
jtools::export_summs()
的結果分配給 object; 這個 object 是 class huxtable
model_table = jtools::export_summs(model1, model2, scale=T)
"%.3f"
中的 "f")huxtable::set_number_format(model_table,2:9,2:3,"%.3f")
Output:
─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
Model 1 Model 2
─────────────────────────────────────────────────────────────────────────────────────────
(Intercept) -0.108 0.073
(0.097) (0.169)
x -0.048 -0.035
(0.098) (0.098)
`factor(g)`2 -0.175
(0.235)
`factor(g)`3 -0.373
(0.241)
─────────────────────────────────────────────────────────────────────────────────────────
N 100 100
R2 0.00 0.03
─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
All continuous predictors are mean-centered and scaled by 1 standard deviation. *** p < 0.001; ** p < 0.01; * p < 0.05.
Column names: names, Model 1, Model 2
您可以直接傳遞number_format
字符串:
library(jtools)
model1 <- lm(drat ~ wt + hp, mtcars)
model2 <- lm(drat ~ hp, mtcars)
export_summs(model1, model2, scale = TRUE, number_format = "%.4g")
#> ----------------------------------------------------------------------------
#> Model 1 Model 2
#> ---------------------------------------------------
#> (Intercept) 3.597 *** 3.597 ***
#> (0.06852) (0.08586)
#> wt -0.3937 ***
#> (0.09254)
#> hp 0.01942 -0.2399 **
#> (0.09254) (0.08724)
#> ---------------------------------------------------
#> N 32 32
#> R2 0.5083 0.2014
#> ----------------------------------------------------------------------------
#> All continuous predictors are mean-centered and scaled by 1
#> standard deviation. *** p < 0.001; ** p < 0.01; * p < 0.05.
#>
#> Column names: names, Model 1, Model 2
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.