ggeffects icon indicating copy to clipboard operation
ggeffects copied to clipboard

Adding linetype as an argument based on significance of slope

Open AlexandreGareau opened this issue 1 year ago • 4 comments

Hi I was wondering if you would be interested to add a linetype argument to the plot() function that would make dash line for non-significant slope and solid line for significant slope.

I attempted to make this modification but realize that I could not edit the geom_line() directly after plotting, but had to modify the constructor directly after creating the plot.

When presenting significant interaction effect, it seems important to present which line are significant or not, given that some null effect might look interpretable without this information.

Thank you for this awesome package. I am not an enough advanced user to directly propose the change in a pull request. Sorry :(

AlexandreGareau avatar Sep 29 '23 12:09 AlexandreGareau

I'm not sure, but are you looking for Johnson-Neyman intervals? See https://strengejacke.github.io/ggeffects/articles/introduction_comparisons_2.html

strengejacke avatar Oct 03 '23 09:10 strengejacke

Not specifically, because this only applies to continuous data. I am looking to use the hypothesis_test() output to change linetype conditionnally. I am worried that people in my organization will interpret line that are not statistically significant and I would like to make clear graphical insight for people to realize that some lines should be interpreted as null (non-significant).

I was able to do it by using delete_layers() from ggpmisc and respecify the geom_line() layer.

Do you understand my proposition better? I find that presenting slopes in a graphic without there statistical significance is... a slippery slope ;)

AlexandreGareau avatar Oct 03 '23 11:10 AlexandreGareau

I'm not quite sure if this could be automated - what would be the "null" you're testing against? Simple contrasts if a slope differs from 0, or pairwise comparisons (i.e. do certain groups differ significantly)? What if you have categorical predictors only?

Currently, based on hypothesis_test(), I would manually create the plot and set line type aesthetics for certain groups, e.g.:

library(ggeffects)
library(ggplot2)

data(iris)
m <- lm(Sepal.Width ~ Sepal.Length * Species, data = iris)
pr <- ggpredict(m, c("Sepal.Length", "Species"))

ggplot(pr, aes(x = x, y = predicted, ymin = conf.low, ymax = conf.high, color = group, fill = group)) +
  geom_ribbon(alpha = 0.1, color = NA) +
  geom_line(aes(linetype = group)) +
  scale_linetype_manual(values = c(1, 2, 2)) +
  see::scale_color_flat() +
  see::scale_fill_flat()

Created on 2023-10-03 with reprex v2.0.2

strengejacke avatar Oct 03 '23 14:10 strengejacke

The null would come from the hypothesis_test(..., test = NULL) p-value for each slope (simple slope analysis). A traditional p < .05 would be used. The comparison of slope is already provided by the interaction term in a traditional moderated regression table.

Anyhow your solution offers some flexibility that I can work around instead of using delete_layers(). I could also add a column to the ggpredict() to distinguish statistically significant slope for the ggplot data.

Thank you for taking the time to respond.

I mostly want to integrate some information about hypothesis_test(..., test = NULL) in the plot to help interpret the interaction.

AlexandreGareau avatar Oct 04 '23 14:10 AlexandreGareau