BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
afgdurrani0
Pyrite | Level 9

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;

 

1 ACCEPTED SOLUTION

Accepted Solutions
Rick_SAS
SAS Super FREQ

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

10 REPLIES 10
Rick_SAS
SAS Super FREQ

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.

afgdurrani0
Pyrite | Level 9

Dear Rick_SAS,

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

Rick_SAS
SAS Super FREQ

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!

afgdurrani0
Pyrite | Level 9

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;

?

Rick_SAS
SAS Super FREQ

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.

afgdurrani0
Pyrite | Level 9
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 🙂
Rick_SAS
SAS Super FREQ

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 */
afgdurrani0
Pyrite | Level 9
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"!
Rick_SAS
SAS Super FREQ

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.

afgdurrani0
Pyrite | Level 9

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 🙂 

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is ANOVA?

ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.

Find more tutorials on the SAS Users YouTube channel.

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