MATLAB: What tool to use to perform Nonlinear Regression with more than 3 variables

curve fittingmultiplenlinfitnonlinearregression

Hi
I am trying to perform a nonlinear regression in Matlab. I have one dependent variale (response) and 16 independent variables (predictors). I am trying to find any tool in Matlab that can perform the nonlinear regression or curve fitting for all of them together.
Is there any such tool in Matlab?

Best Answer

The nlinfit function will do what you want.
The procedure for having multiple independent variables is not quite obvious, but easy enough to do. The nonlinear fitting functions will only take one argument for the independent variable, but that argument can be a matrix. To do a nonlinear regression with multiple independent variables, combine your different independent variables into a matrix, and pass that to nlinfit.
For example:
% EQUATION: y = exp(q*x1) * sin(r*x2)
% MAPPING: b(1) = q, b(2) = r, x(:,1) = x1, x(:,2) = x2
x = [x1(:), x2(:)];
f = @(b,x) exp(b(1).*x(:,1)) .* sin(b(2).*x(:,2));
B0 = [1; 1];
B = nlinfit(x, y, f, B0);
(Note: Untested code, for illustration purposes only!)