Added utility function to compute within-sample correlations