# spectrum of recruits Splus rec_scan("E:\\Stat207\\Class\\Examples\\Ch2\\recruit.dat") help(spec.pgram) # to get details # see the difference par(mfrow=c(2,2)) spec.pgram(rec, spans=1, taper=0.1, pad=0, detrend=F, demean=T, plot=T) spec.pgram(rec, spans=3, taper=0.1, pad=0, detrend=F, demean=T, plot=T) spec.pgram(rec, spans=c(3,3), taper=0.1, pad=0, detrend=F, demean=T, plot=T) spec.pgram(rec, spans=c(3,5), taper=0.1, pad=0, detrend=F, demean=T, plot=T) # note spectrum() does the same thing as spec.pgram # AR spectral estimate for recruits rec.ar <- ar(rec) # Fit an AR model using AIC rec.ar$aic # to see which model is chosen (p=13) par(mfrow=c(1,1)) rec.arspec <- spec.ar(rec.ar,plot=T) # superimpose the AR spectrum for this rec.per <- spec.pgram(rec) # data and its periodogram. spec.plot(rec.per, add=T) # Coherency between SOI and Recruits x1_matrix(soi) x2_matrix(rec) x_cbind(x1,x2) spec_spec.pgram(x, spans=c(3,5), taper=0.1, pad=0, detrend=F, demean=T, plot=T) rho_spec$coh length(rho) length(x1) freq_(1:length(rho)-1)/length(x1) plot(freq,rho,type="l")