Multiple Linear regression to obtain coefficients
显示 更早的评论
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 个评论
John D'Errico
2016-4-30
编辑:John D'Errico
2016-4-30
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
2016-4-30
the cyclist
2016-4-30
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
2016-4-30
编辑:Stephane Magnam
2016-4-30
John D'Errico
2016-5-1
编辑:John D'Errico
2016-5-1
So then data is y in the model?
y = a + b*x + c*z
Stephane Magnam
2016-5-1
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Linear Predictive Coding 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!