library(bspec)
library(lomb)
library(WaveletComp)
library(zoo)
library(quantmod)
library(dplyr)
library(astrochron)
library(IRISSeismic)
library(Hmisc)
setwd("C:/MSc_CC/lisas")
spec1 <- welchPSD(sunspots, seglength=200)
plot(spec1$frequency, spec1$power, log='y',type="l", xlim=c(0,1))
spec1$frequency[findPeaks(spec1$power, thresh=30000.0)]
## [1] 0.095
1/0.095
## [1] 10.52632
rm(spec1)
read.csv("NAO.csv", header=TRUE)
mydata <- read.table("NAO.csv", header=FALSE, sep=",")[,2]
NAO <- ts(mydata,start=1825, end=2017)
plot (NAO, type="l")
NAOwelch <- welchPSD(NAO, seglength=100) # use seg100 for NAO
plot(NAOwelch$frequency, NAOwelch$power,type="l", xlim=c(0,0.6))
NAOwelch$frequency[findPeaks(NAOwelch$power, thresh=1)]
## [1] 0.09 0.14 0.21
Peak 1
1/0.09
## [1] 11.11111
Peak 2
1/0.14
## [1] 7.142857
Peak 3
1/0.21
## [1] 4.761905
write.table(NAO, file = "Winter_NAO_data.csv", col.names=FALSE, sep=",")
rm(NAOwelch)
rm(mydata)
rm(NAO)
read.csv("Precipitation_Ireland.csv", header=TRUE)
mydata <- read.table("Precipitation_Ireland.csv", header=TRUE, sep=",")
IrePrec <- ts(mydata,start=1711, end=2016)
plot(IrePrec, type="l")
data2 <- (mydata %>% filter(mydata$Month == c(1, 2)))
data_winter <- aggregate(data2[,3],list(data2$Year), mean)
detrended <- detrend(data_winter)
dev.off()
detrendedts <- ts(detrended$x,start=1711, end=2016)
plot(detrendedts, type= "l")
detrendtswelch <- welchPSD(detrendedts, seglength=50) # use seg50 for ire prec
plot(detrendtswelch$frequency, detrendtswelch$power,type="l", xlim=c(0,0.6))
detrendtswelch$frequency[findPeaks(detrendtswelch$power, thresh=600)]
## [1] 0.04 0.14 0.20 0.30
Peak 1
1/0.04
## [1] 25
Peak 2
1/0.14
## [1] 7.142857
Peak 3
1/0.2
## [1] 5
Peak 4
1/0.3
## [1] 3.333333
write.table(detrendedts, file = "Winter _precipitation_data.csv", row.names=FALSE, col.names=FALSE, sep=",")
read.csv("Winter _precipitation_data.csv", header=FALSE)
precipitation_winter <- read.table("Winter _precipitation_data.csv", sep=",")
read.csv("Winter_NAO_data.csv", header=FALSE)
NAO_winter <- read.table("winter_NAO_data.csv", sep=",")
ts1 <- ts(precipitation_winter$V1,start=1711, end=2016)
ts2 <- ts(NAO_winter$V2, start=1825, end=2017)
t <- ts.intersect(ts1,ts2,dframe=TRUE)
correlation = rcorr(t$ts1,t$ts2, type="pearson")
The correlation value between winter precipitation and winter NAO is 0.12. The number of data points across both time series is 499. Reading across the Pearson correlation table we arrive at a value of 0.01 along the top. The correlation value is 0.12 is larger than this and therefore can be considered significant.
DF <- crossSpectrum(t)
transferFunction <- DF$Pxy / DF$Pxx
transferAmp <- Mod(transferFunction)
plot(DF$freq,transferAmp,type='l',log='x', xlab="Frequency", main="Transfer Function Amplitude")
A clear cycle for both data sets can be seen at a frequency of 0.2. This reaches a peak transfer amplitude of 1.
write.table(t, file = "NAO_and_precipitation_data.csv", col.names=FALSE, sep=",")
read.csv("pedrido.csv", header=TRUE)
mydata <- read.table("pedrido.csv", header=TRUE, sep=",")
plot(mydata$Sand~mydata$Age, type= "l")
There is possibly a cycle occurring at every 1000 intervals of age. Roughly, every interval of 1000 along the age axis there is a sudden increase to a peak in the sand data. This tends to be followed by a sudden decrease in the sand data. These peaks increase to different amplitudes, but there is roughly a 1000 age interval year frequency.
mydata$Depth=NULL
ls<- lsp(mydata, from = NULL, to = NULL, ofac = 5, alpha = 0.05, plot = TRUE)
A significance of over 95% (0.05) was chosen. There are two peaks at a frequency of 0.001 and 0.003.
lsp(mydata, from = NULL, to = NULL, ofac = 5, alpha = 0.05,type = c("period"), plot = TRUE)
New_age <- seq(from = -10, to = 4600, by = 10)
new_data <- approx(x=mydata$Age, y=mydata$Sand, xout=New_age, method="linear")
names(new_data) <- c("date","sand")
plot(mydata$Age, mydata$Sand, type="o", col="blue", lty=1, main="Original Data vs Downsampled Data")
points(new_data$date, new_data$sand, col="red", pch="*")
lines(new_data$date, new_data$sand, col="red",lty=2)
The original data appear to have occasionally more dramatic and higher peaks than the downsampled data. For example, at the age interval of around 900, the original sand data reaches a peak value of 12, while the downsampled data only reaches a peak of just over 10. Similarly, the peak at the age interval of 3300 shows a difference in peak values, with the original data peak reaching 15, and the downsampled data reaching 14. Generally, the original data and downscaled data follow the same pattern, with an occasional reduction in peak values in the downsampled data.
write.csv(new_data, file = "PedridoEvenData.csv")
Pedrido <- read.csv("PedridoEvenData.csv")[ ,3]
New_age <- read.csv("PedridoEvenData.csv")[ ,2]
my.data = data.frame(date = New_age, Pedrido=Pedrido)
my.wt = analyze.wavelet(my.data, "Pedrido", loess.span = 0, dt = 10, dj = 1/20, make.pval = TRUE, method = "white.noise", params = NULL, n.sim = 100, date.format = "%Y", date.tz = NULL, verbose = TRUE)
wt.image(my.wt, color.key = "i", label.time.axis = TRUE, main = "wavelet power spectrum", legend.params = list(lab = "wavelet power levels"), periodlab = "period (years)", timelab = "time (years)", date.format = "%d", spec.time.axis = list(at = seq(-10, 462, by = 10), labels = seq(0, 460, by = 50)))
## Warning in wt.image(my.wt, color.key = "i", label.time.axis = TRUE, main = "wavelet power spectrum", :
## Please check your time axis specifications. Default settings were used.
There appears to be one main significant cycle. This occurs between 2000-3500 year ago. This had a cyclical frequency of roughly 500 years. Two other cycles appear but seem to be relatively less significant.
wt.avg(my.wt, siglvl=0.05, sigcol="red")
read.csv("NAO_and_precipitation_data.csv", header=FALSE)
NAO_precip_winter <- read.table("NAO_and_precipitation_data.csv", sep=",")[,2:3]
my.date <- seq(as.POSIXct("1825-01-30 00:00:00", format = "%Y"), by = "year", length.out = 192)
date<- my.date
my.data <- cbind(NAO_precip_winter,date)
my.wc <- analyze.coherency(my.data, c(1, 2), dt=1)
wc.image(my.wc, main = "cross-wavelet power spectrum, x over y", legend.params = list(lab = "cross-wavelet power levels"), periodlab = "period (years)", show.date = TRUE)
read.csv("CET.csv", header=TRUE)
CET <- read.csv("CET.csv")[ ,14]
Year <- read.csv("CET.csv")[ ,1]
my.data = data.frame(date = Year, CET=CET)
my.wt = analyze.wavelet(my.data, "CET", loess.span = 0, dt = 10, dj = 1/20, make.pval = TRUE, method = "white.noise", params = NULL, n.sim = 100, date.format = "%Y", date.tz = NULL, verbose = TRUE)
wt.image(my.wt, color.key = "i", label.time.axis = TRUE, main = "wavelet power spectrum", legend.params = list(lab = "wavelet power levels"), periodlab = "period (years)", timelab = "time (years)", date.format = "%d", spec.time.axis = list(at = seq(-10, 462, by = 10), labels = seq(0, 460, by = 50)))
## Warning in wt.image(my.wt, color.key = "i", label.time.axis = TRUE, main = "wavelet power spectrum", :
## Please check your time axis specifications. Default settings were used.
There seems to be less pronounced significant events in this power spectrum. The most significant events occurs around 2750 years ago. This had a cyclical frequency of around 16 years. Another significant event seems to have occurred around around 2300-2400 years ago. This had a cyclical frequency of around 16 years also.
wt.avg(my.wt, siglvl=0.05, sigcol="red")