# Response Surfaces and Multiple Linear Regression

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?

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

## 1 Answer

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: CODE:

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 b1 <- lm(y~x1+x2)$coefficients
b2 <- lm(y~x1+x2)\$coefficients

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

zdim <- function(xax1,xax2,b0,b1,b2) {
b0+xax1*b1+xax2*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,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, pch = 16)
points(trans3d(x1[y>fit],x2[y>fit],y[y>fit],pmat=res), col = mycols, pch = 16)