vincentarelbundock / marginaleffects

R package to compute and plot predictions, slopes, marginal means, and comparisons (contrasts, risk ratios, odds, etc.) for over 100 classes of statistical and ML models. Conduct linear and non-linear hypothesis tests, or equivalence tests. Calculate uncertainty estimates using the delta method, bootstrapping, or simulation-based inference
https://marginaleffects.com
Other
444 stars 46 forks source link

base::summary doesn't work well with marginaleffects::comparisons #1108

Closed hrdawson closed 5 months ago

hrdawson commented 5 months ago

I'm trying to use this solution to a question on StackOverflow: https://stackoverflow.com/a/72973618/6039476 All the code that I used (including the example data) is from that link. However, the result that I get is very different from the handy comparisons table shown in that answer. Instead, I get this result:

> summary(cmp)
     rowid       term             contrast            estimate       std.error       statistic        p.value             s.value          conf.low       conf.high     
 Min.   :1   Length:2           Length:2           Min.   :45.10   Min.   :11.65   Min.   :3.195   Min.   :0.0000000   Min.   : 9.483   Min.   :17.44   Min.   : 72.77  
 1st Qu.:1   Class :character   Class :character   1st Qu.:56.58   1st Qu.:12.27   1st Qu.:4.349   1st Qu.:0.0003493   1st Qu.:18.946   1st Qu.:30.12   1st Qu.: 83.04  
 Median :1   Mode  :character   Mode  :character   Median :68.05   Median :12.88   Median :5.504   Median :0.0006985   Median :28.410   Median :42.80   Median : 93.30  
 Mean   :1                                         Mean   :68.05   Mean   :12.88   Mean   :5.504   Mean   :0.0006985   Mean   :28.410   Mean   :42.80   Mean   : 93.30  
 3rd Qu.:1                                         3rd Qu.:79.53   3rd Qu.:13.50   3rd Qu.:6.658   3rd Qu.:0.0010478   3rd Qu.:37.873   3rd Qu.:55.49   3rd Qu.:103.57  
 Max.   :1                                         Max.   :91.00   Max.   :14.12   Max.   :7.812   Max.   :0.0013971   Max.   :47.336   Max.   :68.17   Max.   :113.84  

  predicted_lo    predicted_hi     predicted        side    color       ppt_id        RT       
 Min.   :601.6   Min.   :646.7   Min.   :601.6   left :2   red :2   1      :2   Min.   :594.6  
 1st Qu.:601.6   1st Qu.:658.2   1st Qu.:601.6   right:0   blue:0   2      :0   1st Qu.:594.6  
 Median :601.6   Median :669.6   Median :601.6                      3      :0   Median :594.6  
 Mean   :601.6   Mean   :669.6   Mean   :601.6                      4      :0   Mean   :594.6  
 3rd Qu.:601.6   3rd Qu.:681.1   3rd Qu.:601.6                      5      :0   3rd Qu.:594.6  
 Max.   :601.6   Max.   :692.6   Max.   :601.6                      6      :0   Max.   :594.6  
                                                                    (Other):0  

When I use View(cmp) in R Studio, I see that the cmp object does contain the handy table shown in the StackOverflow question so I think this is something incompatible with base::summary(). I would leave a comment on the StackOverflow answer, except I don't yet have 50 reputation and am not eligible to comment. In the end, a very handy function–if you know where to find the result. Thanks!

vincentarelbundock commented 5 months ago

Thanks for report. I have updated the StackOverflow post.

The summary() syntax is no longer supported, and I recommend using avg_comparisons() or comparisons() instead. This was a breaking change made in preparation for the release of version 1.0.0, which will have a stable user interface for the foreseeable future.