- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi everyone,
I'm having some trouble with my code to using PROC NLIN. I try to fit ODR by year with Gamma distribution. When I run the code, I keep getting the error " WARNING: Maximum number of iterations exceeded. WARNING: PROC NLIN failed to converge."
Here are my data and code. Thank you so much!
%macro gamma_fit();
proc nlin data= my_data (where=(_leaf_ = "01"))
maxiter=100 method=marquardt converge=0.0000001;
parameters alpha = 0 to 10 by 5 beta = 0 to 10 by 5 lambda = 0 to 1;
model ODR = pdf("gamma",year,alpha,beta)*lambda;
output out=nlinout predicted=pred parms=alpha beta lambda;
run;
%mend;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
Can you provide us with the data in data step code with data lines?
Also, if you just want to fit a gamma distribution to your data, there are much better ways :
Use PROC SEVERITY (SAS/ETS) for example, or PROC UNIVARIATE (base SAS).
See also here:
- The generalized gamma distribution
By Rick Wicklin on The DO Loop March 15, 2021
https://blogs.sas.com/content/iml/2021/03/15/generalized-gamma-distribution.html - The inverse gamma distribution in SAS
By Rick Wicklin on The DO Loop January 27, 2021
https://blogs.sas.com/content/iml/2021/01/27/inverse-gamma-distribution-sas.html
Good luck,
Koen
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
Thank you for your reply. Is it mandatory to provide my data step code because it seems like very complicated to show.
To make it easier, let's see the picture below. I have about 50 _leaf_, each _leaf_ has about 24-30 years and each year has its own ODR. I need to fit the ODR of each _leaf_ with Gamma distribution.
I use the code as above but about 10 out of 50 _leaf_ show us the error "WARNING: Maximum number of iterations exceeded. WARNING: PROC NLIN failed to converge."
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
Why don't you do something like this?
Your PROC UNIVARIATE would additionally need a by-statement to do by-group processing :
BY _LEAF_;
data Robots;
input Length @@;
label Length = 'Attachment Point Offset (in mm)';
datalines;
10.147 10.070 10.032 10.042 10.102
10.034 10.143 10.278 10.114 10.127
10.122 10.018 10.271 10.293 10.136
10.240 10.205 10.186 10.186 10.080
10.158 10.114 10.018 10.201 10.065
10.061 10.133 10.153 10.201 10.109
10.122 10.139 10.090 10.136 10.066
10.074 10.175 10.052 10.059 10.077
10.211 10.122 10.031 10.322 10.187
10.094 10.067 10.094 10.051 10.174
;
run;
/* The following statements create a histogram with a fitted GAMMA density curve */
ods select ParameterEstimates FitQuantiles Histogram;
proc univariate data=Robots;
histogram Length /
GAMMA(theta=10 fill)
/* Use the ALPHA= and the SIGMA= gamma-options to */
/* specify the shape parameter and the scale parameter */
/* By default, PROC UNIVARIATE computes maximum likelihood estimates for alpha and sigma */
href = 10
hreflabel = 'Lower Bound'
odstitle = 'Fitted GAMMA Distribution of Offsets';
inset n = 'Sample Size' /
pos=ne cfill=blank;
run;
/* end of program */
Also, what is ODR? Order Defect Rate?
Best regards,
Koen
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
That particular type of Warning says that you might want to consider either increasing the number of iterations (say to 200) and/or relaxing the convergence criteria somewhat.
How much actual practical difference in your model would there be if changed the converge=0.0000001 to converge=0.000001 or even converge=0.00001 ? If you can't answer that right away then perhaps try it and see.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
Thank you for your suggestion. I just tried fixing the parameters (increasing maxiter = 32000 and converge = 0.1) and it worked for almost _leaf_. Now only One _leaf_ has minor issue, it shows that "WARNING: Step size shows no improvement. WARNING: PROC NLIN failed to converge"