0

I am using TSclust package for SAX (symbolic aggregate aggregation) plots. In accordance to example shown on page 25, I am using the function

SAX.plot(as.ts(df$power), w=30, alpha=4) 

But, it generates error as:

Error in if ((n <- as.integer(n[1L])) > 0) { : argument is of length zero

I am not able to debug it. Even I looked into the source code of SAX.plot function but I do not find the relevant error message typed in.

The required R dataobject can be found at link

R version: 3.2
TSclust version:1.2.3

www
  • 38,575
  • 12
  • 48
  • 84
Haroon Lone
  • 2,837
  • 5
  • 29
  • 65

1 Answers1

2

Hello apparently it's because you need to normalize your data, check out this example :

# Parameters
w <- 30 
alpha <- 4 

# PAA
x <- df$power
paax <- PAA(x, w) 
plot(x, type="l", main="PAA reduction of series x") 
p <- rep(paax,each=length(x)/length(paax)) #just for plotting the PAA
lines(p, col="red")

# SAX
convert.to.SAX.symbol(paax , alpha)
# [1] 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
# You need to scale PAA result
convert.to.SAX.symbol(scale(paax) , alpha)
# [1] 1 1 1 1 1 1 1 1 1 2 2 1 4 3 3 1 2 2 2 4 4 4 1 1 2 4 3 3 4 4


# SAX plot : with scaling this works
SAX.plot(as.ts(scale(df$power)), w=w, alpha=alpha) 

That's likely the example you can found in the function help page.

Victorp
  • 13,636
  • 2
  • 51
  • 55
  • thanks. One small curious question: How did you find that non-normalized data are causing problems. – Haroon Lone Oct 10 '15 at 13:28
  • 1
    You're welcome! I just checked the steps in `SAX.plot` function and repeat these manually and saw the problem in `convert.to.SAX.symbol` when you don't scale your data. – Victorp Oct 10 '15 at 14:39