**Portfolio Probe » R language**, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)

Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

*Fringe *provides an excellent example of cointegration. This is a television show in which there are two adjacent universes. The universes are almost alike but not exactly.

Now, everyone knows that history is chaotic. If a butterfly does an extra flap of its wings, then that difference spreads out to change subsequent events everywhere. But the *Fringe* universes stay largely in step. Decades ago a building was built in one universe, but not the other; a company was founded in one, but not the other. Yet the universes are not diverging.

That’s cointegration.

I’m doubtful that Clive Granger and colleagues invented cointegration to help out the science fiction industry. More likely they saw either something in the economic world that the mathematics couldn’t handle, or a hole in the mathematics. They may or may not have had thoughts of a Nobel prize (achieved, 2003). Hitting mainstream culture would have been just a pipe dream.

## An economic example

Take the case of a company that has two classes of shares — common and preferred, say. The price histories of those share classes are going to be cointegrated.

The shares are essentially the same except for voting rights and perhaps a few other details. Their prices are going to move together. Not exactly together: there will be differences due to large trades and other random events. But if the prices drift too far apart, then someone is going to take advantage of that discrepancy.

**More technical explanation:** Two time series are cointegrated if each is not stationary (and hence “integrated”), but there is a linear combination of them that is stationary.

In our example, the difference in prices will be a stationary series.

## R implementation

Packages that include functions related to cointegration include:

`vars``urca``tsDyn``tseries`

There are additional packages that contain tests for cointegration. I’m unaware of any additional packages that are more useful in terms of cointegration than that. Please correct me if I’ve missed anything.

Bernhard Pfaff has a book: Analysis of Integrated and Cointegrated Time Series with R.

## Epilogue

My wife is quietly amused that she has got me to watch a science fiction show. She hooked me with Walter, the scientist. The science that he does — as far as I can tell — is complete nonsense. (I think that’s why they call it science fiction.) However, Walter is the picture of a real scientist.

**leave a comment**for the author, please follow the link and comment on their blog:

**Portfolio Probe » R language**.

R-bloggers.com offers

**daily e-mail updates**about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.

Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.