error_stats function

Calculate common error statistics