主要内容

corrCOV

将协方差矩阵转换为相关矩阵

Description

example

R= corrcov(C)返回相关矩阵Rcorresponding to the covariance matrixC.

example

[R,sigma] = corrcov(C)also returnssigma, a vector of standard deviations.

Examples

collapse all

Compare the correlation matrix obtained by applyingcorrCOVon a covariance matrix with the correlation matrix obtained by direct computation usingCorrcoef在输入矩阵上。

加载医院data set and create a matrix containing theWeightBloodPressuremeasurements. Note that医院.BloodPressurehas two columns of data.

load医院X = [hospital.Weight hospital.BloodPressure];

计算协方差矩阵。

c = cov(x)
C =3×3706.0404 27.7879 41.0202 27.7879 45.0622 23.8194 41.0202 23.8194 48.0590

通过使用协方差矩阵来计算相关矩阵corrCOV.

R1 = Corrcov(C)
R1 =3×31.0000 0.1558 0.2227 0.1558 1.0000 0.5118 0.2227 0.5118 1.0000

直接使用Corrcoef, 和then compareR1withR2.

R2 = corrcoef(X)
R2 =3×31.0000 0.1558 0.2227 0.1558 1.0000 0.5118 0.2227 0.5118 1.0000

The correlation matricesR1R2是相同的。

找到标准的矢量deviations from the covariance matrix, and show the relationship between the standard deviations and the covariance matrix.

加载医院data set and create a matrix containing theWeight,BloodPressure, 和Agemeasurements. Note that医院.BloodPressurehas two columns of data.

load医院X = [hospital.Weight hospital.BloodPressure hospital.Age];

计算协方差矩阵X.

c = cov(x)
C =4×4706.0404 27.7879 41.0202 17.5152 27.7879 45.0622 23.8194 6.4966 41.0202 23.8194 48.0590 4.0315 17.5152 6.4966 4.0315 52.0622

C是正方形,对称和阳性半芬矿。对角元素C是四个变量的差异X.

计算相关矩阵和标准偏差Xfrom the covariance matrixC.

[R,s1] = corrcov(C)
r =4×41.0000 0.1558 0.2227 0.0914 0.1558 1.0000 0.5118 0.1341 0.2227 0.5118 1.0000 0.0806 0.0914 0.1341 0.0806 1.0000
s1 =4×126.5714 6.7128 6.9325 7.2154

Compute the square root of the diagonal elements inC, 和then compares1withs2.

s2 = sqrt(diag(C))
s2 =4×126.5714 6.7128 6.9325 7.2154

s1s2相等,对应于变量的标准偏差X.

Input Arguments

collapse all

Covariancematrix, specified as a square, symmetric, and positive semidefinite matrix.

For a matrixXthat hasNobservations (rows) andn随机变量(列),Cis ann-经过-nmatrix. Thendiagonal elements ofCvariancesnrandom variables inX, 和a zero diagonal element inCindicates a constant variable inX.

Data Types:single|double

Output Arguments

collapse all

Correlation matrix, returned as a matrix that corresponds to the covariance matrixC.

Data Types:single|double

Standard deviations, returned as ann-经过-1向量。

The elements ofsigma是standard deviations of the variables inX, theN-经过-nmatrix that producesC. Rowiinsigma对应于列的标准偏差iinX.

Data Types:single|double

More About

collapse all

Covariance

For two random variable vectorsAB, the covariance is defined as

COV ( A , B ) = 1 N 1 i = 1 N ( A i μ A ) * ( B i μ B )

whereNis the length of each column,μAμB是mean values ofAB, respectively, and*denotes the complex conjugate.

TheCOVariance matrixof two random variables is the matrix of pairwise covariance calculations between each variable,

C = ( COV ( A , A ) COV ( A , B ) COV ( B , A ) COV ( B , B ) ) .

For a matrixX, in which each column is a random variable composed of observations, the covariance matrix is the pairwise covariance calculation between each column combination. In other words, C ( i , j ) = COV ( X ( : , i ) , X ( : , j ) ) .

方差

For a random variable vectorAcomposed ofNscalar observations, the variance is defined as

V = 1 N 1 i = 1 N | A i μ | 2

whereμis the mean ofA,

μ = 1 N i = 1 N A i .

Some definitions of variance use a normalization factor ofNinstead ofN–1, but the mean always has the normalization factorN.

Extended Capabilities

Version History

Introduced in R2007b