views:

1444

answers:

3

Are there any c (or c++) libraries out there that can take an array of numbers and do basic statistical analysis on it (mean, median, mode, whatever else might be interesting)?

+1  A: 

There's Apophenia. I haven't used it myself. Do you really want it to be C-callable? The R environment gives you pretty much everything, and a bag of chips.

Charlie Martin
+1  A: 

If you're looking to do more advanced analysis, there are some nice libraries out there like GSL, TNT, Blitz++, VxL, and various Boost libraries. Most of these are fairly heavyweight libraries that are more complex than a few simple functions, but they're also far more powerful.

If you need to do a lot of statistical processing, you might consider a language that's more tuned to it like R, Matlab, SciPy for Python, etc.

Mr Fooz
Doing all of these naively with your own code is not necessarily going to be numerically stable. For example, your mean function loses precision in certain cases. Does he really want to debug that? Use GSL or some other decent library and you get numerically stable algorithms.
tgamblin
Good point...answer modified.
Mr Fooz
+3  A: 

GNU Scientific Library (GSL) provides the functionality. Apophenia mentioned by another appears to provide a layer on top of GSL. Something to bear in mind with GSL is that it is frequently a slow implementation of many functions. For instance, its mean calculations perform division inside the loop to ensure best possible precision of the result. In many applications thus cost is not worth the precision.

SetJmp