library(zoo)
library(waveslim)
options(repr.plot.width=8, repr.plot.height=4)
dat=read.table(file="GMSL_TPJAOS_V4.2_199209_201711.txt",header=FALSE)
# year+fraction of year (mid-cycle)
time.msl=dat$V3
# smoothed (60-day Gaussian type filter) GMSL (GIA applied) variation (mm); annual and semi-annual signal removed
msl.mean=dat$V12
plot(zoo(msl.mean,time.msl), xlab="",ylab="MSL (mm)")
# linear detrending
msl.detrended=residuals(lm(msl.mean~time.msl))
plot(zoo(msl.detrended,time.msl), xlab="",ylab="MSL - detrended (mm)")
mei=t(read.table(file="mei.data",header=FALSE)[,2:13])
library(tidyr)
mei.ts=ts(gather(as.data.frame(mei),V2:V13)$value,start=1993, frequency=12)
plot(time(mei.ts)[which(mei.ts>0)],mei.ts[which(mei.ts>0)],type="h",xlab="",ylab="MEI enso index",col=2,ylim=c(-2,3))
lines(time(mei.ts)[which(mei.ts<0)],mei.ts[which(mei.ts<0)],type="h",xlab="",ylab="MEI enso index",col=4,ylim=c(-2,3))
plot(zoo(msl.detrended,time.msl),type="h",xlab="",ylab="MSL (mm)")
acf(msl.detrended, main="GMSL - detrended",lag.max=100)
pacf(msl.detrended, main="GMSL - detrended",lag.max=100)
library(forecast)
auto.arima(msl.detrended)
arima(msl.detrended,order=c(1,0,0))
par(mfrow=c(1,2))
hist(msl.detrended,main="", xlab="mm")
qqnorm(msl.detrended)
qqline(msl.detrended)
msl.modwt <- modwt(msl.detrended, "haar", 6)
msl.modwt.bw <- brick.wall(msl.modwt, "haar")
msl.modwt.var <- wave.variance(msl.modwt.bw)
matplot(2^(0:5), msl.modwt.var[-7,], type="b", log="xy",
xaxt="n", ylim=c(.001, 6), pch="*LU", lty=1, col=c(1,4,4),
xlab="wavelet Scale", ylab="", main="Wavelet spectrum (Haar wavelet filter)")
axis(side=1, at=2^(0:5))
msl.modwt <- modwt(msl.detrended, "la8", 6)
msl.modwt.bw <- brick.wall(msl.modwt, "la8")
msl.modwt.var <- wave.variance(msl.modwt.bw)
matplot(2^(0:5), msl.modwt.var[-7,], type="b", log="xy",
xaxt="n", ylim=c(.001, 6), pch="*LU", lty=1, col=c(1,4,4),
xlab="wavelet Scale", ylab="",main="Wavelet spectrum (LA8 filter)")
axis(side=1, at=2^(0:5))