Calculate a sum of squares