code for covariance estimate