Example 2: Maximum Likelihood Estimation

This example obtains maximum likelihood estimates for the parameters of a gamma distribution.


import com.imsl.math.*;
import com.imsl.stat.distributions.*;
import java.text.DecimalFormat;

public class MaximumLikelihoodEstimationEx2 {

    public static void main(String[] args) throws Exception {
        double x[] = {
            1.015998e0, 0.2677489e0, 2.198958e0, 1.784697e0, 0.691063e0,
            0.992409e0, 0.5466309e0, 1.154601e0, 2.613015e0, 1.219826e0,
            1.158957e0, 3.933280e0, 0.2462264e0, 3.946624e0, 4.184852e0,
            1.148567e0, 1.798003e0, 1.437205e0, 2.383511e0, 2.030147e0,
            0.7575e0, 0.903873e0, 0.5005532e0, 0.296348e0, 1.564283e0,
            2.787072e0, 0.3472906e0, 2.228984e0, 2.328759e0, 4.634677e0,
            1.41974e0, 0.5815979e0, 2.654966e0, 1.719702e0, 1.668744e0,
            2.203117e0, 0.7410172e0, 0.5147782e0, 0.4841398e0, 2.745041e0,
            1.455526e0, 0.7109387e0, 0.967477e0, 0.876192e0, 0.4505406e0,
            0.3986173e0, 0.4707685e0, 0.301807e0, 0.624848e0, 4.325418e0,
            1.410972e0, 2.630923e0, 0.4841873e0, 0.1835388e0, 0.2373447e0,
            0.5298828e0, 1.323294e0, 1.672188e0, 0.009495691e0, 1.832066e0,
            1.210357e0, 1.133037e0, 1.23147e0, 0.379497e0, 2.001283e0,
            0.5448404e0, 0.1165402e0, 1.834957e0, 1.530335e0, 2.550148e0,
            1.240445e0, 1.058339e0, 1.613384e0, 1.708352e0, 1.134821e0,
            0.6249367e0, 0.8273115e0, 0.9793533e0, 0.05378025e0,
            0.6828388e0, 0.9259066e0, 0.8168141e0, 3.910878e0, 1.88685e0,
            2.836617e0, 1.644921e0, 0.863347e0, 2.128436e0, 2.710456e0,
            4.747736e0, 0.823015e0, 1.279859e0, 2.991689e0, 2.483813e0,
            0.0610894e0, 0.5572344e0, 0.07148165e0, 0.3847188e0,
            1.322698e0, 0.3358647e0
        };

        GammaPD gamma = new GammaPD();

        MaximumLikelihoodEstimation mle
                = new MaximumLikelihoodEstimation(x, gamma, 3, 1);

        mle.compute();

        double[] parameterEstimates = mle.getEstimates();
        double[][] hessian = mle.getHessian();
        double[] stdErrs = mle.getStandardErrors();
        double mLogLikelihood = mle.getMinusLogLikelihood();

        PrintMatrixFormat pmf = new PrintMatrixFormat();
        pmf.setNumberFormat(new DecimalFormat("0.00000000"));

        PrintMatrix pm = new PrintMatrix("MLEs");
        pm.print(pmf, parameterEstimates);

        pm.setTitle("hessian");
        pm.print(pmf, hessian);

        pm.setTitle("standard errors");
        pm.print(pmf, stdErrs);

        System.out.printf("Minus log likelihood: %5.2f\n", mLogLikelihood);
    }
}

Output

     MLEs
       0       
0  1.47875577  
1  0.96006357  

             hessian
         0              1        
0   -95.27326615  -104.15984884  
1  -104.15984884  -160.43415880  

standard errors
       0       
0  0.19017869  
1  0.14655443  

Minus log likelihood: 130.88
Link to Java source.