res_1 <- lm(data = ggplot2::diamonds, price ~ carat)
res_2 <- lm(data = ggplot2::diamonds, price ~ carat + x + y + z)
res_list <- list(
"Model 1" = res_1,
"Model 2" = res_2
)分析結果表の作成
- modelsummary パッケージを使うと、綺麗な分析結果の表を作成できる
- modelsummary::msummary
- stars オプションで、有意水準の点の付け方を指定できる
- fmt オプションで、数値の丸め方を指定できる
- gof_map オプションで、統計量の名前を変更できる
- gof_omit オプションで不要な統計量を指定すれば、表から削除できる
- coef_map オプションで、表内の説明変数の名前を指定できる
res_list |>
modelsummary::msummary(
stars = c("†" = .1, "*" = .05, "**" = .01, "***" = .001), # 有意水準の点
fmt = '%.4f', # 少数第4位以下は四捨五入
gof_map = list(
list("raw" = "adj.r.squared", "clean" = "調整済みR<sup>2</sup>", "fmt" = 4),
list("raw" = "nobs", "clean" = "N", "fmt" = 0)), # 統計量の名前の変更
gof_omit = "IC|Log|F|RMSE|(R2$)", # 指定した統計量を省略
coef_map = c(
"carat" = "カラット数",
"x" = "幅",
"y" = "高さ",
"z" = "奥行"
) # 説明変数の名前の変更
)| Model 1 | Model 2 | |
|---|---|---|
| カラット数 | 7756.4256*** | 10233.9134*** |
| (14.0666) | (62.9366) | |
| 幅 | -884.2091*** | |
| (40.4704) | ||
| 高さ | 166.0384*** | |
| (25.8584) | ||
| 奥行 | -576.2035*** | |
| (39.2822) | ||
| :—————— | ————-: | ————–: |
| 調整済みR2 | 0.8493 | 0.8541 |
| N | 53940 | 53940 |
Note: ^^ † p < 0.1, * p < 0.05, ** p < 0.01, *** p < 0.001