#Smoothing the periodogram: spec.pgram as last week #regulate the amount of smoothing with the argument span # Ocean wave data (From Percival and Walden) ocw <- ts(scan(url("http://stat.ethz.ch/Teaching/Datasets/ocwave.dat")), frequency=4) ocw <- ts(scan("Ocwave.sapa"),frequency=4) plot(ocw) acf(ocw,lag.max=100) spec.pgram(ocw,taper=0,demean=TRUE,detrend=FALSE) spec.pgram(ocw,demean=TRUE,detrend=FALSE,add=TRUE,col=2) #notice again the advantage of tapering (taper has default value 0.1) par(mfrow=c(3,1)) #smoothing the periodogram spec.pgram(ocw,demean=TRUE,detrend=FALSE) spec.pgram(ocw,spans=c(5,5)) spec.pgram(ocw,spans=c(11,11)) spec.ar(ar.mle(ocw)) #ar spectrum for comparison spec.ar(ar.burg(ocw)) # To understand the argument span: Show the weights used for smoothing sp <- spec.pgram(ocw,spans=11,plot=FALSE) sp$kernel sp <- spec.pgram(ocw,spans=c(11,11),plot=FALSE) sp$kernel #Lynx data par(mfrow=c(3,1)) spec.pgram(log(lynx),demean=TRUE,detrend=FALSE) spec.pgram(log(lynx),spans=c(3,3),demean=TRUE,detrend=FALSE) spec.ar(ar.mle(log(lynx))) #simulated AR(4), as used last week ar.coef <- c(2.7607,-3.8106,2.6535,-0.9238) x <- arima.sim(n=1024,model=list(ar=ar.coef)) par(mfrow=c(3,1)) spec.pgram(x,demean=TRUE,detrend=FALSE) spec.pgram(x,spans=c(11,11),demean=TRUE,detrend=FALSE) spec.ar(ar.mle(x,order.max=4))