How can I do non-linear regression for three varietals?
Show older comments
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 Comments
abuzer
on 23 Jan 2017
If you need to fit data with a nonlinear model, transform the variables to make the relationship linear. Alternatively, try to fit a nonlinear function directly using either the Statistics and Machine Learning Toolbox™ nlinfit function, the Optimization Toolbox™ lsqcurvefit function, or by applying functions in the Curve Fitting Toolbox™.
the cyclist
on 23 Jan 2017
I don't understand. Where is the nonlinearity?
abuzer
on 23 Jan 2017
I assumed he wrote wrong equation. Because he asks nonlinear..
Riyadh Muttaleb
on 23 Jan 2017
Accepted Answer
More Answers (1)
the cyclist
on 23 Jan 2017
Edited: the cyclist
on 23 Jan 2017
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 Comments
Riyadh Muttaleb
on 23 Jan 2017
the cyclist
on 23 Jan 2017
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
on 25 Jan 2017
Categories
Find more on MATLAB 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!