Labelling interaction terms in `tab_model`
onesandzeroes opened this issue · comments
It would be great if tab_model
(and other functions) could apply variable labels to interactions, as in the below example:
library(sjPlot)
library(sjlabelled)
library(dplyr)
data(iris)
iris = iris %>%
mutate(Species = as.factor(Species)) %>%
var_labels(Petal.Length = "Petal length",
Petal.Width = "Petal width",
Species = "Species of flower")
m1 = lm(Petal.Length ~ Petal.Width * Species, data = iris)
tab_model(m1, prefix.labels = "label")
I'd like to have a go at a pull request for this, but I'm a bit unsure where to start. Should insight
be providing information about interaction terms? Or should this be done "post-hoc" in sjlabelled::get_term_labels
? It seems like if insight
was providing this info in a robust way, we could do something smarter than just splitting the coefficient names by ":"
and trying to match them up to terms.
insight now provides a function find_interactions()
, which helps finding the interaction terms, so we can use this information in sjlabelled::get_term_labels()
to label interaction terms.
So I would say the place to address this is sjlabelled (I'll transfer this issue).
ANy news on this? Would you still like to open a PR?
Sorry, I did have an initial look at this but it wasn't as straightforward as I thought - I think the main issue was it wasn't easy to go from what find_interactions()
is returning to the actual coefficients that need to be labelled (e.g. coef(model)
). Right now I don't think I have time to work on this, so no PR in the near future from me.
Ok, I leave this issue open, maybe I can address it.