Calculating h2 and extracting residuals