R code for assessing model quality