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;
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.
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.
Dear Rick_SAS,
Could you please write it as Proc statement in a comment?
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!
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;
?
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.
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 */
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.
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 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.