Tuesday, October 25, 2011

Cointegrated drunk and her dog visualized

Chart: Drunk and Her Dog

I was reading today an article about cointegration, written by Michael P. Murray. It describes a case of a random walking drunk accompanied by an unleashed dog. Occasionally the dog barks or the drunk calls the dog, and they try to get a little closer to each other based on the sounds.

I thought it may be interesting to visualize the process. You can see the result above :)

The drunk and her dog start at the position [0,0]. Their final positions (in this case after 100,000 moves by each) are indicated by the crossings of the green - for the drunk - and blue - for the dog - lines.

There are three parameters to set: the number of steps, the frequency of either dog barking or the drunk calling the dog, and the efficiency of the correction mechanism, i.e. how much they can reduce distance between themselves on each occasion they try to get closer, and how precisely they can set the course toward each other (the angel).

Although trajectories of both the drunk and the dog follow the random walk:

They are highly correlated:

> cor(drunk_path[,1],dog_path[,1])
[1] 0.9951132
> cor(drunk_path[,2],dog_path[,2])
[1] 0.9937595

And the distance between them is a stationary process:

> mean(distance);sd(distance)
[1] 8.948513
[1] 6.242085

You can decrease the correlation of the cointegrated processes by manipulating the frequency of error correction and precision of the correction mechanism - see parameters mentioned above.

1 comment:

Johnson said...

It is a remarkable website and great percentage. I want to thanks. proper process! You men do a super excellent blog, and feature a few first rate contents. preserve up the good work. Black Friday Amazon