double totalSum = 0;
double totalSumSquared = 0;
// sum and sum of squares
for (int i = 0; i < data.size(); i++) {
Instance instance = data.get(i);
int value = (int) instance.get(attr);
double label = data.getDataset().getLabel(instance);
double square = label * label;
sums[value] += label;
sumSquared[value] += square;