Programming the statistical procedures from SAS

WARNING: PROC NLIN failed to converge error

Accepted Solution Solved
Reply
Contributor
Posts: 71
Accepted Solution

WARNING: PROC NLIN failed to converge error

Hello, 

How can I resolve the 'PROC NLIN failed to converge.' error? Here is the code: 

PROC IMPORT DATAFILE="/folders/myfolders/Brook trout temp-final.xlsx"
OUT=brooktrout
DBMS=XLSX
REPLACE;
RUN;
title 'Gastric evacuation in brook trout - SQRT model +AC (12.5-20.4)';
data exp;
set brooktrout;
if expno=1 or expno=2 or expno=4 or expn=5 or expno=6 or expno=7 or expno=8;
run;
proc nlin data=exp method=marquardt;
parms RLT=0.0013 A=0.05 B=0.46 TU=20;
C=1.31;
R=RLT*predlcm**C*EXP(A*temp)*(1-EXP(B*(temp-TU)));
model sqrtstw=sqrtsow-0.5*R*time;
der.RLT=-0.5*predlcm**C*EXP(A*temp)*(1-EXP(B*(temp-TU)))*time;
der.A=-0.5*RLT*predlcm**C*temp*EXP(A*temp)*(1-EXP(B*(temp-TU)))*time;
der.B=-0.5*RLT*predlcm**C*EXP(A*temp)*(20-temp)*EXP(B*(temp-TU))*time;
der.TU=-0.5*RLT*predlcm**C*EXP(A*temp)*B*EXP(B*(temp-TU))*time;
 
output out=expp p=pstw r=stw_residual;
run;
proc summary data=expp;
var stw_residual stw;
output out=stats css(stw)=sstot uss(stw_residual)=ssres N=N;
run;
data expp;
set stats;
rsquared=1-(ssres/sstot);
adjrsquared = 1-(1-rsquared)*(N-1) / (N- 3 -1);
run;
proc print data=expp;
run;

 


Accepted Solutions
Solution
‎03-12-2018 08:57 AM
SAS Super FREQ
Posts: 4,243

Re: WARNING: PROC NLIN failed to converge error

In the IF statement of your DATA EXP step, you need to change to EXPNO=5.  Currently, all those observations are not part of the data that you are analyzing. That will make a difference, especially if there are many observations that have EXPON=5.

View solution in original post


All Replies
SAS Super FREQ
Posts: 4,243

Re: WARNING: PROC NLIN failed to converge error

[ Edited ]

You should begin by checking your derivatives, which look wrong to me. In particular, der.B has the term (20-temp), which I think should be (TU-temp).

 

Actually, there is really no need to write your own derivatives. PROC NLIN will automatically generate analytical derivatives.

Contributor
Posts: 71

Re: WARNING: PROC NLIN failed to converge error

Dear Rick_SAS,

Could you please write it as Proc statement in a comment?

SAS Super FREQ
Posts: 4,243

Re: WARNING: PROC NLIN failed to converge error

If you don't know how to take the derivative of the exponential term and apply the chain rule, then just delete the incorrect statement and NLIN will generate it for you.  Good luck!

Contributor
Posts: 71

Re: WARNING: PROC NLIN failed to converge error

You mean I should simply delete these lines: 

 

der.RLT=-0.5*predlcm**C*EXP(A*temp)*(1-EXP(B*(temp-TU)))*time;
der.A=-0.5*RLT*predlcm**C*temp*EXP(A*temp)*(1-EXP(B*(temp-TU)))*time;
der.B=-0.5*RLT*predlcm**C*EXP(A*temp)*(20-temp)*EXP(B*(temp-TU))*time;
der.TU=-0.5*RLT*predlcm**C*EXP(A*temp)*B*EXP(B*(temp-TU))*time;

?

SAS Super FREQ
Posts: 4,243

Re: WARNING: PROC NLIN failed to converge error

I think they are all correct except for der.B, so just delete that line and see what happens. But, yes, you could also delete all four lines.

Contributor
Posts: 71

Re: WARNING: PROC NLIN failed to converge error

I received the same error (PROC NLIN failed to converge.) again though I removed above mentioned lines.

P.S. Today I learn one new thing that writing derivatives are not essential. It will make my life easy Smiley Happy
SAS Super FREQ
Posts: 4,243

Re: WARNING: PROC NLIN failed to converge error

Great. Two common reasons why a model might not converge is 

1. The model does not fit your data.

2. The initial guesses are not sufficiently close to the actual parameter estimates for your model.

 

I can't do anything about (1). If the problem is (2) then you can specify several parameter values on the PARMS statement. For example, if you are not sure about the parameter values for A ant TU, you can specify multiple guesses:

 

parms RLT=0.0013 
           A=0.05 0.1    /* 2 guesses */
           B=0.46 
           TU=15 20 25; /* 3 guesses */
Contributor
Posts: 71

Re: WARNING: PROC NLIN failed to converge error

I provided multiple guesses but again didn't work. The model adequately fit to my data and provides a best curve line.
By the way, along with converge error I also get one more error which is: "WARNING: Maximum number of iterations exceeded"!
Solution
‎03-12-2018 08:57 AM
SAS Super FREQ
Posts: 4,243

Re: WARNING: PROC NLIN failed to converge error

In the IF statement of your DATA EXP step, you need to change to EXPNO=5.  Currently, all those observations are not part of the data that you are analyzing. That will make a difference, especially if there are many observations that have EXPON=5.

Contributor
Posts: 71

Re: WARNING: PROC NLIN failed to converge error

Thanks for the correction. I was making a small mistake (in derivatives as well as in guesses). I should first fix the "A" with the value I need to calculate separately using exponential function. Now the Convergence criterion met successfully.

 

Thank you very much for your help. I always learn new things at this platform Smiley Happy 

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 10 replies
  • 291 views
  • 5 likes
  • 2 in conversation