Skip to main content
added 373 characters in body
Source Link
Glen_b
  • 290.5k
  • 37
  • 652
  • 1.1k

ButThe same should generally apply to covariance matrices of complete samples (no missing values), since they can also be seen as a form of discrete population covariance.

However due to inexactness of floating point numerical computations, even algebraically positive definite cases might occasionally be computed to not be even positive semi-definite; good choice of algorithms can help with this.

Sample More generally, sample covariance matrices - depending on how they deal with missing values in some variables - may or may not be positive semi-definite, even in theory. If pairwise deletion is used, for example, then there's no guarantee of positive semi-definiteness. Further, accumulated numerical error can cause sample covariance matrices that should be notionally positive semi-definite to fail to be.

This happened on the first example I tried (I probably should supply a seed but it's not so rare that you should have to try a lot of examples before you get one).

But due to inexactness of floating point numerical computations, even algebraically positive definite cases might occasionally be computed to not be even positive semi-definite; good choice of algorithms can help with this.

Sample covariance matrices - depending on how they deal with missing values in some variables - may or may not be positive semi-definite. If pairwise deletion is used, for example, then there's no guarantee of positive semi-definiteness. Further, accumulated numerical error can cause sample covariance matrices that should be notionally positive semi-definite to fail to be.

The same should generally apply to covariance matrices of complete samples (no missing values), since they can also be seen as a form of discrete population covariance.

However due to inexactness of floating point numerical computations, even algebraically positive definite cases might occasionally be computed to not be even positive semi-definite; good choice of algorithms can help with this.

More generally, sample covariance matrices - depending on how they deal with missing values in some variables - may or may not be positive semi-definite, even in theory. If pairwise deletion is used, for example, then there's no guarantee of positive semi-definiteness. Further, accumulated numerical error can cause sample covariance matrices that should be notionally positive semi-definite to fail to be.

This happened on the first example I tried (I probably should supply a seed but it's not so rare that you should have to try a lot of examples before you get one).

added 229 characters in body
Source Link
Glen_b
  • 290.5k
  • 37
  • 652
  • 1.1k

But due to inexactness of floating point numerical computations, even algebraically positive definite cases might occasionally be computed to not be even positive semi-definite; good choice of algorithms can help with this.

Sample covariance matrices - depending on how they deal with missing values in some variables - may or may not be positive semi-definite. If pairwise deletion is used, for example, then there's no guarantee of positive semi-definiteness. Further, accumulated numerical error can cause sample covariance matrices that should be notionally positive semi-definite to fail to be.

Sample covariance matrices - depending on how they deal with missing values in some variables - may or may not be positive semi-definite. If pairwise deletion is used, for example, then there's no guarantee of positive semi-definiteness. Further, accumulated numerical error can cause sample covariance matrices that should be notionally positive semi-definite to fail to be.

But due to inexactness of floating point numerical computations, even algebraically positive definite cases might occasionally be computed to not be even positive semi-definite; good choice of algorithms can help with this.

Sample covariance matrices - depending on how they deal with missing values in some variables - may or may not be positive semi-definite. If pairwise deletion is used, for example, then there's no guarantee of positive semi-definiteness. Further, accumulated numerical error can cause sample covariance matrices that should be notionally positive semi-definite to fail to be.

added 4 characters in body
Source Link
Glen_b
  • 290.5k
  • 37
  • 652
  • 1.1k
 z <- x + y + rnorm(30)/50  # same x and y as before.
 xyz1 <- data.frame(x=x,y=y,z=z) # high correlation but definitely of full rank 

xyz1$x[sample(1:30,5)] xyz1$x[sample(1:30,5)]<-NA   # make 5 x's missing
 xyz1$y[sample<- NA   # make 5 x's missing  

xyz1$y[sample(1:30,5)]<] <- NA   # make 5 y's missing
    

xyz1$z[sample(1:30,5)]<] <- NA   # make 5 z's missing
    

cov(xyz1,use="pairwise")     # the individual pairwise correlationscovars are fine ... 

           x          y        z
x  1.2107760 -0.2552947 1.255868
y -0.2552947  1.2728156 1.037446
z  1.2558683  1.0374456 2.367978 

 chol(cov(xyz1,use="pairwise"))  # ... but leave the matrix not positive semi-definite 

Error in chol.default(cov(xyz1, use = "pairwise")) : 
  the leading minor of order 3 is not positive definite

 chol(cov(xyz1,use="complete")) # but deleting even more rows leaves it PSD 

          x          y          z
x 0.8760209 -0.2253484 0.64303448
y 0.0000000  1.1088741 1.11270078
z 0.0000000  0.0000000 0.01345364
 z <- x + y + rnorm(30)/50  # same x and y as before.
 xyz1 <- data.frame(x=x,y=y,z=z) # high correlation but definitely of full rank
 xyz1$x[sample(1:30,5)]<-NA   # make 5 x's missing
 xyz1$y[sample(1:30,5)]<-NA   # make 5 y's missing
  xyz1$z[sample(1:30,5)]<-NA   # make 5 z's missing
  cov(xyz1,use="pairwise")     # the individual pairwise correlations are fine ...
           x          y        z
x  1.2107760 -0.2552947 1.255868
y -0.2552947  1.2728156 1.037446
z  1.2558683  1.0374456 2.367978
 chol(cov(xyz1,use="pairwise"))  # ... but leave the matrix not positive semi-definite
Error in chol.default(cov(xyz1, use = "pairwise")) : 
  the leading minor of order 3 is not positive definite

 chol(cov(xyz1,use="complete")) # but deleting even more rows leaves it PSD
          x          y          z
x 0.8760209 -0.2253484 0.64303448
y 0.0000000  1.1088741 1.11270078
z 0.0000000  0.0000000 0.01345364
z <- x + y + rnorm(30)/50  # same x and y as before.
xyz1 <- data.frame(x=x,y=y,z=z) # high correlation but definitely of full rank 

xyz1$x[sample(1:30,5)] <- NA   # make 5 x's missing  

xyz1$y[sample(1:30,5)] <- NA   # make 5 y's missing   

xyz1$z[sample(1:30,5)] <- NA   # make 5 z's missing   

cov(xyz1,use="pairwise")     # the individual pairwise covars are fine ... 

           x          y        z
x  1.2107760 -0.2552947 1.255868
y -0.2552947  1.2728156 1.037446
z  1.2558683  1.0374456 2.367978 

 chol(cov(xyz1,use="pairwise"))  # ... but leave the matrix not positive semi-definite 

Error in chol.default(cov(xyz1, use = "pairwise")) : 
  the leading minor of order 3 is not positive definite

 chol(cov(xyz1,use="complete")) # but deleting even more rows leaves it PSD 

          x          y          z
x 0.8760209 -0.2253484 0.64303448
y 0.0000000  1.1088741 1.11270078
z 0.0000000  0.0000000 0.01345364
added 1098 characters in body
Source Link
Glen_b
  • 290.5k
  • 37
  • 652
  • 1.1k
Loading
added 232 characters in body
Source Link
Glen_b
  • 290.5k
  • 37
  • 652
  • 1.1k
Loading
added 232 characters in body
Source Link
Glen_b
  • 290.5k
  • 37
  • 652
  • 1.1k
Loading
added 232 characters in body
Source Link
Glen_b
  • 290.5k
  • 37
  • 652
  • 1.1k
Loading
Source Link
Glen_b
  • 290.5k
  • 37
  • 652
  • 1.1k
Loading