How to calculate sums of squares