new file for binned residuals code and general DGAM function