Summary of whuber's [answer][1] with J. M's comment with another example data of 3x2 matrix about data = {{58, 35}, {11, 25}, {10, 23}}; rc = {{"agree", "neutral", "disgaree"}, {"men", "women"}}; TableForm[data, TableHeadings -> rc] fit = Outer[Times, Total[data, {2}], Total[data]]/Total[data, 2]; TableForm[fit // N, TableHeadings -> rc] residual = data - fit; TableForm[residual // N, TableHeadings -> rc] \[Chi]2array = residual^2/fit; TableForm[\[Chi]2array // N, TableHeadings -> rc] \[Chi]2 = Total[\[Chi]2array, 2]; \[Chi]2 // N df = (Times @@ # - Total[#] + 1) &[Dimensions[data]]; 1 - CDF[ChiSquareDistribution[df], \[Chi]2] // N [1]: https://mathematica.stackexchange.com/a/5285/9815