Archive for August, 2009

0.8.6 supports PostgreSQL and has better output formatting

Monday, August 24th, 2009

New features:

  • Added support for PostgreSQL databases.
  • Each item of output now has a preceding display line and a description of its data source (database and table) and when it was created.
  • Improved layout of exported scripts.
  • Added unit tests for main statistical algorithms used.
  • Better handling of timestamp and autonumber fields in data entry/editing.

Bug fixes:

  • Fixed script export bug.

Additionally, the Windows package now installs a menu shortcut for uninstallation. It always should have, of course, but the latter is still an example of a little thing which makes newer versions of SOFA Statistics nicer to use. The idea is that, collectively, thousands of details like that will create a sense of polish. The Ubuntu 100 papercuts project is one inspiration.

wxWebKit will enable graphing when it is packaged

Friday, August 21st, 2009

wxWebKit ( is a very important widget for the SOFA Statistics project as it will be used to display all output. At present, the only debian package for wxWebKit (kindly supplied by Christoph Willing) does not support the display of local images. Fortunately this is being rectified through the hard work of Kevin Ollivier, and a new package should be out sometime soon. This is expected to be a standard package which should simplify the installation instructions for Ubuntu users.

Once the wxWebKit package is available, a lot of development work will take place in SOFA Statistics to provide auxiliary graphs which support analysis e.g. by displaying the data distributions in the samples used for an ANOVA. It will finally be possible to really start delivering on the “learn-as-you-go” promise of SOFA Statistics.

Testing the statistical algorithms

Friday, August 21st, 2009

A statistical program has to produce accurate results reliably. And it has to keep doing so even when some aspects of the program change between versions. Seemingly trivial or non-consequential programming changes can have an enormous impact on the final result produced. So the only way to have confidence in a program is through automated testing. In many cases, it is also possible to test against a standard dataset with a guaranteed, known result (e.g.

The one-way ANOVA has passed the most difficult NIST test when using the default “precision” setting (as opposed to speed, which relies on floating point maths).

Additionally, the ANOVA, and all the other tests, are now tested using a number of carefully crafted Python functions and a simple program called NOSE ( The tests can feed hundreds of random samples of data into each SOFA Statistics algorithm and check the output against a trusted algorithm e.g. from SciPy.

Of course, randomness is not enough to test an algorithm. It is necessary to also feed in cases where some values are very high, very close to zero, or very similar to other values. The specific approach necessary to separate out the weak algorithms depends on the particular test. The NIST ANOVA datasets, for example, include lots of values with the same leading digits and the only difference occurring after the decimal point. A deliberate approach to testing increases the odds of exposing errors.

In the open source world there is no need to take anyone’s word for it. The test script, and all the algorithms for SOFA Statistics, are open source (, and any developers or statisticians who can extend or otherwise improve the tests are welcome to do so. That’s the open source way. So if you think of something that could help strengthen SOFA Statistics or its testing, please feel free to contact me.

As part of the testing just completed, a couple of small bugs were detected and these will be corrected in the next release coming soon.

wxPython hourglass cursor not working in Ubuntu

Monday, August 17th, 2009

The following code worked in Windows but not in Ubuntu:

# hourglass cursor

curs = wx.StockCursor(wx.CURSOR_WAIT)
Something happens that takes a while … … … …
# Return to normal cursor
curs = wx.StockCursor(wx.CURSOR_ARROW)

Use instead:


NB good to use wx.IsBusy() with EndBusyCursor().  On Windows, ending a cursor if one is not running causes an error.

if wx.IsBusy():

Misc library issues

Monday, August 17th, 2009

Re: pysqlite-2.5.5-win32-py2.6.exe – it wouldn’t install on my clean virtual XP environment.  It was unable to locate the component msvcr71.dll. So I was forced to include that in the Windows package.

The mysqldb module doesn’t currently have an official 2.6 version of the Windows installer.  Which was the main reason I had kept the Windows version to Python 2.5 for which there was one  (SciPy was no longer relevant so shifting to 2.6 for all installers was definitely in contention).  And there had been mixed experience of mysqldb packages put together by third parties (  But I really needed a feature which was introduced in Python 2.6 – namely the float method as_integer_ratio.  This was needed to enable my float to decimal function to work ( which I needed to get the level of precision required to pass the hardest NIST ANOVA test ( In the end I went with  Another option was

BTW there is a lot to like about Python 2.6 – it is the gateway to the 3 series and will make that eventual transition a lot easier.

0.8.5 has stronger ANOVA support and can output in multiple styles

Monday, August 17th, 2009

Version 0.8.5 has the following new features:

  • The one-way ANOVA now presents the user with a choice of either precision or speed. Precision passes the hardest NIST test ( and is the default.  The speed option uses standard floating point arithmetic with all the pros and cons that entails.
  • ANOVA displays more information in output to enable comparison with known results.
  • HTML output can now display multiple styles for different tables.
  • Importing now requires alphanumeric names for tables.

and the following main bug fixes:

  • Importing CSV files is now working (regression added in 0.8.4).
  • CSV files with multiple data types in columns are handled correctly when user opts to let SOFA Statistics fix a column type.
  • Kruskal Wallis H test now copes with string variables.

The decimal module in Python

Wednesday, August 12th, 2009

Python has a brilliant decimal module ( you may need if you want to avoid floating point errors.  This may be necessary if you are faced with compounding errors under special circumstances e.g. if testing a statistical routine against a purpose-built test dataset (e.g.  The performance hit is substantial, however, so it has to be used judiciously.  Anyway, here is an example:

import decimal
D = decimal.Decimal
decimal.getcontext().prec = 120
d1 = D("1.1")
f1 = 1.1
print "Decimal result is: %s" % round((d1**1000 - D("2.46993291801e+41")),3)
print "Floating point result is: %s" % round((f1**1000 - 2.46993291801e+41),3)

Decimal result is: -4.17366587591e+29
Floating point result is: -3.97456123863e+29

Usually, floating point is good enough – but not under all circumstances.  In which case, it pays to be familiar with the decimal module.