6
$\begingroup$

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

$\endgroup$
6
  • $\begingroup$ 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. $\endgroup$
    – Jaap
    Commented Dec 1, 2016 at 7:32
  • $\begingroup$ 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. $\endgroup$
    – Jaap
    Commented Dec 1, 2016 at 7:35
  • 2
    $\begingroup$ Feed us with some of that R you coded! $\endgroup$
    – nicovank
    Commented Dec 1, 2016 at 7:36
  • 1
    $\begingroup$ @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. $\endgroup$
    – Anke
    Commented Dec 1, 2016 at 7:48
  • $\begingroup$ @nicovank: Of course. I've added the code to my original post. But it's really very basic. $\endgroup$
    – Anke
    Commented Dec 1, 2016 at 7:55

1 Answer 1

4
$\begingroup$

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.

$\endgroup$
1
  • 7
    $\begingroup$ Would you mind adding some code to your answer to show how to use the package for such analysis? $\endgroup$
    – user45065
    Commented Dec 1, 2016 at 10:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.