Take the 2-minute tour ×
MathOverflow is a question and answer site for professional mathematicians. It's 100% free, no registration required.

What is the best algorithm for computing covariance that would be accurate for a large number of values like 100,000 or more?

share|improve this question
    
One quick note. I know some people will think this is basic but I have looked in a lot of places (numerical analysis texts, computational statistics texts and google scholar) and I've never seen it discussed. Doing the straightforward thing does not work for large datasets. –  Kim Greene Nov 18 '09 at 20:26
add comment

2 Answers 2

up vote 5 down vote accepted

Check out How to calculate correlation accurately. There are two common formulas that are algebraically equivalent but one has much better numerical properties than the other.

share|improve this answer
1  
Yes, but that is only a partial answer. The problem is that the “good” formula requires two passes over the data, one to compute the arithmetic means and one to compute the quadratic sums. It would be very handy to have an algorithm that uses only a single pass, yet is numerically stable. Surely, someone must have thought of one? It doesn't seem to me an intractable problem. –  Harald Hanche-Olsen Nov 18 '09 at 21:53
1  
Here's a way to compute standard deviation in one pass. I imagine you could take the ideas from this algorithm to create an accurate single-pass algorithm for covariance. johndcook.com/standard_deviation.html –  John D. Cook Nov 19 '09 at 0:17
add comment

The single-pass and parallel versions at Wikipedia may be what you're looking for. The single pass version is more numerically stable, but moves a division into the inner loop, which may hurt performance.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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