Constrained nonlinear regression

Hi, I was wondering if Matlab has functions to perform constrained nonlinear regression in a similar way as the Constrained Nonlinear Regression (CNLR) in SPSS.
Here is a SPSS syntax example:
*NonLinear Regression.
MODEL PROGRAM b1=13 b2=-6 b3=-1.33 .
COMPUTE PRED_ = b1 + b2 * exp(b3*advert).
CNLR sales
/OUTFILE='C:\TEMP\SPSSFNLR.TMP'
/PRED PRED_
/BOUNDS b1 >= 0; b2 <= 0; b3 <= 0
/SAVE PRED RESID
/CRITERIA STEPLIMIT 2 ISTEP 1E+20 .
Any ideas how to perform this computation in Matlab?
Thanks, Mark

Risposte (1)

Sargondjani
Sargondjani il 18 Mag 2012

0 voti

lsqnonlin

5 Commenti

Mark
Mark il 20 Mag 2012
Thanks for the suggestion.
I used the following code in Matlab to fit the data:
X=[56.25 78.75 101.25 123.75 146.25 168.75 191.25 213.75];
Y=[0.2 0.2 0.2 1 1 0.8 1 0.8];
fit = @(X0,X,Y)(1./(1+ exp(-((-(X0(1))+X)*X0(2))) ))-Y;
% Initialize the coefficients of the function.
X0=[105 0.031]';
options = optimset('Largescale','off');
x=lsqnonlin(fit,X0,[],[],options,X,Y);
And in SPSS:
MODEL PROGRAM b=105 slope= 0.031.
COMPUTE PRED_=1/(1+exp(-((-b+X)*slope))).
CNLR resp
/PRED PRED_
/CRITERIA STEPLIMIT 2 ISTEP 1E+20
/BOUNDS slope>-1; slope<1; b>=56; b<=214 .
Solution:
SPSS: 103.059 0.767
Matlab: 106.683 0.253
Especially, the second coefficient (slope of the function) differs between Matlab and the SPSS output.
Is there something wrong with the used matlab code?
it's hard to say but your initial guess for the second coefficient is poor. i dont know how well behaved your problem is, but the optimizer only finds a local minimum so it could get stuck in a not optimal point... so you should first try with a better initial guess
if that doesnt work, than the exit message should give you clues what to change to improve the results (post exit message here if you want help on this)
for a start:
- use lower values for TolFun and TolX (default 1e-6 i think)
- supply analytical gradient (this looks not too hard for your problem)
and a good check is to make a 3D plot of the error's (at gridpoints). you can use 'meshgrid' to get matrices with all grippoints...
Mark
Mark il 21 Mag 2012
The initial guess for the coefficients were based on:
[b1,d1,s1] = glmfit(X',Y','binomial');
Playing with the initial guess for the second coefficient between 0 and 1 didn't changed the Matlab solution.
The exitflag = 3 (Change in the residual was less than the specified tolerance.)
hmmm, i think you should calculate the errors yourself and check if the SPSS solution gives you a smaller error in matlab...
i did a grid search myself and i came to the same conclusion as lsqnonlin: the optimum is somewhere around 106.7 and 0.25
...maybe you should try to improve the result of SPSS

Accedi per commentare.

Richiesto:

il 18 Mag 2012

Community Treasure Hunt

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

Start Hunting!

Translated by