Example 1: Maximum Likelihood Estimation

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


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

public class MaximumLikelihoodEstimationEx1 {

    public static void main(String[] args) throws Exception {
        double[] x = {
            0.12396e0, 0.58037e0, 0.28837e0, 0.38195e0,
            0.44387e0, 0.17680e0, 0.22661e0, 0.55939e0,
            0.41646e0, 0.33781e0, 0.63768e0, 0.81501e0,
            0.55952e0, 0.50559e0, 0.39315e0, 0.67901e0,
            0.66032e0, 0.52279e0, 0.53164e0, 0.19165e0,
            0.83432e0, 0.16578e0, 0.30614e0, 0.57622e0,
            0.24793e0, 0.55212e0, 0.32037e0, 0.62443e0,
            0.54663e0, 0.56399e0, 0.61369e0, 0.62853e0,
            0.47957e0, 0.57208e0, 0.44813e0, 0.69026e0,
            0.73784e0, 0.28413e0, 0.18926e0, 0.58319e0,
            0.28740e0, 0.61739e0, 0.32052e0, 0.29761e0,
            0.68279e0, 0.75275e0, 0.48364e0, 0.56711e0,
            0.72584e0, 0.32971e0, 0.86950e0, 0.79991e0,
            0.52609e0, 0.46006e0, 0.52828e0, 0.27842e0,
            0.58179e0, 0.37934e0, 0.29819e0, 0.53552e0,
            0.46476e0, 0.22105e0, 0.36031e0, 0.49400e0,
            0.41216e0, 0.34985e0, 0.26751e0, 0.57636e0,
            0.54788e0, 0.48447e0, 0.75758e0, 0.60260e0,
            0.56603e0, 0.57345e0, 0.35777e0, 0.79578e0,
            0.46025e0, 0.57042e0, 0.31177e0, 0.56309e0,
            0.52548e0, 0.69891e0, 0.27270e0, 0.38819e0,
            0.73049e0, 0.54734e0, 0.50803e0, 0.48510e0,
            0.87042e0, 0.52287e0, 0.67998e0, 0.40186e0,
            0.48845e0, 0.64425e0, 0.65228e0, 0.45132e0,
            0.23021e0, 0.39449e0, 0.70417e0, 0.31853e0
        };

        BetaPD beta = new BetaPD();

        MaximumLikelihoodEstimation mle
                = new MaximumLikelihoodEstimation(x, beta, 1, 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  3.67112042  
1  3.73274034  

            hessian
        0             1        
0  -16.82252107   14.45938489  
1   14.45938489  -16.23511103  

standard errors
       0       
0  0.50349626  
1  0.51252395  

Minus log likelihood: -35.22
Link to Java source.