R dtw package: query and reference vectors for binary data to pass it to dtw function

165 Views Asked by At

I have two time series tables that look like this.

enter image description here

I calculated the binary column to count for specific categorical value, if this value = “x” then assign 1, else assign 0. I graphed this using ggplot like this,

 p <-ggplot(x1,aes(Time, binary))
 p + geom_line()+ 
 xlab("Time in seconds (s)")+
 scale_y_continuous(name="x = 1, anything else = 0", breaks=c(0, 1))+
 labs(title = "Example of the duration")

I got exactly what I wanted,

enter image description here

I did the same for the second time series and I got this graph, enter image description here

Now it is time to use dtw function to calculate the distance. I am not sure how to store this binary data into carry or matrix to pass it through dtw function here,

dtw(
  x,
  y = NULL,
  dist.method = "Euclidean",
  step.pattern = symmetric2,
  window.type = "none",
  keep.internals = FALSE,
  distance.only = FALSE,
  open.end = FALSE,
  open.begin = FALSE,
  ...
)

where x is the query vector or local cost matrix and y is reference vector, or NULL if x given as a local cost matrix

What I did is this,

i<-c(x1$binary)
j<-c(x2$binary)
dtw1 <-dtw(i, j, dist.method="Euclidean", keep.internals = T, step.pattern= symmetric)
plot(dtw1)

But this is not correct. The graphs for each one is not the same as shown below. The matrix cost is null. It only calculates the number of 0,1 of each column. I know this is not correct, but I don’t know how to get the query and reference vectors to calculate the dtw. How to apply that for this binary data? enter image description here

1

There are 1 best solutions below

0
On

What I did is this, instead of assigning the binary values to the dtw function, I used time.

i<-c(x1$Time)
j<-c(x2$Time)
dtw1 <-dtw(i, j, dist.method="Euclidean", keep.internals = T, step.pattern= asymmetric)
plot(dtw1)