-1

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
Yang Yang
  • 858
  • 3
  • 26
  • 49

2 Answers2

2

There seems to be a bug in wtc. It passes off lag1 to the wt function to compute the wavelet transform of each series separately, but does so without subsetting lag1, 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 for lag1.

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 wtc top level if the user didn't supply them, and subset the lag1 vector if the user does supply them.

I suggest you contact the maintainer to mention the problem.

In the meantime, just don't bother computing lag1 initially; inside wt.sig, which is called by wtc -> wt, if lag1 is NULL, it estimates the AR(1) coefficient via arima(), which is the same way the wtc computes it for the significance test in that function. The code will do what you want if you just ignore lag1 and let it compute the coefs for you internally.

Gavin Simpson
  • 170,508
  • 25
  • 396
  • 453
  • Thank you for your reply. I will try to contact the maintainer. And for now, I will just ignore the lag1. Thanks. – Yang Yang Jul 11 '16 at 17:09
0

You do not have to estimate the AR(1) coefficient prior to calling the wtc function as this is done internally. However, if you insist on computing the coefficients and supplying them to wtc, the latest version of biwavelet (0.20.9) available on GitHub fixes the warning issue and also implements Gavin's suggestion to improve efficiency (i.e., it doesn't compute the coefficients if they're already provided by the user). Thanks to you both for pointing out the issue...

Tarik
  • 11
  • 1