0

I'm trying to get the interaction plot for my regression analysis. I already tested the regression. It's fine. Here's the code:

plot(data$ocs, data$efs, pch=19)
abline(lm(data$efs~data$ocs))

model1 <- lm(efs ~ ocs * rws, data = data)
summary(model1)
interact_plot(model=model1, pred = ocs, modx = rws, data = data)

Now everything works except interact_plot. I get back following error message:

Error in element_line(colour = text_and_line_color, linewidth = 0.5, linetype = 1,  : 
  unused argument (linewidth = 0.5)

What does this even mean?

interact_plot is a function from interactions!

rws = c(3.8, 3.8, 4.4, 3.2, 4, 3.8, 4.2, 4.6, 4.4, 3, 3.6, 3.4, 3.8, 4, 3.4, 
4, 2.2, 4, 3.4, 4, 2.8, 3, 3, 4.2, 3, 3.6, 3.8, 3.8, 3, 3.8, 
3.4, 3.2, 3.4, 3.4, 3.8, 4, 3.2, 3, 4.6, 4, 3.4, 3, 2.8, 3.8, 
3.8, 3.6, 2.8, 3.8, 4.6, 3, 3.8, 3.8, 3.4, 3.8, 2.4, 2.4, 4.2, 
3.6, 2.6, 3.6, 2.4, 3.2, 4, 4.2, 3.4, 3.2, 3.8, 4.8, 3.6, 4, 
3, 3.4, 4.2, 4.4, 3.8, 4.2, 4, 3.6, 4.4, 4, 3, 4.6, 4.4, 4, 3.4, 
4, 3.8, 4.8, 3.4, 3.4, 3.8, 3.8, 3.6, 3.6, 4.6, 3.6, 3.6, 2.6, 
2.8, 4.6, 4, 3.4, 3.8, 3.8, 3.6, 3, 3.2, 2.8, 3.6, 3.6, 3.4, 
3.6, 2.2, 4.2, 3.6, 3.8, 3.4, 3.8, 4.4, 2.4, 2, 3.4, 4.2, 3.2, 
3.2, 3.2, 3, 3.6, 3.6, 2.8, 3.6, 2.8, 3.6, 4.4, 3, 3.6, 3.2, 
4.8, 3.4, 3.8, 4.2, 3.2, 3.6, 3.8, 3.6, 3, 4, 3.8, 3.8, 4.2, 
3.6, 4.4, 3.6, 3.4, 3.8, 4.4, 3.4, 3.4, 4, 4.2, 3.8, 3.6, 4, 
4.6, 3.2, 4, 3.4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3.6, 2.4, 2, 3.4, 3.4, 0, 2.8, 2.4, 1.4, 2.8, 2.2, 2.4, 3.4, 
3.2, 1.8, 2, 3.8, 3.4, 1.8, 2, 2.6, 2.6, 3.4, 3.8, 3.6, 2.8, 
3.2, 3.4, 3.2, 2.4, 2.6, 3, 3.2, 3, 2.4, 3.4, 3.6, 3.6, 3, 3.6, 
4, 2.2, 2.8, 2.8, 3.2, 2.2, 1.6, 3.4)
jrcalabrese
  • 2,184
  • 3
  • 10
  • 30
  • 1
    Could you please share some reproducible data using `dput`? – Quinten Jan 17 '23 at 16:29
  • It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. Where does the `interact_plot` function come from? – MrFlick Jan 17 '23 at 16:44
  • sara, welcome to SO! Regarding the comments above, it's super important too to to list packages, I think `interact_plot` comes from **interactions**, which is not a package I'm familiar with. Might be important to check that function. – Michael Roswell Jan 17 '23 at 16:47
  • I added the data so it's reproducable. – sarathustra Jan 17 '23 at 17:00
  • Your error isn't reproducible for me; it produces an intersection plot. Are you sure you've called `library(interactions)` and that your packages and R versions are updated? – jrcalabrese Jan 17 '23 at 18:02
  • i'm going to cry!!!! thanks for your comment! I checked for updates but everything is in order! – sarathustra Jan 17 '23 at 18:32
  • What version of `interactions` and R are you currently using? – jrcalabrese Jan 17 '23 at 18:36
  • I use R Studio Version 1.3.1093. When I click "Check for updates" it says there are none. – sarathustra Jan 17 '23 at 18:47
  • 1
    Your RStudio version is [likely at least two years old](https://www.rstudio.com/products/rstudio/older-versions/), the current version is 2022.07.2. Please update R and RStudio to the most recent version if you can. – jrcalabrese Jan 17 '23 at 18:59
  • Did updating R and RStudio solve your error message? – jrcalabrese Jan 19 '23 at 12:58

1 Answers1

-1

First, put your data into a dataframe and run the model:

data<-as.data.frame(cbind(rws,efs,ocs))
model1 <- lm(efs ~ ocs * rws, data = data)

Next, the sjPlot package is very useful in this case.

library(sjPlot)
sjPlot::plot_model(model1, type='int')

You can also create neat tables with the same package:

sjPlot::tab_model(model1)
Ben
  • 1,113
  • 10
  • 26