Maximum Likelihood Estimator of the parameter of Gamma(,1) distribution
Solution to Q1: Gamma Sample Generation
We use the standard routine rgamma in R language, which uses the following method for generation of Gamma sample:
For
A rejection technique [1] is used based on the majoring function
Since if and if and the inequality is valid for all . The function
is a probability density that is proportional to g(x). Sampling from h(x) is no problem since both parts have easily invertible integrals: with a probability of an x below 1 (first part of h(x)) is sampled, otherwise the second part of h(x) is used. The rejection test is based on which is or .
For
Ahrens and Dieter’s modified rejection method [2] is used.
Applying the transformation , the resulting transformed function g(t) is close to the standard normal density f(t).
The mode of g(t) is at , but g(0) is a little larger than .
Also, g(t) intersects the standard normal density f(t) only once at some .
Consequently, for all .
This calls for the following modification of Von Neumann’s acceptance-rejection technique:
Generate a standard normal deviate T [3].
If , accept as a gamma() sample.
For , where f(t) majorizes g(t), the ratio can be compared with a (0, 1)-uniform deviate U for an ordinary rejection test.
(For simplicity this test is also applied when . In this case and T is always accepted.)
Obviously rejection occurs with probability
Hence, whenever a negative T is rejected, it must be replaced with a new , and this has to be a sample from the difference distribution whose probability density function is proportional to in [). Sampling from this difference is done by means of a double-exponential hat.
Solution to Q2: Maximum Likelihood Estimation of
We use the standard routine fitdistr in R language, with BFGS method. For Gamma distribution reasonable starting values for the iterative method can be computed by the routine itself.
BFGS Method [4]
In Newton’s method, we find the new iterate as a function of as follows. For any point x define , the second order Taylor expansion around is given by
This defines a quadratic model of the function near the point . Its gradient with respect to x is , and it is minimized at .
Working with the inverse Hessian in place of , the secant equation becomes . The optimization is then : minimize subject to , , which has the unique solution
where ,
,
W is any matrix satisfying , and
.
Each step of the BFGS method has the form
where is computed from a line search procedure to satisfy the Wolfe conditions:
with .
Solution to Q3 & Q4: Results
The following graphs were plotted for values of MLE of against the values of , the parameter used for generation of sample. ranges from .1 to 10 in steps of .1, and for each value of , estimates for 20 samples are calculated. n is the number of Gamma variates in a single sample.
Example outputs from different samples with for :
The quantities in brackets are the estimated standard errors due to numerical optimization, which, we see, decrease as the sample size n is increased. Also, the variance of the estimates is less for large sample sizes.
And though we have different algorithms for sample generation for the cases and , the sampling and estimation methods do not differentiate between integer and non-integer values, and the precision achieved is similar in two cases.
For example, when and :
Examples of generated Samples:
Code for plots (in R language)
library(MASS)
n=50 #number of variates in each sample
alpha=.1*(1:100) #range of alpha for sample generation
s=20Ψ #number of samples for each value of alpha
assign("x", c())
assign("y", c())
assign("z", c())
for (a in alpha)
for (i in 1:s) {
x <- c(x,(a))
y <- c(y,fitdistr(rgamma(n,(a)), "gamma", rate=1, method="BFGS"))
}
for (i in 1:(s*length(alpha))) z[i] = y[[5*i-4]]
plot(
Ψx,z, type="l", main=expression(paste("MLE of ",alpha)),
Ψsub=substitute(paste("n = ", n), list(n=n)),
Ψxlab=expression(alpha[0]), ylab=expression(alpha)
Ψ)
Code for single estimation (in R language)
n=50Ψ #number of variates in each sample a=2 #value of alpha for generation of sample fitdistr(rgamma(n,a), "gamma", rate=1, method="BFGS")
References
- [1] Ahrens, J. H. and Dieter, U. (1974). Computer methods for sampling from gamma, beta, Poisson and binomial distributions. Computing, 12, 223–246
- [2] Ahrens, J. H. and Dieter, U. (1982). Generating gamma variates by a modified rejection technique. Communications of the ACM, 25, 47–54
- [3] Ahrens, J. H. and Dieter, U. (1972). Computer methods for sampling from the exponential and normal distributions. Communications of the ACM, 15, 873-882
- [4] Jorge Nocedal and Stephen J. Wright (2000). Numerical Optimization