dat <- structure(list(x = c(1, 2, 3, 4, 5), y = c(8, 12, 22, 28, 30)), .Names = c("x", "y"), row.names = c(NA, -5L), class = "data.frame") summary(dat$x) summary(dat$y) fm1 <- lm(dat$y ~ dat$x, data = dat) fm1 fm2 <- lm(dat$x ~ dat$y, data = dat) fm2 fm1_m <- fm1$coefficients[1] fm1_q <- fm1$coefficients[2] fm2_m <- fm2$coefficients[1] fm2_q <- fm2$coefficients[2] xx <- 1:5 yy <- 8:30 convyval <- function(e){(1/fm2_q)*e - (fm2_q/fm2_m)} # PREDICT VALUES yhat1 <- predict(fm1, list(x = xx)) yhat2 <- convyval(yy) # PLOT DATA plot(dat$x,dat$y) lines(xx, yhat1, col="blue", lwd=2) lines(xx, yhat2, col="red", lwd=2)