Wavemulcor package - wave.multiple.cross.correlation function - replacement has a length of zero

I would like to use the wavemulcor package and, in particular, the wave.multiple.cross.correlation function to perform multiple correlation of wavelet data on my data.

I follow the example according to the package guide, but use my data instead. The function works with the sample data, but throws an error when I try to use it. The error refers to "replacement is zero length", but I'm not sure what that means.

I searched for a Google bug, but there are many examples of the same problem for different functions, and, as a rule, they all have something to do with loops in the code.

Then I looked for a troubleshooting problem and read about debugging. I tried to debug the code, but I can’t understand where it breaks, I’m still in the early stages of learning the code. I think it could be this section of code in the wave.multiple.cross.correlation function, which is causing the problem:

xy.cor.vec <- matrix(unlist(xy.cor), l, dd)
    xy.mulcor <- matrix(0, l, 2 * lm + 1)
    YmaxR <- vector("numeric", l)
    for (i in 1:l) {
        r <- xy.cor.vec[i, ]
        P <- diag(d)/2
        P[lower.tri(P)] <- r
        P <- P + t(P)
        Pidiag <- diag(solve(P))
        if (is.null(ymaxr)) {
            YmaxR[i] <- Pimax <- which.max(Pidiag)
        }

Are there other ways to determine why this is not working?

The actual error is as follows:

> Lst <- wave.multiple.cross.correlation(xx, lag.max = NULL, ymaxr = NULL)
Error in YmaxR[i] <- Pimax <- which.max(Pidiag) : 
  replacement has length zero

I tried to trace all the variables in the source code, but I just can't figure it out.

This is the code I'm trying to use and for completeness, here is a link to dput () xx, which is a list of variables that I want to use, see the code below for information about xx

library(wavemulcor)
library(readxl)

rm(list = ls()) # clear objects
graphics.off() # close graphics windows

RNC20_30Hourly <- read_excel(RNC20_30Hourly.xlsx")

RNC20_30Hourly <- RNC20_30Hourly[-1]

RNC20_30TS <- ts(RNC20_30Hourly, start = 1, frequency = 23)

wf <- "d4"
J <- 6
lmax <- 36

n <- nrow(RNC20_30TS)

CK0158U09A3.modwt <- modwt(RNC20_30TS[,"CK0158U09A3"], wf, J)
CK0158U09A3.modwt.bw <- brick.wall(CK0158U09A3.modwt, wf)

CK0158U21A1.modwt <- modwt(RNC20_30TS[,"CK0158U21A1"], wf, J)
CK0158U21A1.modwt.bw <- brick.wall(CK0158U21A1.modwt, wf)

CK0158U21A2.modwt <- modwt(RNC20_30TS[,"CK0158U21A2"], wf, J)
CK0158U21A2.modwt.bw <- brick.wall(CK0158U21A2.modwt, wf)

CK0158U21A3.modwt <- modwt(RNC20_30TS[,"CK0158U21A3"], wf, J)
CK0158U21A3.modwt.bw <- brick.wall(CK0158U21A3.modwt, wf)

xx <- list(CK0158U09A3.modwt.bw, 
           CK0158U21A1.modwt.bw, 
           CK0158U21A2.modwt.bw,
           CK0158U21A3.modwt.bw)

Lst <- wave.multiple.cross.correlation(xx, lag.max = 13, ymaxr = NULL)

CK0158.RTWP.cross.cor <- as.matrix(Lst$xy.mulcor[1:J,])
YmaxR <- Lst$YmaxR

cell.names <- c("CK0158U09A3", "CK0158U21A1", "CK0158U21A2", "CK0158U21A3")
rownames(CK0158.RTWP.cross.cor)<-rownames(CK0158.RTWP.cross.cor,
                                          do.NULL = FALSE, prefix = "Level ")
lags <- length(-lmax:lmax)

lower.ci <- tanh(atanh(CK0158.RTWP.cross.cor) - qnorm(0.975) /
                   sqrt(matrix(trunc(n/2^(1:J)), nrow=J, ncol=lags)- 3))
upper.ci <- tanh(atanh(CK0158.RTWP.cross.cor) + qnorm(0.975) /
                   sqrt(matrix(trunc(n/2^(1:J)), nrow=J, ncol=lags)- 3))

par(mfrow=c(3,2), las=1, pty="m", mar=c(2,3,1,0)+.1, oma=c(1.2,1.2,0,0))
for(i in J:1) {
  matplot((1:(2*lmax+1)),CK0158.RTWP.cross.cor[i,], type="l", lty=1, ylim=c(-1,1),
          xaxt="n", xlab="", ylab="", main=rownames(CK0158.RTWP.cross.cor)[[i]][1])
  if(i<3) {axis(side=1, at=seq(1, 2*lmax+1, by=12),
                labels=seq(-lmax, lmax, by=12))}
  #axis(side=2, at=c(-.2, 0, .5, 1))
  lines(lower.ci[i,], lty=1, col=2) ##Add Connected Line Segments to a Plot
  lines(upper.ci[i,], lty=1, col=2)
  abline(h=0,v=lmax+1) ##Add Straight horiz and vert Lines to a Plot
  text(1,1, labels=cell.names[YmaxR[i]], adj=0.25, cex=.8)
}
par(las=0)
mtext('Lag (hours)', side=1, outer=TRUE, adj=0.5)
mtext('Wavelet Multiple Cross-Correlation', side=2, outer=TRUE, adj=0.5)

Any help in solving / fixing this problem would be greatly appreciated.

+4
1

, . , :

wave.multiple.cross.correlation(xx, lag.max = NULL, ymaxr = NULL)

lmax, .

Lst <- wave.multiple.cross.correlation(xx, lmax)

, , lmax = 36 lag.max = 13

, 100 !

+2

Source: https://habr.com/ru/post/1681834/


All Articles