fix bug in computing expected counts in the formula