jacob-long / jtools

Tools for summarizing/visualizing regressions and other helpful stuff
https://jtools.jacob-long.com
GNU General Public License v3.0
164 stars 22 forks source link

Rename terms using partial string matching #122

Closed mattysimonson closed 2 months ago

mattysimonson commented 2 years ago

Renaming (and filtering out) coefficients in plot_summs() and export_summs() is already straightforward, but it could be made less cumbersome through partial string matching. Consider your example from the plot_summs documentation

plot_summs(fit1, fit2, fit3,
           coefs = c("Frost Days" = "Frost", "% Illiterate" = "Illiteracy",
                     "Murder Rate" = "Murder"),
           scale = TRUE, robust = TRUE)

Supposed now the model contained Frost * Murder. I would have to type in "Frost Days x Murder Rate" = "Frost:Murder" for the interaction. Ideally, though, plot_summs would recognize that if I wanted to remane Frost and Murder then I would also want to rename the interaction the same way. This issue also applies to export_summs.

(one complication is that interaction terms often require a linebreak after the x symbol in order to comfortably fit in a plot without blowing up the labeling area)

Aside from interactions, partial string matching would be a useful feature in the event that I simply had a lot of variables I wanted in include with similar names. If my data contained region_north, region_west,region_south, andregion_east, it would be great if I could typecoef = "region"to catch them all. A complementarydrop_coefs argument` would help as well.

All of this is inspired by the new fixest package's etable function which makes including, excluding, and renaming very easy. See the keep, drop, order and dict arguments: https://lrberge.github.io/fixest/reference/etable.html

jacob-long commented 2 months ago

FYI on implementation: I'm using regex matching and it requires the specification of an additional argument, coefs.match to "regex" to preserve the legacy behavior by default. This only applies to plot_coefs()/plot_summs(); in the case of export_summs(), I'm relying too much on an external package to process the coefficient names to be able to use the same approach.