#
# Generate an AR(1) time series
#
vv <- arima.sim(model=list(ar=0.8), n=1024)
#
# Compute the ACF of this stationary series
#
vv.acf <- acf(vv, plot=FALSE)
#
# Compute the localized autocovariance. We'll use
# a reasonably smooth wavelet.
#
vv.lacv <- lacv(vv, filter.number=4)
#
# Various plots of the lacv
#
# The whole lacv at time t=100. First work out sizes:
#
dim(vv.lacv)
# [1] 1024 14323
#
(14323-1)/2
# [1] 7161
#
# So, rows of vv.lacv index time ranging from 1 to 1024
# Cols index lag ranging from -7161 through to 7161.
#
# Now the plot
#
plot( -7161:7161, vv.lacv[100,], type="l", xlab="lag", ylab="Autocovariance")
#
# Most of the action, for this time series especially, is near to the zero
# lag. So, let's zoom in on the action. And let's plot autocorrelation,
# rather than autocovariance. We'll use the estimate of the autocovariance
# at lag zero at this time for the denominator.
#
# The following commands plots the lacv for lags ranging from -10 to 10 at
# time t=100. Change the 100 to something else for different times
#
plot(-10:10,vv.lacv[100,(7162-10):(7162+10)]/vv.lacv[100,7162], type="l", xlab="lag")
#
# Let us get an indication of how accurate the lacv is, we shall superimpose
# some of the regular acf values on this plot. Note that vv.acf[1] contains
# the acf at lag zero, which is 1.
#
points(1, vv.acf[2])
points(2, vv.acf[3])
points(3, vv.acf[4])
points(4, vv.acf[5])
#
# You should find that the lacv is pretty accurate, which is good
# seeing as it is a local quantity.
#
Run the code above in your browser using DataLab