Numerical algorithms and statistical theory is quite robust and universal, but once you look into the various software implementations you discover that presumed standards are not so universal. That’s indeed the great thing about ‘standards’, there are so many to choose from.

Having spent quite a bit of time looking into \chi^2-tests and ways to filter out noise from big data, I discovered that the so-called Pearson p-value is somewhat different in Excel, Mathematica and R. Sometimes the difference is subtle (of the order of 1E-10) sometimes not so insignificant. The reason I want to highlight it here is because it took me a whole lot of time to figure things out and hope these notes will help someone out there. Aside from the technical bit I also have to confess that I was amazed at the sharpness with which the test allowed us to distinguish noise from signal, but I’m too much bound to confidentiality to reveal more.

Consider the couple of vectors (46,44) and (50,50) and test for correlation, typically in R you would do something like the following

producing a p-value of 0.9939 while in Excel or Mac’s Numbers you get

Numbers Chi

while in Mathematica you (to my surprise) need to implement it yourself like so

The reason for the discrepancy is that R has a somewhat different implementation which takes also the Yates correction into account;

If you wish to have the same value in R as in spreadsheet programs and Mathematica you need to use

which seems obvious when you look at it but, like many things in numerical maths, the assumption that all packages create correct outputs depends on large sets of assumptions (about your model, distribution, validity domain and whatnot).