# # Written by: # -- # John L. Weatherwax 2009-04-21 # # email: wax@alum.mit.edu # # Please send comments and especially bug reports to the # above email address. # #----- mk_acf_plots = function( Z_t, save_Plots=F, name="" ){ # # Make Autocorrelation Plots when given an input time series Z_t # DN="../../WriteUp/Graphics/Chapter6/" # Plot the time series: # if( save_Plots ){ fn=paste(paste(DN,name,sep=""),"_z_t.eps",sep="") postscript(fn, onefile=FALSE, horizontal=FALSE) } title=paste(name,"z_t",sep=": ") plot( Z, type="l", col=c("black"), main=title ) if( save_Plots ){ dev.off() } if( !save_Plots ){ par(ask=TRUE) } # assume the user is going to view these plots # Plot the ACF for Z_t, Delta(Z_t), and Delta^2(Z_t): # if( save_Plots ){ fn=paste(paste(DN,name,sep=""),"_acf_z_t.eps",sep="") postscript(fn, onefile=FALSE, horizontal=FALSE) } title=paste(name,"ACF(z_t)",sep=": ") acf( Z, lag.max=12, main=title ) if( save_Plots ){ dev.off() } w1 = diff( Z, differences = 1 ) if( save_Plots ){ fn=paste(paste(DN,name,sep=""),"_acf_delta1_z_t.eps",sep="") postscript(fn, onefile=FALSE, horizontal=FALSE) } title=paste(name,"ACF( Delta(z_t) )",sep=": ") acf( w1, lag.max=12, main=title ) if( save_Plots ){ dev.off() } w2 = diff( Z, differences = 2 ) if( save_Plots ){ fn=paste(paste(DN,name,sep=""),"_acf_delta2_z_t.eps",sep="") postscript(fn, onefile=FALSE, horizontal=FALSE) } title=paste(name,"ACF( Delta^2(z_t) )",sep=": ") acf( w2, lag.max=12, main=title ) if( save_Plots ){ dev.off() } # Plot the PACF for Z_t, Delta(Z_t), and Delta^2(Z_t): # if( save_Plots ){ fn=paste(paste(DN,name,sep=""),"_pacf_z_t.eps",sep="") postscript(fn, onefile=FALSE, horizontal=FALSE) } title=paste(name,"PACF(z_t)",sep=": ") pacf( Z, lag.max=12, main=title ) if( save_Plots ){ dev.off() } if( save_Plots ){ fn=paste(paste(DN,name,sep=""),"_pacf_delta1_z_t.eps",sep="") postscript(fn, onefile=FALSE, horizontal=FALSE) } title=paste(name,"PACF( Delta(z_t) )",sep=": ") pacf( w1, lag.max=12, main=title ) if( save_Plots ){ dev.off() } if( save_Plots ){ fn=paste(paste(DN,name,sep=""),"_pacf_delta2_z_t.eps",sep="") postscript(fn, onefile=FALSE, horizontal=FALSE) } title=paste(name,"PACF( Delta^2(z_t) )",sep=": ") pacf( w2, lag.max=12, main=title ) if( save_Plots ){ dev.off() } } # Load the individual series and plot # Z = scan("../../Data/series_a.dat",strip.white=T) mk_acf_plots( Z, name="Series_A", save_Plots=F ) Z = scan("../../Data/series_b.dat",strip.white=T) mk_acf_plots( Z, name="Series_B", save_Plots=F ) Z = scan("../../Data/series_c.dat",strip.white=T) mk_acf_plots( Z, name="Series_C", save_Plots=F ) Z = scan("../../Data/series_d.dat",strip.white=T) mk_acf_plots( Z, name="Series_D", save_Plots=F ) Z = scan("../../Data/series_e.dat",strip.white=T) mk_acf_plots( Z, name="Series_E", save_Plots=F ) Z = scan("../../Data/series_f.dat",strip.white=T) mk_acf_plots( Z, name="Series_F", save_Plots=F )