In an effort to help populate the R tag here, I am posting a few questions I have often received from students. I have developed my own answers to these over the years, but perhaps there are better ways floating around that I don't know about.
The question: I just ran a regression with continuous
thelm <- lm(y~x*f,data=thedata)
##restrict prediction to the valid data
##from the model by using thelm$model rather than thedata
thedata$yhat <- predict(thelm,
The effects package has good ploting methods for visualizing the predicted values of regressions.
thedata<-data.frame(x=rnorm(20),f=rep(c("level1","level2"),10)) thedata$y<-rnorm(20,,3)+thedata$x*(as.numeric(thedata$f)-1) library(effects) model.lm <- lm(formula=y ~ x*f,data=thedata) plot(effect(term="x:f",mod=model.lm,default.levels=20),multiline=TRUE)