# 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)
#This is an object of type "list".
# How do we ge the names of the items in the list?
names(yacf)
# 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
# This looks like an array... lets check
temp=yacf$acf
class(temp)
# 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]