recoded binned residual function to make it robust to instances where there are many identical fitted values