I am using biwavelet package to conduct wavelet coherence analysis. I have a problem in setting the lag1 values (which should be a vector containing the AR(1) coefficient of each time series ) correctly. The following gives a reproducible example. Thanks a lot.
t1 <- cbind(1:100, rnorm(100))
t2 <- cbind(1:100, rnorm(100))
lag.t1=acf(t1,plot=F)$acf[2]
lag.t2=acf(t2,plot=F)$acf[2]
wtc.t1t2 <- wtc(t1, t2, max.scale = 32,lag1=c(lag.t1,lag.t2))
When I do this, an error occurs like this:
Warning messages:
1: In 2 * lag1 * cos(freq * 2 * pi) :
longer object length is not a multiple of shorter object length
2: In 1 - 2 * lag1 * cos(freq * 2 * pi) + lag1^2 :
longer object length is not a multiple of shorter object length
3: In (1 - lag1^2)/(1 - 2 * lag1 * cos(freq * 2 * pi) + lag1^2) :
longer object length is not a multiple of shorter object length
There seems to be a bug in
wtc. It passes offlag1to thewtfunction to compute the wavelet transform of each series separately, but does so without subsettinglag1, which is where the warnings are coming from - basically the wrong lag is getting used in the second series as the code expects a length 1 vector forlag1.What is odd is that the code internally computes the AR(1) coefficients for each series but these only get used later in the code if you want to test significance. These are never passed on; it would save computing the AR model twice for each series if the maintainer just passed on these coefficients from the
wtctop level if the user didn't supply them, and subset thelag1vector if the user does supply them.I suggest you contact the maintainer to mention the problem.
In the meantime, just don't bother computing
lag1initially; insidewt.sig, which is called bywtc->wt, iflag1isNULL, it estimates the AR(1) coefficient viaarima(), which is the same way thewtccomputes it for the significance test in that function. The code will do what you want if you just ignorelag1and let it compute the coefs for you internally.