import java.text.*; import com.imsl.stat.*; import com.imsl.math.*; import com.imsl.math.BLAS; import com.imsl.math.PrintMatrix; import java.util.logging.Logger; import java.util.logging.LogRecord; import java.util.logging.Level; import java.util.logging.Handler; public class ARAutoUnivariateEx2 { public static void main(String args[]) throws Exception { /* THE CANDIAN LYNX DATA AS USED IN TIMSAC 1821-1934 */ double[] y = {0.24300e01, 0.25060e01, 0.27670e01, 0.29400e01, 0.31690e01, 0.34500e01, 0.35940e01, 0.37740e01, 0.36950e01, 0.34110e01, 0.27180e01, 0.19910e01, 0.22650e01, 0.24460e01, 0.26120e01, 0.33590e01, 0.34290e01, 0.35330e01, 0.32610e01, 0.26120e01, 0.21790e01, 0.16530e01, 0.18320e01, 0.23280e01, 0.27370e01, 0.30140e01, 0.33280e01, 0.34040e01, 0.29810e01, 0.25570e01, 0.25760e01, 0.23520e01, 0.25560e01, 0.28640e01, 0.32140e01, 0.34350e01, 0.34580e01, 0.33260e01, 0.28350e01, 0.24760e01, 0.23730e01, 0.23890e01, 0.27420e01, 0.32100e01, 0.35200e01, 0.38280e01, 0.36280e01, 0.28370e01, 0.24060e01, 0.26750e01, 0.25540e01, 0.28940e01, 0.32020e01, 0.32240e01, 0.33520e01, 0.31540e01, 0.28780e01, 0.24760e01, 0.23030e01, 0.23600e01, 0.26710e01, 0.28670e01, 0.33100e01, 0.34490e01, 0.36460e01, 0.34000e01, 0.25900e01, 0.18630e01, 0.15810e01, 0.16900e01, 0.17710e01, 0.22740e01, 0.25760e01, 0.31110e01, 0.36050e01, 0.35430e01, 0.27690e01, 0.20210e01, 0.21850e01, 0.25880e01, 0.28800e01, 0.31150e01, 0.35400e01, 0.38450e01, 0.38000e01, 0.35790e01, 0.32640e01, 0.25380e01, 0.25820e01, 0.29070e01, 0.31420e01, 0.34330e01, 0.35800e01, 0.34900e01, 0.34750e01, 0.35790e01, 0.28290e01, 0.19090e01, 0.19030e01, 0.20330e01, 0.23600e01, 0.26010e01, 0.30540e01, 0.33860e01, 0.35530e01, 0.34680e01, 0.31870e01, 0.27230e01, 0.26860e01, 0.28210e01, 0.30000e01, 0.32010e01, 0.34240e01, 0.35310e01}; double[][] printOutput=null; double timsacAR[], mmAR[], mleAR[], lsAR[]; double forecasts[], residuals[]; double timsacConstant, mmConstant, mleConstant, lsConstant; double timsacVar, timsacEquivalentVar, mmVar, mleVar, lsVar; int maxlag = 20; String[] colLabels = {"TIMSAC", "Method of Moments", "Least Squares", "Maximum Likelihood"}; String[] colLabels2= {"Observed", "Forecast", "Residual"}; PrintMatrixFormat pmf = new PrintMatrixFormat(); PrintMatrix pm = new PrintMatrix(); NumberFormat nf = NumberFormat.getNumberInstance(); pm.setColumnSpacing(4); nf.setMinimumFractionDigits(4); pmf.setNumberFormat(nf); pmf.setColumnLabels(colLabels); System.out.println("Automatic Selection of Minimum AIC AR Model"); System.out.println(""); ARAutoUnivariate autoAR = new ARAutoUnivariate(maxlag, y); autoAR.compute(); int orderSelected = autoAR.getOrder(); System.out.println("Minimum AIC Selected="+autoAR.getAIC()+ " with an optimum lag of k= "+ autoAR.getOrder()); System.out.println(""); timsacAR = autoAR.getTimsacAR(); timsacConstant = autoAR.getTimsacConstant(); timsacVar = autoAR.getTimsacVariance(); lsAR = autoAR.getAR(); lsConstant = autoAR.getConstant(); lsVar = autoAR.getInnovationVariance(); autoAR.setEstimationMethod(ARAutoUnivariate.METHOD_OF_MOMENTS); autoAR.compute(); mmAR = autoAR.getAR(); mmConstant = autoAR.getConstant(); mmVar = autoAR.getInnovationVariance(); autoAR.setEstimationMethod(ARAutoUnivariate.MAX_LIKELIHOOD); autoAR.compute(); mleAR = autoAR.getAR(); mleConstant = autoAR.getConstant(); mleVar = autoAR.getInnovationVariance(); printOutput = new double[orderSelected+1][4]; printOutput[0][0] = timsacConstant; for(int i=0; i