corrCOV
将协方差矩阵转换为相关矩阵
Description
Examples
Compare Correlation Matrices Obtained by Two Different Methods
Compare the correlation matrix obtained by applyingcorrCOV
on a covariance matrix with the correlation matrix obtained by direct computation usingCorrcoef
在输入矩阵上。
加载医院
data set and create a matrix containing theWeight
和BloodPressure
measurements. Note that医院.BloodPressure
has 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 compareR1
withR2
.
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 matricesR1
和R2
是相同的。
Find Standard Deviations from Covariance Matrix
找到标准的矢量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
, 和Age
measurements. Note that医院.BloodPressure
has 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
.
计算相关矩阵和标准偏差X
from 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 compares1
withs2
.
s2 = sqrt(diag(C))
s2 =4×126.5714 6.7128 6.9325 7.2154
s1
和s2
相等,对应于变量的标准偏差X
.
Input Arguments
C
—协方差矩阵
matrix
Covariancematrix, specified as a square, symmetric, and positive semidefinite matrix.
For a matrixXthat hasNobservations (rows) andn随机变量(列),C
is ann-经过-nmatrix. Thendiagonal elements ofC
是variances的nrandom variables inX, 和a zero diagonal element inC
indicates a constant variable inX.
Data Types:single
|double
Output Arguments
R
— Correlation matrix
matrix
Correlation matrix, returned as a matrix that corresponds to the covariance matrixC
.
Data Types:single
|double
sigma
— Standard deviations
vector
Standard deviations, returned as ann-经过-1向量。
The elements ofsigma
是standard deviations of the variables inX, theN-经过-nmatrix that producesC
. Rowi
insigma
对应于列的标准偏差i
inX.
Data Types:single
|double
More About
Covariance
For two random variable vectorsA和B, the covariance is defined as
whereNis the length of each column,μA和μB是mean values ofA和B, respectively, and*
denotes the complex conjugate.
TheCOVariance matrixof two random variables is the matrix of pairwise covariance calculations between each variable,
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, .
方差
For a random variable vectorAcomposed ofNscalar observations, the variance is defined as
whereμis the mean ofA,
Some definitions of variance use a normalization factor ofNinstead ofN–1, but the mean always has the normalization factorN.
Extended Capabilities
GPU Arrays
使用并行计算工具箱™在图形处理单元(GPU)上运行加速代码。
此功能完全支持GPU数组。万博1manbetx有关更多信息,请参阅Run MATLAB Functions on a GPU(Parallel Computing Toolbox).
Version History
Open Example
You have a modified version of this example. Do you want to open this example with your edits?
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
选择一个网站
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select:.
您还可以从以下列表中选择一个网站:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- AméricaLatina(Español)
- Canada(English)
- United States(English)
欧洲
- Belgium(English)
- 丹麦(English)
- Deutschland(德意志)
- España(Español)
- Finland(English)
- 法国(Français)
- 爱尔兰(English)
- 意大利(Italiano)
- Luxembourg(English)
- Netherlands(English)
- 挪威(English)
- Österreich(德意志)
- Portugal(English)
- Sweden(English)
- 瑞士
- 英国(English)