Calculating the correlation matrices