02-16-2018 08:59 AM
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
3 weeks ago
02-16-2018 11:41 AM
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?
02-17-2018 08:47 PM
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.
02-18-2018 07:04 AM
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;
02-18-2018 07:24 AM
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.
02-18-2018 12:14 PM
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.
3 weeks ago
Need further help from the community? Please ask a new question.