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 Barlett and Moran formulas.
using System;
using Imsl.Stat;
using PrintMatrix = Imsl.Math.PrintMatrix;
public class AutoCorrelationEx1
{
public static void Main(String[] args)
{
double[] x = new double[]{ 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());
Console.Out.WriteLine();
new PrintMatrix
("AutoCorrelations are: ").Print(ac.GetAutoCorrelations());
Console.Out.WriteLine("Mean = " + ac.Mean);
Console.Out.WriteLine();
new PrintMatrix
("Standard Error using Bartlett are: ").Print
(ac.GetStandardErrors(AutoCorrelation.StdErr.Bartletts));
Console.Out.WriteLine();
new PrintMatrix
("Standard Error using Moran are: ").Print
(ac.GetStandardErrors(AutoCorrelation.StdErr.Morans));
Console.Out.WriteLine();
new PrintMatrix
("Partial AutoCovariances: ").
Print(ac.GetPartialAutoCorrelations());
ac.Mean = 50;
new PrintMatrix
("AutoCovariances are: ").Print
(ac.GetAutoCovariances());
Console.Out.WriteLine();
new PrintMatrix
("AutoCorrelations are: ").
Print(ac.GetAutoCorrelations());
Console.Out.WriteLine();
new PrintMatrix
("Standard Error using Bartlett are: ").Print
(ac.GetStandardErrors(AutoCorrelation.StdErr.Bartletts));
}
}
AutoCovariances are:
0
0 1382.908024
1 1115.02915024
2 592.00446848
3 95.29741072
4 -235.95179904
5 -370.0108088
6 -294.25541456
7 -60.44237232
8 227.63259792
9 458.38076816
10 567.8407384
11 546.12202864
12 398.93728688
13 197.75742912
14 26.89107936
15 -77.2807224
16 -143.73279616
17 -202.04799792
18 -245.37223168
19 -230.81567344
20 -142.8788232
AutoCorrelations are:
0
0 1
1 0.806293065691258
2 0.428086653780237
3 0.0689108813212006
4 -0.170620023128885
5 -0.267559955093586
6 -0.212780177317129
7 -0.043706718936501
8 0.164604293249802
9 0.331461500117813
10 0.410613524938228
11 0.394908424249623
12 0.288477093166393
13 0.143001143740562
14 0.0194453129877855
15 -0.0558827637549379
16 -0.10393518127421
17 -0.146103713633525
18 -0.17743206881559
19 -0.166906019369514
20 -0.103317661565611
Mean = 46.976
Standard Error using Bartlett are:
0
0 0.0347838253702384
1 0.0962419914340011
2 0.156783378574532
3 0.205766777086907
4 0.230955675779118
5 0.228994712235613
6 0.208621905639667
7 0.178475936561125
8 0.145727084432033
9 0.134405581638002
10 0.150675803916788
11 0.174348147103935
12 0.190619474429408
13 0.195490061669564
14 0.195892530944597
15 0.196285328179458
16 0.196020624500033
17 0.198716030900604
18 0.205358590947539
19 0.2093868822353
Standard Error using Moran are:
0
0 0.0985184366143778
1 0.0980196058819607
2 0.0975182235357506
3 0.0970142500145332
4 0.0965076447241154
5 0.0959983659991659
6 0.0954863710632231
7 0.0949716159867634
8 0.094454055643212
9 0.0939336436627724
10 0.0934103323839415
11 0.0928840728025648
12 0.0923548145182799
13 0.0918225056781811
14 0.0912870929175277
15 0.090748521297303
16 0.0902067342384192
17 0.0896616734523426
18 0.0891132788679007
19 0.0885614885540095
Partial AutoCovariances:
0
0 0.806293065691258
1 -0.634544877310468
2 0.0782508772709519
3 -0.0585660846582815
4 -0.00094221571933657
5 0.171719898229681
6 0.108591873581717
7 0.11000138764865
8 0.0785374339029981
9 0.0791563332964613
10 0.0687065876031485
11 -0.0378019674610775
12 0.0811184838397538
13 0.0334124214991749
14 -0.0348467839607946
15 -0.130648157884444
16 -0.154900984829049
17 -0.119085063160732
18 -0.0161889037437313
19 -0.00385175459253345
AutoCovariances are:
0
0 1392.0526
1 1126.5241
2 604.1624
3 106.7545
4 -225.882
5 -361.0259
6 -286.5701
7 -53.7603
8 235.9665
9 470.7857
10 584.0143
11 564.7639
12 418.3631
13 216.1044
14 43.125
15 -63.4683
16 -131.5012
17 -189.0627
18 -229.6888
19 -212.1559
20 -121.5693
AutoCorrelations are:
0
0 1
1 0.809253975029392
2 0.434008312616923
3 0.0766885532917362
4 -0.162265420142888
5 -0.259347886710603
6 -0.205861545749061
7 -0.0386194458456527
8 0.16950975846746
9 0.338195338308337
10 0.419534649768263
11 0.405705861976767
12 0.300536847530043
13 0.155241547625427
14 0.0309794328174093
15 -0.04559332025241
16 -0.0944656832651295
17 -0.135815773053403
18 -0.165000086922003
19 -0.152405088715757
20 -0.0873309672350025
Standard Error using Bartlett are:
0
0 0.0344591054641365
1 0.0972222809088609
2 0.15947410033087
3 0.209799660647689
4 0.235599778243579
5 0.233236443705991
6 0.211657508693781
7 0.180412936841618
8 0.14689653606348
9 0.133747601649498
10 0.148150190923942
11 0.172282351100035
12 0.190275929042947
13 0.196791614240352
14 0.197983743593071
15 0.198474748794747
16 0.198318159677368
17 0.201022833791806
18 0.207071652966429
19 0.210217650328868
Link to C# source.