The following are the issues that I summarize succinctly in sequence, as each of them are an interesting problem in itself and then follow it up with my solutions:
i) How to unlag two time-series so as to lose the least data due to the lagging, and at the same time to maximize the cross-correlation or spectral coherence.
ii) how would this be done when you are dealing with multivariate time-series. As it's greater than the two, its like solving a rubiks cube optimally while lagging various time-series in the dataset so as to preserve a summed up measure of (i).
iii) How to compute a weighted-coherence?
I will skip ii) and answer i) and iii) due to reasons of conflict of interest and research collaboration/confidential agreements on my work on ii). I understand that iii) happens to be the central question to start with followed by i).
My solution for iii)
Pre-Processing Steps: Say you had two time -series t1 and t2. Determine a CCF maximizing lag, say optLag and unlag t1 and t2 as unlaggedTS = lag(t2,optLag)
and perform a time-series union of the dataset as unionTS = ts.union(t1,unlaggedTS)
.
Following that, as the time-series unlagging would produce a few NA's as you lose entries by lagging, you need to set these values to zero in unionTS as required-meaning that nothing was observed at the NA points.
Step 2:
Now, obtain an abinded time-series, with the span parameters as required.
bindTSPair= abind(((spectrum(unionTS,span=c(16,16),plot=F)$spec)[,1]),((spectrum(unionTS,span=c(16,16),plot=F)$spec)[,2]))
Following it, just normalize the data in bindTSPair as say:
normalizedTS=round(data.Normalization(c(bindTSPair),type="n4"),6)
Then obtained the following two halves:
TSHalf1=normalizedTS[1:(length(bindTSPair)/2)]
TSHalf2=normalizedTS[((length(bindTSPair)/2)+1):(length(bindTSPair))]
and then finally obtain 'a weighted' version of spectral coherence as follows:
weightedCoherence=sum((10*(TSHalf1 + TSHalf2)) * (spectrum(unionTS,span=c(10,10),plot=F)$coh))
You may change the weighting as required or using 'prior' info.
My solution for i) to obtain a CCF maximizing lag:
for(i in 2:ncol(myTS))
{
for(j in 2:ncol(myTS))
{
r=ccf(myTS[,i],myTS[,j],lag.max=1000,plot=TRUE)
tp=sort((r$acf),index.return=TRUE)$ix
tn=sort((r$acf),index.return=TRUE,decreasing=T)$ix
cn=r$acf[tn[length(tn)]]
cp=r$acf[tp[length(tp)]]
if(abs(cp) > abs(cn))
{
temp=r$lag[tp[length(tp)]]
tcc=cp
}
if(abs(cn) > abs(cp))
{
temp=r$lag[tn[length(tn)]]
tp=tn
tcc=cn
}
if(abs(cn) > abs(cp))
{
temp=r$lag[tp[length(tp)]]
}
show(i)
if(length(tp) != 0)
{
mlag[i,j]=temp
mcc[i,j]=tcc
}
}
}
mlag=mlag[2:ncol(myTS),2:ncol(myTS)]
mlag=data.frame(mlag)
Best Answer
The power spectrum is the frequency-domain counterpart of the time-domain autocovariance function.
According to the frequency-domain view, a white noise process can be viewed as the sum of an infinite number of cycles with different frequencies where each cycle has the same weight.
The power spectrum is not used to predict a time series. It is used to examine the main characteristics of the series and propose a time series model accordingly. For example, it can be used to detect if seasonality is present in the data, if so, the spectrum will show peaks at the seasonal frequencies.
In principle, the same information can be obtained from both the spectrum and the autocovariance function, but in some contexts it is more convenient to work with the frequency-domain representation. For example, if you are interested in looking at the seasonal frequencies that determine the seasonal pattern observed in the series, the spectrum will show you the cycles that lead that component. If you want to analyze the frequency of some phenomenon such as the business cycle, the spectrum is a straightforward way to get a graphical view to it.