Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistent renaming of statistic and estimate columns #722

Closed
mps9506 opened this issue Mar 14, 2024 · 1 comment
Closed

Inconsistent renaming of statistic and estimate columns #722

mps9506 opened this issue Mar 14, 2024 · 1 comment

Comments

@mps9506
Copy link

mps9506 commented Mar 14, 2024

Thanks for adding the ability to easily rename statistics and estimates in the development version of modelsummary(). This is very handy, but I came across a few inconsistencies in application when reshaping the table to have statistics in a separate column (I could very well be missing something obvious here).

  • Example 1a renaming confidence intervals splits the column and replaces the estimate column name with NA:
library(modelsummary)
mod <- lm(mpg ~ factor(cyl), mtcars)

modelsummary(
  mod, 
  estimate = c("$\\hat{\\beta}$" = "estimate"),
  statistic = c("Confidence Interval" = "conf.int"),
  shape = term ~ model + statistic)
+--------------+---------+---------------------+--------+
|              | (1)                           |        |
+--------------+---------+---------------------+--------+
|              | NA      | Confidence Interval | (1)    |
+==============+=========+=====================+========+
| (Intercept)  | 26.664  | 24.676              | 28.651 |
+--------------+---------+---------------------+--------+
| factor(cyl)6 | -6.921  | -10.108             | -3.734 |
+--------------+---------+---------------------+--------+
| factor(cyl)8 | -11.564 | -14.220             | -8.908 |
+--------------+---------+---------------------+--------+
| Num.Obs.     | 32      |                     |        |
+--------------+---------+---------------------+--------+
| R2           | 0.732   |                     |        |
+--------------+---------+---------------------+--------+
| R2 Adj.      | 0.714   |                     |        |
+--------------+---------+---------------------+--------+
| AIC          | 170.6   |                     |        |
+--------------+---------+---------------------+--------+
| BIC          | 176.4   |                     |        |
+--------------+---------+---------------------+--------+
| Log.Lik.     | -81.282 |                     |        |
+--------------+---------+---------------------+--------+
| RMSE         | 3.07    |                     |        |
+--------------+---------+---------------------+--------+ 

Example 1b: using "[{conf.low}, {conf.high}]" fails to rename the confidence interval column:

modelsummary(
  mod, 
  estimate = c("$\\hat{\\beta}$" = "estimate"),
  statistic = c("Confidence Interval" = "[{conf.low}, {conf.high}]"),
  shape = term ~ model + statistic)
+--------------+---------------+---------------------------+
|              | (1)                                       |
+--------------+---------------+---------------------------+
|              | $\hat{\beta}$ | [{conf.low}, {conf.high}] |
+==============+===============+===========================+
| (Intercept)  | 26.664        | [24.676, 28.651]          |
+--------------+---------------+---------------------------+
| factor(cyl)6 | -6.921        | [-10.108, -3.734]         |
+--------------+---------------+---------------------------+
| factor(cyl)8 | -11.564       | [-14.220, -8.908]         |
+--------------+---------------+---------------------------+
| Num.Obs.     | 32            |                           |
+--------------+---------------+---------------------------+
| R2           | 0.732         |                           |
+--------------+---------------+---------------------------+
| R2 Adj.      | 0.714         |                           |
+--------------+---------------+---------------------------+
| AIC          | 170.6         |                           |
+--------------+---------------+---------------------------+
| BIC          | 176.4         |                           |
+--------------+---------------+---------------------------+
| Log.Lik.     | -81.282       |                           |
+--------------+---------------+---------------------------+
| RMSE         | 3.07          |                           |
+--------------+---------------+---------------------------+ 

and, example 2, using a named vector greater than length equal 1 for the statistics columns causes the estimate column to be named NA (maybe I'm using this incorrectly?):

modelsummary(
  mod, 
  estimate = c("$\\hat{\\beta}$" = "estimate"),
  statistic = c("t-stat" = "statistic",
                "p-value" = "p.value"),
  shape = term ~ model + statistic)
+--------------+---------+--------+---------+
|              | (1)                        |
+--------------+---------+--------+---------+
|              | NA      | t-stat | p-value |
+==============+=========+========+=========+
| (Intercept)  | 26.664  | 27.437 | <0.001  |
+--------------+---------+--------+---------+
| factor(cyl)6 | -6.921  | -4.441 | <0.001  |
+--------------+---------+--------+---------+
| factor(cyl)8 | -11.564 | -8.905 | <0.001  |
+--------------+---------+--------+---------+
| Num.Obs.     | 32      |        |         |
+--------------+---------+--------+---------+
| R2           | 0.732   |        |         |
+--------------+---------+--------+---------+
| R2 Adj.      | 0.714   |        |         |
+--------------+---------+--------+---------+
| AIC          | 170.6   |        |         |
+--------------+---------+--------+---------+
| BIC          | 176.4   |        |         |
+--------------+---------+--------+---------+
| Log.Lik.     | -81.282 |        |         |
+--------------+---------+--------+---------+
| RMSE         | 3.07    |        |         |
+--------------+---------+--------+---------+ 

output from sessionInfo()

R version 4.3.1 (2023-06-16 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 11 x64 (build 22631)

Matrix products: default


locale:
[1] LC_COLLATE=English_United States.utf8  LC_CTYPE=English_United States.utf8    LC_MONETARY=English_United States.utf8 LC_NUMERIC=C                          
[5] LC_TIME=English_United States.utf8    

time zone: America/New_York
tzcode source: internal

attached base packages:
[1] grid      stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] survey_4.4-1            survival_3.5-7          Matrix_1.6-1.1          modelsummary_1.9.9.9999

loaded via a namespace (and not attached):
 [1] compiler_4.3.1       crayon_1.5.2         Rcpp_1.0.11          tinytable_0.1.0.9000 callr_3.7.3          splines_4.3.1        fastmap_1.1.1        lattice_0.21-8      
 [9] R6_2.5.1             tables_0.9.17        generics_0.1.3       curl_5.0.2           knitr_1.45           MASS_7.3-60          backports_1.4.1      checkmate_2.3.1     
[17] desc_1.4.2           insight_0.19.8.10    rprojroot_2.0.3      DBI_1.1.3            rlang_1.1.3          performance_0.10.9.6 xfun_0.42            parameters_0.21.5.7 
[25] datawizard_0.9.1.7   cli_3.6.2            ps_1.7.5             digest_0.6.33        processx_3.8.2       rstudioapi_0.15.0    remotes_2.4.2.1      prettyunits_1.2.0   
[33] glue_1.6.2           data.table_1.14.8    mitools_2.4          pkgbuild_1.4.2       fansi_1.0.4          bayestestR_0.13.2    tools_4.3.1          htmltools_0.5.6     
@vincentarelbundock
Copy link
Owner

thanks a lot for the report. I really appreciate that you took the time to craft minimal and useful example.

I believe that all the issues highlighted are now fixed on Github.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants