How to plot a regression with interaction variables

Viewed 20

i am trying to plot the following equations in R in order to observe their effects:

KickLikes <- (lm(dataT$Kickstarter  ~ dataT$Twitter*dataT$likes))
summary(KickLikes)

KickRegM3 <- (lm(dataT$Kickstarter  ~ dataT$Twitter*dataT$retweets*dataT$likes))
summary(KickRegM3)

All of my variables are numerical Is there an easy way to plot these models ?

> dput(head(dataT))
structure(list(date = c("2021-01-01", "2021-01-02", "2021-01-03", 
"2021-01-04", "2021-01-05", "2021-01-06"), Kickstarter = c(4L, 
0L, 0L, 0L, 8L, 4L), Money = c(50278.64, 0, 0, 0, 366279.590415302, 
172073.0471292), Backers = c(2880L, 0L, 0L, 0L, 6588L, 3528L), 
    Twitter = c(1324L, 1548L, 1297L, 1585L, 1636L, 1583L), replies = c(882L, 
    1252L, 910L, 1018L, 810L, 1000L), likes = c(22859L, 24375L, 
    17854L, 20341L, 19521L, 19401L), retweets = c(8621L, 8239L, 
    6141L, 6728L, 6938L, 6842L)), row.names = c(NA, -6L), class = c("tbl_df", 
"tbl", "data.frame"))
1 Answers

You can plot conditional predictions or conditional marginal effects using the marginaleffects package: https://vincentarelbundock.github.io/marginaleffects/ (Disclaimer: I am the author.)

dataT <- structure(list(date = c("2021-01-01", "2021-01-02", "2021-01-03", 
"2021-01-04", "2021-01-05", "2021-01-06"), Kickstarter = c(4L, 
0L, 0L, 0L, 8L, 4L), Money = c(50278.64, 0, 0, 0, 366279.590415302, 
172073.0471292), Backers = c(2880L, 0L, 0L, 0L, 6588L, 3528L), 
    Twitter = c(1324L, 1548L, 1297L, 1585L, 1636L, 1583L), replies = c(882L, 
    1252L, 910L, 1018L, 810L, 1000L), likes = c(22859L, 24375L, 
    17854L, 20341L, 19521L, 19401L), retweets = c(8621L, 8239L, 
    6141L, 6728L, 6938L, 6842L)), row.names = c(NA, -6L), class = c("tbl_df", 
"tbl", "data.frame"))

KickLikes <- lm(Kickstarter ~ Twitter * likes, data = dataT)

library(marginaleffects)

plot_cme(KickLikes, effect = "Twitter", condition = "likes")


plot_cap(KickLikes, condition = c("Twitter", "likes"))

Related