model3 <- lm(lsat ~ (wwhours + I(wwhours^2))*jahreslohn + age + I(age^2) + female + employed + log(jahreslohn) + hhsize, data = d)
this is my linear model. "jahreslohn" = yearly income. i want to plot this function but I am not able to.
I tried with a new data frame keeping all the other variables on the mean
# graphical display of interaction effect
newdata_inc <- data.frame( wwhours = seq(1, 70, by = 1),
age = mean(d$age),
female = "Men", "Women",
employed = "employed",
jahreslohn = d$jahreslohn,
hhsize = mean(d$hhsize))
newdata_inc$yhat <- predict(model3, newdata_inc)
ggplot(newdata_inc, aes(x=wwhours, y=yhat)) +
labs(x="working hours", y="Life Satisfaction") +
geom_line(aes(wwhours, yhat, linetype=jahreslohn), linewidth=1.5) +
theme_bw()
Error in data.frame(wwhours = seq(1, 70, by = 1), age = mean(d$age), female = "Men", :
arguments imply differing number of rows: 70, 1, 188153