critical! correction to stat_with_uncertainty. Also moved helper functions outside of analyze_fogrun() for use by other scripts