IDEMSInternational / R-Instat

A statistics software package powered by R
http://r-instat.org/
GNU General Public License v3.0
38 stars 103 forks source link

Interaction plots #4429

Open lilyclements opened 6 years ago

lilyclements commented 6 years ago

I quite like using interaction plots when exploring the data and thought perhaps something like this could be appropriate for R-Instat especially since it is quite an easy couple of functions to implement.

Three Way Interaction There's a really easy function to do a three-way interaction plot (And it's ggplot!). It's with the dae package and is interaction.ABC.plot. I've used it several times but will show their example as then I have code which can be replicated;

interaction.ABC.plot(response = MOE, x.factor = A, groups.factor = B,
                     trace.factor = C, data=ABC.Interact.dat,
                     title = "Three-Way Interaction Plot")

image

Two-Way Interaction I haven't been able to find a function like the one above to do this. However, it can be done quite nicely with the qplot function outlined here - https://sebastiansauer.github.io/vis_interaction_effects/

So on that link there is this code to do a two-way interaction plot

library(ggplot2) 
library(dplyr) 
tips <- read.csv("https://sebastiansauer.github.io/data/tips.csv")
qplot(x = total_bill, y = tip, data = tips, color = sex) +
  geom_smooth(method = "lm") 

And this is the plot that gives (again this is given on the link above)

image

It's not a necessary feature, but one I know I use a lot in R and I think could be quite appropriate in R-Instat! Especially since the three-way-interaction plot is so simple.

In fact if the lecturer strike continues onto next week then I might be able to implement it. Although, hopefully I'll have lectures again by then.

rdstern commented 6 years ago

That's really interesting. We do need to get back to our modelling dialogues and that certainly includes having interaction plots. Recently I have become more impressed with the outputs from the mosaic project, see, for example here.

They have the main package called mosaic, also mosaiccore, and mosaicmodel. I'd be interested in your views on that. They have recently also added ggplot2 to their original use of the lattice plotting system.

lilyclements commented 6 years ago

Sorry it's taken a while to reply! I couldn't get it to work on my macbook for some reason and wasn't reunited with my laptop until Tuesday.

plotModel is a nice function. It's not one I've come across before, but is definitely one which looks really useful.

If I can/Once I do work out confidence intervals on it then it's definitely a preference to the one I was suggesting.

dannyparsons commented 6 years ago

These all look interesting. Just one comment that the two way interaction plot we can do all through our scatter plot dialog as we have the geom_smooth options there now.

Ogik99 commented 5 years ago

5164