Solved – Compare two time-series

rtime series

I have two time-series from two different years and would like to statistically test whether they are different in values despite showing the same/similar trends. I'm really new to time-series analysis (and R), so please bear with me. So far, all I've done is create the actual time-series from my data and applied a simple moving average (with n=10).

I've already searched and googled, but all I really can find are prediction models, but that's not really what I'm interested in. I'm more interested in a statistical test comparing the two (e.g. binned by month), however I'm not sure what the appropriate approach and test are.

Here is some of the code:

    k<-read.csv("~/Desktop/k.csv")
    k14<-k[,2]
    k14f<-na.fill(k14,"extend")
    k14ts<-ts(k14f, frequency=365, start=c(2014,305))
    k14tsSMA10<-SMA(k14ts, n=10)
    k15<-[,3]
    k15f<-na.fill(k15,"extend")
    k15ts<-ts(k15f, frequency=365, start=c(2015,305))
    k15tsSMA10<-SMA(k15ts, n=10)
    kSMA<-cbind(k14tsSMA10, k15tsSMA10)
    ts.plot(kSMA)

The two time-series plotted

Best Answer

You can use the Dynamic Time Warping (DTW) that is a good algorithm to find the similarity between two time series since it find the match between the time series that minimize the alignment cost. It's really easy to use and it has a lot of different variations that allow you to set (for example) local weights or just apply it to a subsequence of a time series. If you need for an R package that is ready for the use, I would suggest you to import TSdist and here you can find the documentation.