Suppose I have a MLR equation $y=b_0+b_1x_1+b_2x_2 + e$.

If I were to plot this equation, should it not produce a "line" ? I have looked into response surfaces and I am not sure how one would derive the set of equations required to plot this plane?

  • 3
    $\begingroup$ nope, as long as x1 and x2 are your axes you should get a plane $\endgroup$ – MikeP Aug 11 '15 at 15:36

As @MikeP said, you get a plane because you will want to get predictions for any combination of $(x_1,x_2)$-values.

Here is a graphical illustration, with $y$ values above the surface in red and those below in green:

enter image description here


n <- 20

# generate some data
x1 <- runif(n)
x2 <- runif(n)
u <- rnorm(n,sd=.2)
y <- .6*x1 + .1*x2 + u

# do an OLS regression
b0 <- lm(y~x1+x2)$coefficients[1]
b1 <- lm(y~x1+x2)$coefficients[2]
b2 <- lm(y~x1+x2)$coefficients[3]

# create a grid of values for which predictions are desired
xax1 <- xax2 <- seq(0,1,by=.025)

zdim <- function(xax1,xax2,b0,b1,b2) {

# create fitted values
yhat <- outer(xax1, xax2, zdim,b0=b0,b1=b1,b2=b2)  

# plot
alpha <- 0.3
mycols <- c(rgb(1,0,0,2*alpha),rgb(0,0,1,alpha),rgb(0,1,0,2*alpha))
persp(xax1,xax2, yhat,col=mycols[2],ticktype="detailed") -> res

# add points to surface plot
fit <- b0+x1*b1+x2*b2
points(trans3d(x1[y<fit],x2[y<fit],y[y<fit],pmat=res), col = mycols[3], pch = 16)
points(trans3d(x1[y>fit],x2[y>fit],y[y>fit],pmat=res), col = mycols[1], pch = 16)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.