Example 1: ARAutoUnivariate

Consider the Wolfer Sunspot Data (Anderson 1971, p. 660) consisting of the number of sunspots observed each year from 1749 through 1924. The data set for this example consists of the number of sunspots observed from 1770 through 1869. In this example, ARAutoUnivariate found the minimum AIC fit is an autoregressive model with 3 lags:

\tilde{W_t}=\phi_1\tilde{W_{t-1}}+\phi_2 \tilde{W_{t-2}}+\phi_3\tilde{W_{t-3}} + a_t\rm{,}
where
\tilde{W_t} := W_t - \mu
\mu is the sample mean of the time series  \{W_t\}. Defining the overall constant \theta_0 by \theta_0 := \mu(1- \sum_{i=1}^3\phi_i), we obtain the following equivalent representation:
W_t=\theta_0+\phi_1W_{t-1}+\phi_2W_{t-2}+ \phi_3W_{t-3}+a_t\rm{.}
The example computes estimates for \theta_0\rm{,}\,\phi_1\rm{,}\,\phi_2\rm{,}\,\phi_3 for each of the three parameter estimation methods available.


import com.imsl.stat.*;
import com.imsl.math.PrintMatrix;

public class ARAutoUnivariateEx1 {

    public static void main(String args[]) throws Exception {
        double[] z = {
            100.8, 81.6, 66.5, 34.8, 30.6, 7, 19.8, 92.5,
            154.4, 125.9, 84.8, 68.1, 38.5, 22.8, 10.2, 24.1, 82.9,
            132, 130.9, 118.1, 89.9, 66.6, 60, 46.9, 41, 21.3, 16,
            6.4, 4.1, 6.8, 14.5, 34, 45, 43.1, 47.5, 42.2, 28.1, 10.1,
            8.1, 2.5, 0, 1.4, 5, 12.2, 13.9, 35.4, 45.8, 41.1, 30.4,
            23.9, 15.7, 6.6, 4, 1.8, 8.5, 16.6, 36.3, 49.7, 62.5,
            67, 71, 47.8, 27.5, 8.5, 13.2, 56.9, 121.5, 138.3, 103.2,
            85.8, 63.2, 36.8, 24.2, 10.7, 15, 40.1, 61.5, 98.5,
            124.3, 95.9, 66.5, 64.5, 54.2, 39, 20.6, 6.7, 4.3, 22.8,
            54.8, 93.8, 95.7, 77.2, 59.1, 44, 47, 30.5, 16.3, 7.3,
            37.3, 73.9
        };

        ARAutoUnivariate autoAR = new ARAutoUnivariate(20, z);
        System.out.println("");
        System.out.println("    Method of Moments ");
        System.out.println("");

        autoAR.setEstimationMethod(ARAutoUnivariate.METHOD_OF_MOMENTS);
        autoAR.compute();

        System.out.println("Order Selected: " + autoAR.getOrder());
        System.out.println("AIC = " + autoAR.getAIC() + "       Variance = "
                + autoAR.getInnovationVariance());
        System.out.println("Constant = " + autoAR.getConstant());
        System.out.println("");
        new PrintMatrix("AR estimates are:  ").print(autoAR.getAR());

        /* try another method */
        System.out.println("");
        System.out.println("");
        System.out.println("    Least Squares ");
        System.out.println("");
        autoAR.setEstimationMethod(ARAutoUnivariate.LEAST_SQUARES);
        autoAR.compute();

        System.out.println("Order Selected: " + autoAR.getOrder());
        System.out.println("AIC = " + autoAR.getAIC() + "       Variance = "
                + autoAR.getInnovationVariance());
        System.out.println("Constant = " + autoAR.getConstant());
        System.out.println();
        new PrintMatrix("AR estimates are:  ").print(autoAR.getAR());

        System.out.println("");
        System.out.println("");
        System.out.println("    Maximum Likelihood ");
        System.out.println("");
        autoAR.setEstimationMethod(ARAutoUnivariate.MAX_LIKELIHOOD);
        autoAR.compute();

        System.out.println("Order Selected: " + autoAR.getOrder());
        System.out.println("AIC = " + autoAR.getAIC() + "       Variance = "
                + autoAR.getInnovationVariance());
        System.out.println("Constant = " + autoAR.getConstant());
        System.out.println();
        new PrintMatrix("AR estimates are:  ").print(autoAR.getAR());
    }
}

Output


    Method of Moments 

Order Selected: 3
AIC = 405.9812419650225       Variance = 287.2699077443474
Constant = 13.70978940109534

AR estimates are:  
     0     
0   1.368  
1  -0.738  
2   0.078  



    Least Squares 

Order Selected: 3
AIC = 405.9812419650225       Variance = 221.99519660517407
Constant = 11.610494624981452

AR estimates are:  
     0     
0   1.55   
1  -1.004  
2   0.205  



    Maximum Likelihood 

Order Selected: 3
AIC = 405.9812419650225       Variance = 218.84837588472615
Constant = 11.417850982501161

AR estimates are:  
     0     
0   1.551  
1  -0.999  
2   0.204  

Link to Java source.