CHANGE: corrected  chi-square statistics calculation