I have a plm random effects model that includes an interaction between a continuous and a categorical variable (for illustrative purposes, let's say the categorical variable is strong religiosity and the continuous is contribution to charity).
Here is sample data (IRL, data much larger)
ratio contrib relig np_score ID year
.4 3 1 11 1 1990
0 7 0 8 2 1990
.9 7 1 6 1 1992
.7 6 1 10 1 1994
.1 2 0 4 2 1992
.3 9 0 8 2 1994
I want to plot the predicted outcomes as contribution increases depending on whether the respondent does or does not identify as strongly religious.
m1 <- plm(ratio ~ contrib + relig + np_score + contrib*relig,
data = panel_dat,
index = c("ID", "year"),
model = "random", random.method = "amemiya")
I have tried interaction.plot as follows:
interaction.plot(panel_dat$contrib, panel_dat$relig, predict(m1), col = 2:3, lty = 1)
But I get the error term:
Error in tapply(response, list(x.factor, trace.factor), fun) :
arguments must have same length
I would ultimately rather do this with ggplot2. Any suggestions? Seems like there should be a simple answer...