Forecasting using SAS Forecast Server, SAS/ETS, and more

Finding a gamma distribution from percentiles

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 17
Accepted Solution

Finding a gamma distribution from percentiles

Dear Braintrust,

we are working on prior determination for finding a gamma distribution.

we have the 50th and 90th percentile of gamma distribution and want to find the parameters for defining the gamma distribution fitting our data.

Is there any specific procedure we can follow with SAS?

Thanks so much


Accepted Solutions
Solution
‎03-16-2018 09:43 AM
SAS Super FREQ
Posts: 4,241

Re: Finding a gamma distribution from percentiles

I wrote a description of four different ways to solve a system of nonlinear equations in SAS. See the article "Solve a system of nonlinear equations with SAS."

View solution in original post


All Replies
Super User
Posts: 10,778

Re: Finding a gamma distribution from percentiles


proc univariate data=sashelp.class;
histogram height / gamma;
run;

Check the bottom of Histogram Graphic.

Occasional Contributor
Posts: 17

Re: Finding a gamma distribution from percentiles

Thanks for this answer however I think my previous question was not clear enough.

Let 's say that I want to modelize a gamma distribution.

I only know that the 50th percentile of this gamma (alpha, beta) is pct50 and the 90th percentile is pct90.

how can I find alpha and  beta knowing pct50 and pct90 of the distribution?

Thanks

Super User
Posts: 10,778

Re: Finding a gamma distribution from percentiles

It looks like it is a optimize problem. I remembered @Rick_SAS wrote a bolg about fitting a normal distribution. But he has many data,not like you only two. OR you could use CDF(),QUANTILE() function to enmuerate the alpha beta.

SAS Super FREQ
Posts: 4,241

Re: Finding a gamma distribution from percentiles

The gamma distribution has two parameters (alpha, beta) and you have two constraints, so this requires solving a nonlinear system of equations.Let p1=0.5 and p2=0.95 be the percentiles (expressed as quantiles in (0,1)).

The nonlinear equations are

 

Solve for (alpha, beta) that satisfy:

Eq1: CDF("Gamma", X1, alkpha, beta) = p1

Eq2: CDF("Gamma", X2, alkpha, beta) = p2

 

This can be solved in many ways, but since you posted to the ETS community I assume you want to use SAS/ETS tools. You can use PROC MODEL to solve simultaneous equations. Your example might look like this, where I am using X1=4 for the observed 50th percentile and X2=9 for the observed 95th percentile:

 

data initial;
   alpha=1; beta=1;    /* initial guess for Newton's method */
   p1=0.5;  X1 = 4;   /* first percentile */
   p2=0.95; X2 = 9;   /* second percentile */
run;

proc model data=initial;
  eq.one = cdf("Gamma", X1, alpha, beta) - p1;
  eq.two = cdf("Gamma", X2, alpha, beta) - p2;
  solve alpha beta / solveprint out=solved outpredict;
run;quit;

proc print data=solved noobs;
run;

/* Optional: check that the solution makes sense */
data Check;
set solved;
do x = 0 to 12 by 0.2;
   y = cdf("gamma", x, alpha, beta);
   output;
end;
run;

proc sgplot data=Check;
series x=x y=y;
refline 0.5 0.95 / axis=y;
refline 4 9 / axis=x;
run;

.

Occasional Contributor
Posts: 17

Re: Finding a gamma distribution from percentiles

Thank you so much for your answer. it works with your example but when checking from this approach from a seminal paper the authors mention pct50 = 8.9 and pct90 = 4.4 the authors found a gamma(5.9, 0.7)

when replacing these values and pct90 vs pct95 from your solution have this warning:

 

The solution failed because 2 equations are missing or have extreme values for observation
1 at NEWTON iteration

 

I don't know how to fix this properly.

 

SAS Super FREQ
Posts: 4,241

Re: Finding a gamma distribution from percentiles

What is the reference? I believe that you (or the authors) have a typo somewhere. The 50th percentile must be less than the 90th percentile for any valid distribution.

 

You should investigate the meaning of the parameters in your reference. I am using the standard parameterization where the first parameter (alpha) is the shape parameter and the second (beta) is the scale parameter. Other researchers might use an alternative parameterization where the second parameter is a RATE parameter. The relationship is RATE = 1/SCALE.

 

You can easily modify the code I provided to graph the CDF  for Gamm(5.9, 0.7) or Gamma(5.9, 1/0.7). You will see that neither curve gives the percentiles that you claim.

 

data Check;
alpha = 5.9; beta=0.7;
do x = 0 to 15 by 0.2;
   yScale = cdf("gamma", x, alpha, beta);
   yRate = cdf("gamma", x, alpha, 1/beta);
   output;
end;
run;

proc sgplot data=Check;
series x=x y=yScale / curvelabel;
series x=x y=yRate / curvelabel;
refline 0.5 0.9 / axis=y;
run;

I'll be out of town for the next week, but I think these tips should point you in the right direction. Good luck.

 

Solution
‎03-16-2018 09:43 AM
SAS Super FREQ
Posts: 4,241

Re: Finding a gamma distribution from percentiles

I wrote a description of four different ways to solve a system of nonlinear equations in SAS. See the article "Solve a system of nonlinear equations with SAS."

☑ This topic is solved.

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

Discussion stats
  • 7 replies
  • 306 views
  • 1 like
  • 3 in conversation