US Trade Deficits: A Change Point Analysis  

While I was researching on ‘outlier detection’ techniques last week, I stumbled upon this well explained article on Change Point analysis.

Change Point analysis can be used to detect extreme/subtle changes in a time series and I decided to try writing the algorithm in R, starting with the case of Single Change Point Detection, before jumping onto the general case of multiple.

I borrowed the following data from here:

table_2.png

Following the article’s method, the function would primarily have three parts:

  1. Calculating the cumulative sums(CUSUM)
  2. Bootstrapping, to confirm a change
  3. Using the CUSUM Estimator to detect when the change occured

Here’s the R function:
code.png

The below image shows output from the first part of the function i.e. calculating the cumulative sums, as a grey line overlayed on the orange line which depicts the original time series of trade deficits.

New1_2.png

Moving right along, the output of the second part of the function is summarized in the following histogram, which shows that all of the 1000 samples have the Sdiff(Smax-Smin) value below that for the original time series, thus indicating there indeed is a change happening. Bingo!

hist.png

Now, time to look at the output from the third part of the function, the CUSUM Estimator. Here is the output thrown at the console:

output.png

Yes. Change Point detected! And I just made some more progress with R! :)

Sanket

 
9
Kudos
 
9
Kudos

Now read this

Normalization of data

In this post, I will cover two of the most popular techniques for normalization of data. Normalization is a very important data pre-processing step for improving performance of many machine learning algorithms. For this purpose we will... Continue →