load("workspace.RData")
Even after taking out the seasonal and trend component, the random component may be serially correlated. We measure it using Correlograms. Below is the image of the correlogram
wave.dat <- read.table("ts/wave.dat",header=T)
acf(wave.dat$waveht)
A correlogram has the following features 1. The x-axis gives the lag k and the y axis gives the autocorrelation (rk) at each lag. The unit of lag is the sampling interval 0.1 second. Correlation is dimensionless, so there is no unit for y-axis.
If rk falls outside these blue lines, autocorrelation is not zero at 5% confidence. Remember 5% of the lines will fall outside.
lag 0 autocorrelation is always 1.
A lag 1 autorcorrelation of 0.5 implies that a linear depenence of Xt on Xt-1 would explain 5% of the variability of xt.
Some Tips
Usually a trend in the data will show in the correlogram as a slow decay in the autocorrelation, which are large and positive due to similar values in the series occuring close together in time.
If there are seasonal variation, seasonal spikes will be superimposed on this pattern.
If you take a large number of cycles of a discrete sinusidal wave of any amplitude and phase, the acf is a discrete cosine function of the same period.
Lets see the ACF of airpassengers data
acf(AirPassengers)
Here it can be seen easily from the discussion above that it has a trend and seasonality.
We normally do not rely on correlograms to identify the trends and seasonal patterns. The main use of the correlogram is to detect Autocorrelation in the time series after we have removed an estimate of trend and seasonal variation.
Lets decompose the data of AirPassenges and use acf for the random component.
data("AirPassengers")
AP <- AirPassengers
AP.decom <- decompose(AP,"multiplicative")
plot(ts(AP.decom$random[7:138]))
Lets Plot ACF of random component of AP. Here we have left the first 6 and last 6 values because we are using centered moving average of 12 to smooth the time series.
acf(AP.decom$random[7:138])
The ACF suggests that either a damped cosine shape that is characteristic of an autoregressive model of order 2 ( we study it later) or that the seasonal adjustment has not been very effective. To check the later we we calculate the sd of the original series, after trend correction and after seasonal adjustment
sd(AP[7:138])
## [1] 109.4187
sd(AP[7:138]-AP.decom$trend[7:138])
## [1] 41.11491
sd(AP.decom$random[7:138])
## [1] 0.0333884
The reduction in the sd shows that the seasonal adjustment has been very effective.
Period: Jan 1909 to Dec 1980 Data: values Any Transformation in the Data: Original Type: Effective Inflows to the Font Reservoir Unit: meter cube per second Frequency: Monthly Start of Frequency: Jan End of Frequency: Dec
lets read the data and draw a plot of the data:
Fontdsdt.dat <- read.table("ts/Fontdsdt.dat", header=T)
attach(Fontdsdt.dat)
plot(ts(adflow),ylab='adflow')
there seems to he seasonal variations. Lets draw the ACF of the original series
acf(adflow,xlab='lag(Months)',main="")
There is a statistical significant correlation at lag 1. An exponential decay in the correlogram is typical of a first order autoregressive model.
“Introductory Time Series with R”
save.image("workspace.Rdata")