Given two variables, x and y, I run a dynlm regression on the variables and would like to plot the fitted model against one of the variables and th
x
y
what you're looking for is resid(model). Try this:
resid(model)
library(dynlm) x <- 10+rnorm(100) y <- 10+rnorm(100) model <- dynlm(x ~ y) plot(x, type="l", col="red", ylim=c(min(c(x,y,resid(model))), max(c(x,y,resid(model))))) lines(y, type="l", col="green") lines(resid(model), type="l", col="blue")