Reworked version of PR-3084 (mstats-stats comparison)

Rebase of gh-3084, fixing lots of style issues that that PR introduced and a few bugs. The ``kurtosistest`` bug was already present. The bug fixes from gh-3084 left over in this PR look OK; there are some loose ends that can wait till later.