admin 管理员组

文章数量: 1086019

I'm working with {modelsummary} to create a styling function for models. The final tables will be in Polish so I need to rename the columns with estimate and standard error names. I found this question and followed the instructions: How can I rename statistics in modelsummary?

My problem is that the estimate column gets duplicated rather than just renamed. Is there some way to actually get the column renamed rather than creating a new column? Or alternatively is there a way to get it to work with some additional {tinytable} processing? Sample code that should reproduce the issue is below

library(modelsummary)
library(tinytable)
N <- 1e4
x <- rnorm(N)
x2 <- rnorm(N, 1.3, .8)
y <- rnorm(N, 2 + .3*x - .6*x2)
df_to_lm <- data.frame(x, x2, y)
lm_totable_1 <- lm(y ~ x, df_to_lm)
lm_totable_2 <- lm(y ~ x + x2, df_to_lm)
lm_totable_3 <- lm(y ~ x*x2, df_to_lm)

modelsummary(
    models = list("Model 1" = lm_totable_1,
     "Model 2" = lm_totable_2, 
     "Model 3" = lm_totable_3), 
    fmt = 2,
    statistic = c("B" = "{estimate}", 
    "Błąd Standardowy" = "{std.error}"),  # Correctly renaming estimate
    coef_omit = "Intercept",
    shape = term ~ model + statistic,
    gof_map = "r.squared"
  )

I'm working with {modelsummary} to create a styling function for models. The final tables will be in Polish so I need to rename the columns with estimate and standard error names. I found this question and followed the instructions: How can I rename statistics in modelsummary?

My problem is that the estimate column gets duplicated rather than just renamed. Is there some way to actually get the column renamed rather than creating a new column? Or alternatively is there a way to get it to work with some additional {tinytable} processing? Sample code that should reproduce the issue is below

library(modelsummary)
library(tinytable)
N <- 1e4
x <- rnorm(N)
x2 <- rnorm(N, 1.3, .8)
y <- rnorm(N, 2 + .3*x - .6*x2)
df_to_lm <- data.frame(x, x2, y)
lm_totable_1 <- lm(y ~ x, df_to_lm)
lm_totable_2 <- lm(y ~ x + x2, df_to_lm)
lm_totable_3 <- lm(y ~ x*x2, df_to_lm)

modelsummary(
    models = list("Model 1" = lm_totable_1,
     "Model 2" = lm_totable_2, 
     "Model 3" = lm_totable_3), 
    fmt = 2,
    statistic = c("B" = "{estimate}", 
    "Błąd Standardowy" = "{std.error}"),  # Correctly renaming estimate
    coef_omit = "Intercept",
    shape = term ~ model + statistic,
    gof_map = "r.squared"
  )
Share Improve this question asked Mar 27 at 11:22 HonestioreHonestiore 773 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

The estimate column is governed by the estimate argument, not by the statistic argument.

modelsummary(
    models = list("Model 1" = lm_totable_1,
     "Model 2" = lm_totable_2, 
     "Model 3" = lm_totable_3), 
    fmt = 2,
    estimate = c("B" = "{estimate}"),
    statistic = c("Błąd Standardowy" = "{std.error}"),
    coef_omit = "Intercept",
    shape = term ~ model + statistic,
    gof_map = "r.squared"
  )

本文标签: rmodelsummary duplicates estiamte columns instead of renamingStack Overflow