<< nisp_corrcoef Support nisp_erfcinv >>

NISP >> NISP > Support > nisp_cov

nisp_cov

Returns the empirical covariance matrix.

Calling Sequence

C=nisp_cov(x)
C=nisp_cov(x,0)
C=nisp_cov(x,1)
C=nisp_cov(x,y)
C=nisp_cov(x,y,0)
C=nisp_cov(x,y,1)

Parameters

x:

a matrix of doubles

y:

a matrix of doubles

C:

a square matrix of doubles, the empirical covariance

Description

If x is a nobs-by-1 matrix, then nisp_cov(x) returns the variance of x, normalized by nobs-1.

If x is a nobs-by-nvar matrix, then nisp_cov(x) returns the nvar-by-nvar covariance matrix of the columns of x, normalized by nobs-1. Here, each column of x is a variable and each row of x is an observation.

If x and y are two nobs-by-1 matrices, then nisp_cov(x,y) returns the 2-by-2 covariance matrix of x and y, normalized by nobs-1, where nobs is the number of observations.

nisp_cov(x,0) is the same as nisp_cov(x) and nisp_cov(x,y,0) is the same as nisp_cov(x,y). In this case, if the population is from a normal distribution, then C is the best unbiased estimate of the covariance matrix.

nisp_cov(x,1) and nisp_cov(x,y,1) normalize by nobs. In this case, C is the second moment matrix of the observations about their mean.

Examples

x = [1;2];
y = [3;4];
C=nisp_cov(x,y)
expected = [0.5,0.5;0.5,0.5]
//
x = [230;181;165;150;97;192;181;189;172;170];
y = [125;99;97;115;120;100;80;90;95;125];
expected = [
1152.4556,-88.911111
-88.911111,244.26667
]
C=nisp_cov(x,y)

Authors

Bibliography

"Introduction to probability and statistics for engineers and scientists.", Sheldon Ross

<< nisp_corrcoef Support nisp_erfcinv >>