SAS and R 学习记录

# 相关系数与协方差间的转换

***** Program 4.10 PROC IML ***********;
***** Converting a correlation matrix to covariance matrix, and vice versa;
***** Example data from Table 4.4 ;
****** Part I: Converting correlation matrix to covariance matrix;
PROC IML;

*** define the correlation matrix;
R={1.00 0.70 0.20,
0.70 1.00 0.40,
0.20 0.40 1.00};

*** define the diagonal matrix with standard deviations on the diagonal;
S={15 0 0,
0 10 0,
0 0 1};

*** obtain the covariance matrix;
COV=S*R*S;

*** print the covariance matrix;
PRINT COV;
RUN;

***** Part II: Converting covariance matrix to correlation matrix;
PROC IML;

*** define the covariance matrix;
COV={225 105 3,
105 100 4,
3   4 1};

*** obtain the matrix with standard deviations on the diagonal;
S=SQRT(DIAG(COV));

*** the inverse of S matrix;
S_INV=INV(S);

*** obtain correlation matrix;
R=S_INV*COV*S_INV;

** print out the three matrices;
PRINT COV S R;
RUN;

FROM 《SAS for Monte Carlo Studies》，P96-97

#### 终于明白协方差的意义了

2015-12-03 16:50:03

#### 什么是协方差，怎么计算？为什么需要协方差？

2017-05-25 15:34:23

#### 协方差的意义和计算公式

2016-04-06 14:43:46

#### 方差，协方差、标准差，与其意义

2016-09-01 11:51:32

#### 方差、协方差和协方差矩阵

2015-08-18 10:17:49

#### 协方差

2016-06-12 09:11:01

#### 方差与样本方差、协方差与样本协方差

2016-10-22 20:37:05

#### 详解协方差与协方差矩阵

2011-03-23 10:46:00

#### 协方差矩阵概念及计算

2017-02-06 16:27:09

#### 协方差矩阵详谈

2017-09-23 13:42:39