add function to calculate chi2