% Assume that corneoretinal potential is a random variable X = Y + 0.35 [mV]
% where Y is gamma distributed with shape parameter 3 and rate parameter 20 [1/mV]
% (or equivalently, scale parameter 1/20=0.05 [mV]).
%
% (a) What is the probability to observe corneoretinal potential X exceeding 0.5 [mV].
%
% (b) If an observed corneoretinal potential exceeds x* it is recorded
% as significant. If, in the long run, we wish to label 1% largest
% potentials as significant, how the threshold x* should be set?
%
% Hint. This is a simple gamcdf-gaminv-type of problem, but you need to be careful.
% Y, not X, is gamma distributed and in calculations the constant 0.35 needs to be properly handled.
%(a) P(X > 0.5)=P(Y+0.35 > 0.5)=P(Y > 0.15)
1-gamcdf(0.15, 3, 1/20) %0.5768
%(b) 0.01=P(X > x*)=P(Y-0.35 > x*)=P(Y>x*-0.35).
% x*-35 is 0.99-quantile of gamma distribution with shape=3 and rate=20.
xstar = 0.35 + gaminv(0.99, 3, 1/20) %0.7703