Can anyone help me to know why am I getting "Error in seq.default(1, NROW(phases), round(NROW(phases)/30)) : invalid (to - from)/by in seq(.)" After running this code?

wtc.U2U1=wtc(U2, U1, nrands=1500)
# Plot wavelet coherence and phase difference (arrows)
# Make room to the right for the color bar
par(oma=c(0, 0, 0, 1), mar=c(5, 4, 4, 5) +0.1)
plot(wtc.U2U1, plot.phase =TRUE,lty.coi = 1,col.coi = "grey",lwd.coi = 2,
     lwd.sig = 2,arrow.lwd = 0.03,arrow.len = 0.12,ylab = "scale",xlab = "period",
     plot.cb = TRUE,main="wavelet coherence:Kenya vs Burundi")

Hi @Mugenzi123! Welcome!

Although it involves a different package, I think this problem is similar to the one reported over here:

Here's an adaptation of my answer from over there to this specific case:

Narrowly, that’s an error from the seq() function (here is its documentation). It has been called with the following parameters:

  • from = 1
  • to = NROW(phases)
  • by = round(NROW(phases) / 30))

seq() produces regular sequences of numbers. When calling it with these arguments, it tries to produce a sequence from 1 to NROW(phases), with an increment of round(NROW(phases) / 30)) — so (NROW(phases) - 1) / round(NROW(phases) / 30)) needs to be a number that makes sense. The error message is saying that this is not the case.

Broadly, you didn’t call this function yourself. It appears to be part of the internal operations of biwavelet (specifically, the phase.plot() function). So understanding this specific error isn’t that helpful. Something is wrong further upstream that is causing this part of biwavelet’s code to get called with invalid values for either NROW(phases) or round(NROW(phases) / 30)).

Does it shed any light to examine the matrix of phases directly with wtc.U2U1$phases? What values do you get for NROW(wtc.U2U1$phases) and round(NROW(wtc.U2U1$phases) / 30))?

I’m afraid I don’t know enough about this package to get much further than that. Maybe someone else with more experience with it will stop by! Otherwise, if you’ve consulted the documentation and compared it to your code to check for mistakes in how you’re using these functions and you’re still getting the error, you might try posting a question to the GitHub issues tracker for this package: https://github.com/tgouhier/biwavelet/issues