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
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?
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;
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.
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.
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
Learn how to run multiple linear regression models with and without interactions, presented by SAS user Alex Chaplin.
Find more tutorials on the SAS Users YouTube channel.