How can I do non-linear regression for three varietals?

조회 수: 41 (최근 30일)
Riyadh Muttaleb
Riyadh Muttaleb 2017년 1월 23일
댓글: Star Strider 2017년 1월 25일
Hi All,
I have matrix with three variables (x,y,z) I would like to get best non linear regression for these variables using like this equation: Eq=a*x+b*y+c*z+d
How can I get the constants and correlation coefficient?
Thanks in advance,
Riyadh
  댓글 수: 4
abuzer
abuzer 2017년 1월 23일
I assumed he wrote wrong equation. Because he asks nonlinear..
Riyadh Muttaleb
Riyadh Muttaleb 2017년 1월 23일
Thank you for your notes, let's say how can I regress three variables?, I have tried to apply the function you have mentioned but I couldn't to apply them for three variables

댓글을 달려면 로그인하십시오.

채택된 답변

Star Strider
Star Strider 2017년 1월 23일
The equation you posted is linear. Assuming it is a stand-in for a nonlinear equation, the usual way of fitting a function of several variables is to create a matrix of the incependent variables and passing that as one argument to the objective and fitting functions.
Example:
% % % MAPPING: x = xyz(:,1), y = xyz(:,2), z = xyz(:,3), a = b(1), b= B(2), c = b(3), d = b(4)
xyz = [x(:) y(:) z(:)];
Eq = @(b,xyz) b(1).*xyz(:,1) + b(2).*xyz(:,2) + b(3)*zyz(:,3) + b(4);
Then just use them as arguments to whatever fitting function you want (such as nlinfit or lsqcurvefit).
  댓글 수: 4
Riyadh Muttaleb
Riyadh Muttaleb 2017년 1월 25일
Thank you,
this exactly what I have:
SPM(dependent variable)=a+b*S+c*A (S and A are independent variable)
so the equatio will be B = nlinfit(SA, a(:), Eq, B0)?; What is B0? I have values of SPM, S, and A and I would like to have the values of the constants a,b ,c with correlation coefficient R^2.
Thanks in advance
Star Strider
Star Strider 2017년 1월 25일
My pleasure.
You have described a linear model. I would do something like this:
Prms = [ones(size(SPM(:))), S(:), A(:)]\SPM(:);
a = Prms(1)
b = Prms(2)
c = Prms(3)
The core MATLAB linsolve function and the Statistics and Machine Learning Toolbox regress and glmfit functions (and several others) are also options.
That will work if your matrix is not sparse. If it is sparse, use the lsqr function.
See the documentation for the various functions to understand how to use them.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

the cyclist
the cyclist 2017년 1월 23일
편집: the cyclist 2017년 1월 23일
Maybe this will help?
% Here is an example of using nlinfit(). For simplicity, none of
% of the fitted parameters are actually nonlinear!
% Define the data to be fit
x = (0:0.25:10)'; % Explanatory variables
y = x.^2;
z = x.^3;
E = 5 + 3*x + 7*y + 11*z; % Response variable (if response were perfect)
E = E + 500*randn((size(x)));% Add some noise to response variable
% Define function that will be used to fit data
% (F is a vector of fitting parameters)
f = @(F,X) F(1) + F(2).*X(:,1) + F(3).*X(:,2) + F(4).*X(:,3);
F_fitted = nlinfit([x y z],E,f,[1 1 1 1]);
% Display fitted coefficients
disp(['F = ',num2str(F_fitted)])
% Plot the data and fit
figure
plot(z,E,'*',z,f(F_fitted,[x y z]),'g');
legend('data','fit','Location','NorthWest')
  댓글 수: 3
the cyclist
the cyclist 2017년 1월 23일
I edited my example, so that it now uses three explanatory variables: x,y,z.
(It is not important that I happened to used x itself to define y and z.)
Riyadh Muttaleb
Riyadh Muttaleb 2017년 1월 25일
Thank you for you cooperation,
I am a little confused with some numbers that you used,
this is my example:
SPM(dependent variable)=a+b*S+c*A (S and A are independent variable) I have values of SPM, S, and A and I would like to have the values of the constants a,b ,c with correlation coefficient R^2.
Thank you,

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Nonlinear Regression에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by