Multiple Linear regression to obtain coefficients
Show older comments
I need to perform a multiple linear regression to obtain the coefficients for an equation of the form y=a+bx+cz. a,b, and c being the coefficients and x and z are variables for which I have data: 24 data points. 8 value for x for which I have 3 values of y. Those 3 values correspond each to 1 values of z. So I have 3 values of z. Thus x*z=8*3=24 data points. Here is my code but it's wrong after checking the solution for a specific data point. I am not sure what is wrong. I want to use lsqin in a simple way like this. Any help would be appreciated.
function multiple_linear_regression
z=[0 2 4];
x=[10 12 13 14 16 18 20 23]';
data=[13 11 10.5;
8 12 10;
10 10 9;
9 9 8;
9 7 10;
10 8 9;
8 6 5.8;
5 3.5 2];
y=lsqlin(data,x);
end
Thank you
6 Comments
John D'Errico
on 30 Apr 2016
Edited: John D'Errico
on 30 Apr 2016
HUH?
You have listed 3 values of z. You have 8 values of x. Where did the array data come from? What is y?
Somehow I don't think you understand how to do regression, or maybe what it is.
If your goal is to estimate coefficients of [a,b,c] in the model
y = a + b*x + c*z
then you have not provided sufficient information to do so in any meaningful way. It is certainly true that the way you have tried to use lsqlin will not succeed.
So please try explaining your problem more clearly. Provide all of the information.
Stephane Magnam
on 30 Apr 2016
the cyclist
on 30 Apr 2016
My best guess here is that the possible values of x and z are as Stephane has listed them, and data is the 2-dimensional results for the (x,z) combinations. Therefore, the better definition of the variables for input into a typical MATLAB regression routine is
x = [10 12 13 14 16 18 20 23 10 12 13 14 16 18 20 23 10 12 13 14 16 18 20 23 ]';
z = [0 2 4 0 2 4 0 2 4 0 2 4 0 2 4 0 2 4 0 2 4 0 2 4]';
This still leaves a few questions, Stephane. My main one is why did you think that lsqlin is the best function for your regression? You don't mention any other constraint. If you have the Statistics and Machine Learning Toolbox, I would probably just use regress. But I can imagine some possible constraints that might require lsqlin.
Stephane Magnam
on 30 Apr 2016
Edited: Stephane Magnam
on 30 Apr 2016
John D'Errico
on 1 May 2016
Edited: John D'Errico
on 1 May 2016
So then data is y in the model?
y = a + b*x + c*z
Stephane Magnam
on 1 May 2016
Accepted Answer
More Answers (0)
Categories
Find more on Linear Predictive Coding in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!