package com.imsl.test.example.stat.distributions; import com.imsl.math.*; import com.imsl.stat.Random; import com.imsl.stat.distributions.*; /** *
* Estimates the parameters of the normal probability distribution.
** This example obtains maximum likelihood estimates for the parameters of a * normal (Gaussian) distribution.
* * @see Code * @see Output */ public class MaximumLikelihoodEstimationEx3 { public static void main(String[] args) throws Exception { int n = 100; double[] sample = new double[n]; double mean = 25; double stdev = 1.5; Random rand = new Random(123457); for (int i = 0; i < n; i++) { sample[i] = stdev * rand.nextNormal() + mean; } NormalPD norm = new NormalPD(); double[] exactMLEs = norm.getMLEs(sample); MaximumLikelihoodEstimation mle = new MaximumLikelihoodEstimation(sample, norm, 2, 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 java.text.DecimalFormat("0.0000000")); PrintMatrix pm = new PrintMatrix("Analytic MLEs"); pm.print(pmf, exactMLEs); pm.setTitle("Numerical 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); } }