turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- Analytics
- /
- Stat Procs
- /
- WARNING: PROC NLIN failed to converge error

Topic Options

- RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

03-11-2018 05:32 AM

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

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to UmarKhan

03-12-2018 08:26 AM

All Replies

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to UmarKhan

03-11-2018 08:51 PM - edited 03-12-2018 09:12 AM

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.

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Rick_SAS

03-12-2018 02:42 AM

Dear Rick_SAS,

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

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to UmarKhan

03-12-2018 06:20 AM

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!

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Rick_SAS

03-12-2018 06:23 AM

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;
```

?

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to UmarKhan

03-12-2018 06:28 AM

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.

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Rick_SAS

03-12-2018 06:39 AM

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

P.S. Today I learn one new thing that writing derivatives are not essential. It will make my life easy

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to UmarKhan

03-12-2018 06:52 AM

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 */
```

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Rick_SAS

03-12-2018 08:01 AM

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"!

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

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to UmarKhan

03-12-2018 08:26 AM

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Rick_SAS

03-12-2018 08:56 AM

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