# Compare two time-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)


• Welcome to StackOverflow! Please read the info about how to ask a good question and how to give a reproducible example . This will make it much easier for others to help you.
– Jaap
Dec 1, 2016 at 7:32
• Adding to the above: this question appears to be more about statistics and thus better belongs on Cross Validated. If you wait a while, we will migrate it for you.
– Jaap
Dec 1, 2016 at 7:35
• Feed us with some of that R you coded!
– nicovank
Dec 1, 2016 at 7:36
• @ProcrastinatusMaximus I apologize if I posted in the wrong section. I'm really still very new and slightly confused with the overall forum. However, this is both a statistics and programming question.
– Anke
Dec 1, 2016 at 7:48
• @nicovank: Of course. I've added the code to my original post. But it's really very basic.
– Anke
Dec 1, 2016 at 7:55

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.