Computing the chi-squared value