library("zoo") library("ggplot2") library("Rwave") library("WaveletCo") setwd("C:/Users/Blake/Desktop/Elnino") temp<-read.csv("HadCRUT4_global_monthly_temperatures_1850-2014.csv") lintemp<-lm(temp$x ~ temp$X) par(mfrow=c(2,1)) plot(zoo(temp$x,temp$X),xlab="",ylab="") mtext("Monthly Temp Anomalies",side=3) abline(lintemp$coef) x<-resid(lintemp) plot(zoo(x,temp$X), xlab="",ylab="") fttemp<-fft(x-mean(x)) modft<-Mod(fttemp)^2/length(x) freq = (1:length(x)-1)/length(x) id<-modft>.2 & freq<.5 & freq>.01 freq[id] plot(freq[20:(length(freq)-1600)],modft[20:(length(modft)-1600)],type='h', xlab="",ylab="") mtext("Detrended, Not smoothed") mtext("FFT Modulus", side=2, line=2.5) mtext("Frequency (1/months)",side=1,line=2.4) smoothtemp<-spline(temp$X, resid(lintemp), 984/2) smoothft<-fft(smoothtemp$y-mean(smoothtemp$y)) modsmooth<-Mod(smoothft)^2/length(smoothtemp$y) freqsmooth = (1:length(smoothtemp$y)-1)/length(smoothtemp$y) plot(freqsmooth[20:(length(freqsmooth)-775)],modsmooth[20:(length(modsmooth)-775)],type='h', xlab="", ylab="") mtext("Frequency (1/(2months))", side=1, line=2.4) mtext("FFT Modulus",side=2,line=2.5) mtext("Detrended, Smoothed Data",side=3)