Multiple Linear Regression using "REGRESS"

Hello
I am using regress function for multiple linear regression analysis. Once I obtain the values of coefficients, I substitute in the equtation to get the new / predicted values of y.
Then I make the scatterplot of y_original and y_predicted. How can I show the regression line for equation y = ax1 + bx2 + cx3 + d on this scatter plot ? What code should I write for this problem ?
Secondly, How can I find the random error for this multiple linear regression relationship ?

1 Comment

Thanks , this means I cannot plot a multidimensional plot, which can show me the relationship of all three variables (x1,x2,x3) with y ????
Secondly, every regression equation has some random error associated with it. How can we find that random error and what can we conclude out of it ? How shall we interpret that random error ?
Thanks

Sign in to comment.

Answers (2)

dpb
dpb on 5 Oct 2013
s=sprintf('y = %.2f*ax1 + %.2f*x2 + %.2f*x3 + %.2f', b); text(x,y,s)
b is the coefficient matrix from regress; x, y are the coordinates of location where you wish to write the equation in the units of the x- and y-axes used for scatter

7 Comments

Actually I want to show the regression line on scatter plot, not only the equation.
Just evaluate equation at a set of coordinates. Since it's linear in x1 or x2, depending on the axis against which you're plotting it, it only takes to points to define the line for a give value of the other variable.
Maybe I am missing something but from what you are asking, you can not. If your plot is yPredicted vs yActual, your best fit would be a line of yActual and yActual with yPedicted at yActual being your scatter points.
Otherwise, your yPredicted is a surface at a given x1 or x2 or x3.
I can plot two types of graphs 1. Plot between Y-actual, X1, X2 and X3. How can I plot a scatter plot for this in 2D along with regression line passing via the scatter plot.
2. Scatter Plot between Y-Actual and Y-Predicted after substituting the coefficients(Y = ax1 + bx2 + cx3 +d + error). Can I draw a regression line for this scatter plot showing relation between Y predicted and Y actual.
I'm with Marc. Let's say that x1, x2, and x3 were x, y, and z and you had samples of the temperature in the room. So at any point in 3 dimensional space you have a estimated temperature, and at some of the locations you have training data (temperatures). The y value is just a different value. If you pin down one of the coordinates, then you can plot a surface with estimated and actual y. If you pin down 2 two of the coordinates, then you can plot a curve like you're probably thinking of. But it would take you fixing two of the values. So you can get a curve of y vs. x1 for fixed x2 and x3. It would look different for different x2 and x3. I think this is your scenario 1. Of course you can do your scenario 2 (scatter y training vs. y predicted) but only for the training data , not for all x1, x2, and x3.
Thanks , this means I cannot plot a multidimensional plot, which can show me the relationship of all three variables (x1,x2,x3) with y ????
Secondly, every regression equation has some random error associated with it. How can we find that random error and what can we conclude out of it ? How shall we interpret that random error ?
Thanks
@ Image Analyst :
Thanks. Now after applying regress, I get the coefficients a,b,c,d for the following equation:
y_predicted = a.x1 + b.x2 +c.x3 + d
When I substitute these coefficients a,b,c,d along with x1 dataset, x2 dataset, x3 dataset respectively into the equation,I will get the y_predicted dataset. For making a scatter plot between y_original dataset and y_predicted dataset, I use use the following command:
plot(y_predicted,y_original,'o')
Question is:
How can I show the line representing the above equation ( y_predicted = a.x1 + b.x2 +c.x3 + d ) on this scatter plot ?

Sign in to comment.

Priya
Priya on 13 Oct 2013
Thanks , this means I cannot plot a multidimensional plot, which can show me the relationship of all three variables (x1,x2,x3) with y ????
Secondly, every regression equation has some random error associated with it. How can we find that random error and what can we conclude out of it ? How shall we interpret that random error ?
Thanks

5 Comments

How would you propose to show 4D in a 3D world?
doc isosurface
might be of some use in allowing you to pull and show surfaces of response with two variables at a third fixed...
Interpretation of residuals and or errors in RSM is dependent upon the underlying data error structure -- and whether on considers error in the independent variables or only in the measured responses (the latter far more commonly done).
Again, see Draper and Smith text referenced earlier or other texts on regression analysis for the details; this isn't a Matlab question and being so general is OT for the Answers forum.
Priya
Priya on 15 Oct 2013
Edited: Priya on 15 Oct 2013
@ Image Analyst :
Thanks. Now after applying regress, I get the coefficients a,b,c,d for the following equation:
y_predicted = a.x1 + b.x2 +c.x3 + d
When I substitute these coefficients a,b,c,d along with x1 dataset, x2 dataset, x3 dataset respectively into the equation,I will get the y_predicted dataset. For making a scatter plot between y_original dataset and y_predicted dataset, I use use the following command:
plot(y_predicted,y_original,'o')
How can I show the regression line (y_predicted = a.x1 + b.x2 +c.x3 + d ) on this scatter plot ?
It's got the same problem as the raw data -- there are three independent variables plus the response to show....a scatter plot can only show two of them.
No, in this case I have only two variables : y_predicted which is obtained by substituting the values in the above regression equation and y_original (input y dataset).
I can plot the scatter plot, but don't know how to show the line on the plot.
Is it possible to show the line represented b this equation on the scatter plot.
Oh, misinterpreted the question or the intended use of "line" -- that there's no line on the plot by your above command is because that's what you told it to do...
plot(y_predicted,y_original,'o')
says use the 'o' marker; you didn't specify a line style so Matlab obeyed and didn't, either. Use
plot(y_predicted,y_original,'o-')
or alternate linestyle of choice.
doc plot % documents above behavior and marker/linestyle choices

Sign in to comment.

Asked:

on 5 Oct 2013

Commented:

dpb
on 15 Oct 2013

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!