相关系数

相关系数用于表征两组统计数据之间的线性关系,其取值范围在-1~1之间。

对于统计数据X=[x1 x2 ... xn]和Y=[y1 y2 ... yn],设其相关系数为r。

|r| < 0.4 ,X和Y之间低线性相关

0.4<|r|<0.7,X和Y之间显著线性相关

0.7<|r|,X和Y之间高线性相关

-----------------------

平均值 mean(x) = sum(x)/length(x)

方差 var(x) = sum((x-mean(x)).^2)/(length(x)-1)

协方差 cov(x,y) = sum((x-mean(x)).*(y-mean(y)))/(length(x)-1)

相关系数 corrcoef = cov(x,y) / sqrt(var(x)*var(y))

                                = sum((x-mean(x)).*(y-mean(y)))/(length(x)-1)/(sqrt(var(x)*var(y))

                                = sum((x-mean(x)).*(y-mean(y)))/sqrt(sum((x-mean(x)).^2)*sum((y-mean(y)).^2))

matlab的corrcoef计算结果为相关系数矩阵。

在matlab中

对于向量,x和y,  corrcoef = [c_xx,  c_xy;

                                               c_yx,  c_yy]

对于矩阵x=[x1 x2 x3], corrcoef = [ c_x1x1, c_x1x2, c_x1x3;

                                                            c_x2x1, c_x2x2, c_x2x3;

                                                            c_x3x1, c_x3x2, c_x3x3 ];

你可能感兴趣的:(相关系数)