# March 23 2001 # Script for periodogram examples for spectral density course library(ts) # need ts data(sunspots) # attach the sunspot data euler_-0.577216 var.log.exp_pi^2/6 var.exp_1 sunspot.pgram_pgram(sunspots) f.hat.plt.eg2_function(m=15,x.pgram,bands=T){ par(oma=c(0,0,4,0)) txt_paste( c("Daniell Smooth, m = ",m),collapse="") k.daniell_kernel("daniell",m=m) # f.hat_kernapply(x.pgram$pgram/(2*pi),k.daniell) freq_x.pgram$freq[m:(length(x.pgram$pgram)-(m+1))] log.f.hat_kernapply(log(x.pgram$pgram/(2*pi)),k.daniell) if(bands==T){ log.f.ci.up_log.f.hat+2*sqrt(var.log.exp/(2*m+1)) log.f.ci.low_log.f.hat-2*sqrt(var.log.exp/(2*m+1)) ylim_c(min(log.f.hat,log.f.ci.low), max(log.f.hat,log.f.ci.up)) plot(freq,log.f.hat,type="l",main=txt,ylim=ylim) lines(freq,log.f.ci.up,lty=2) lines(freq,log.f.ci.low,lty=2) } else{ plot(freq,log.f.hat,type="l",main=txt) } mtext("Monthly Sunspot Smoothed Log Periodogram", outer=T,side=3,line=3,cex=1.5) } f.hat.plt.eg2(15,sunspot.pgram,bands=T) f.hat.plt.eg2(25,sunspot.pgram,bands=T)