S-PLUS : Copyright (c) 1988, 2007 Insightful Corp. S : Copyright Insightful Corp. Enterprise Developer Version 8.0.4 for Microsoft Windows : 200 7 Working data will be in C:\DDRIVE~1\MYDOCU~1\S-PLUS~1\Project1 > # Exploring the function acf() > > # The function acf(y) will compute the autocorrelation function of the object y, which can > # either be a time series or a vector that is treated like a time series. We'll observe later > # that it can deal with multiple time series, but we will stick with the univaritate case for the moment. > > #To have someting to work with, let's just create a random sequence. > > y<-rnorm(200) > > #Now look at its ACF > > yacf<-acf(y) > > # Now yacf is the output of the acf function. Let's check its "class" > > class(yacf) [1] "acf" [1] "acf" > > > #This is an object of type "list". > # How do we ge the names of the items in the list? > > names(yacf) [1] "acf" "lag" "n.used" "type" "series" "units" "call" > > # We see that the names are "acf" "lag" "n.used" "type" "series" "units" "call" > > # We can explore these in turn... > # The "bottom line" looks like it might be acf. Let's use the list selector $ to look at it. > > yacf$acf , , 1 [,1] [1,] 1.000000000 [2,] -0.025375930 [3,] 0.072179473 [4,] -0.062246031 [5,] -0.010783330 [6,] -0.005818639 [7,] 0.052141828 [8,] -0.133777373 [9,] 0.016325404 [10,] -0.027241653 [11,] -0.026463356 [12,] -0.014267245 [13,] -0.098341668 [14,] -0.060309540 [15,] -0.069225995 [16,] -0.046347466 [17,] 0.105606908 [18,] -0.002364707 [19,] -0.047133909 [20,] -0.013808956 [21,] -0.044105855 [22,] 0.071698490 [23,] -0.056716158 [24,] -0.012477802 > > # This looks like an array... lets check > > temp=yacf$acf > > class(temp) [1] "array" > > # Yup, it is an array. We can now pull out the pieces that we want. > # Say we want the first 10 nontrivial correlations in a vector. > > v=temp[2:11] > > # If you look closely (sometimes a good idea, sometimes not) you will see that temp is # actually a three > # dimensional array. > # Why? This is because acf is set up to handle multiple series. > # > # Fortunately we get easy access to the autocorrelations without specifying the "other # dimensions" > # but we could have used the more explicit extraction > > v=temp[2:11,1,1] > v [1] -0.025375930 0.072179473 -0.062246031 -0.010783330 -0.005818639 0.052141828 -0.133777373 0.016325404 -0.027241653 -0.026463356 >