### Example 1: AutoCorrelation

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. This example computes the estimated autocovariances, estimated autocorrelations, and estimated standard errors of the autocorrelations using both Bartletts and Moran formulas.

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

public class AutoCorrelationEx1 {

public static void main(String args[]) throws Exception {
double[] x = {
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
};

AutoCorrelation ac = new AutoCorrelation(x, 20);

new PrintMatrix("AutoCovariances are:  ").print(
ac.getAutoCovariances());
System.out.println();
new PrintMatrix("AutoCorrelations are:  ").print(
ac.getAutoCorrelations());
System.out.println("Mean = " + ac.getMean());
System.out.println();
new PrintMatrix("Standard Error using Bartlett are:  ").print(
ac.getStandardErrors(AutoCorrelation.BARTLETTS_FORMULA));
System.out.println();
new PrintMatrix("Standard Error using Moran are:  ").print(
ac.getStandardErrors(AutoCorrelation.MORANS_FORMULA));
System.out.println();
new PrintMatrix("Partial AutoCovariances:  ").print(
ac.getPartialAutoCorrelations());
ac.setMean(50);
new PrintMatrix("AutoCovariances are:  ").print(
ac.getAutoCovariances());
System.out.println();
new PrintMatrix("AutoCorrelations are:  ").print(
ac.getAutoCorrelations());
System.out.println();
new PrintMatrix("Standard Error using Bartlett are:  ").print(
ac.getStandardErrors(AutoCorrelation.BARTLETTS_FORMULA));
}
}

#### Output

AutoCovariances are:
0
0  1,382.908
1  1,115.029
2    592.004
3     95.297
4   -235.952
5   -370.011
6   -294.255
7    -60.442
8    227.633
9    458.381
10    567.841
11    546.122
12    398.937
13    197.757
14     26.891
15    -77.281
16   -143.733
17   -202.048
18   -245.372
19   -230.816
20   -142.879

AutoCorrelations are:
0
0   1
1   0.806
2   0.428
3   0.069
4  -0.171
5  -0.268
6  -0.213
7  -0.044
8   0.165
9   0.331
10   0.411
11   0.395
12   0.288
13   0.143
14   0.019
15  -0.056
16  -0.104
17  -0.146
18  -0.177
19  -0.167
20  -0.103

Mean = 46.976000000000006

Standard Error using Bartlett are:
0
0  0.035
1  0.096
2  0.157
3  0.206
4  0.231
5  0.229
6  0.209
7  0.178
8  0.146
9  0.134
10  0.151
11  0.174
12  0.191
13  0.195
14  0.196
15  0.196
16  0.196
17  0.199
18  0.205
19  0.209

Standard Error using Moran are:
0
0  0.099
1  0.098
2  0.098
3  0.097
4  0.097
5  0.096
6  0.095
7  0.095
8  0.094
9  0.094
10  0.093
11  0.093
12  0.092
13  0.092
14  0.091
15  0.091
16  0.09
17  0.09
18  0.089
19  0.089

Partial AutoCovariances:
0
0   0.806
1  -0.635
2   0.078
3  -0.059
4  -0.001
5   0.172
6   0.109
7   0.11
8   0.079
9   0.079
10   0.069
11  -0.038
12   0.081
13   0.033
14  -0.035
15  -0.131
16  -0.155
17  -0.119
18  -0.016
19  -0.004

AutoCovariances are:
0
0  1,392.053
1  1,126.524
2    604.162
3    106.754
4   -225.882
5   -361.026
6   -286.57
7    -53.76
8    235.966
9    470.786
10    584.014
11    564.764
12    418.363
13    216.104
14     43.125
15    -63.468
16   -131.501
17   -189.063
18   -229.689
19   -212.156
20   -121.569

AutoCorrelations are:
0
0   1
1   0.809
2   0.434
3   0.077
4  -0.162
5  -0.259
6  -0.206
7  -0.039
8   0.17
9   0.338
10   0.42
11   0.406
12   0.301
13   0.155
14   0.031
15  -0.046
16  -0.094
17  -0.136
18  -0.165
19  -0.152
20  -0.087

Standard Error using Bartlett are:
0
0  0.034
1  0.097
2  0.159
3  0.21
4  0.236
5  0.233
6  0.212
7  0.18
8  0.147
9  0.134
10  0.148
11  0.172
12  0.19
13  0.197
14  0.198
15  0.198
16  0.198
17  0.201
18  0.207
19  0.21