I'm trying to perform generalized least-squares fitting of highly correlated data. The covariance matrix for these data is large, with many elements close to 1.
# X and Y correspond to my predictor and dependent variables
# C is the covariance matrix of Y
# BF are the best-fit parameters
# BFCM is the covariance matrix of BF
from pylab import *
BF = inv(X.T @ inv(C) @ X) @ (X.T @ inv(C) @ Y)
BFCM = inv(X.T @ inv(C) @ X)
I'm getting negative diagonal terms in the correlation matrix of the best-fit parameters (BFCM
), which is definitely wrong. It seems likely that these negative values come from the limited float
precision used by numpy.linalg
. Is there a way to avoid such floating point precision problems in this case?
Thanks for any suggestions.