matlab求相关性corrcoef结果说明
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
对于一般的矩阵X,执行A=corrcoef(X)后,A中每个值的所在行a和列b,反应的是原矩阵X中相应的第a个列向量和第b个列向量的相似程度(即相关系数)。
计算公式是:C(1,2)/SQRT(C(1,1)*C(2,2)),其中C表示矩阵[f,g]的协方差矩阵,假设f和g都是列向量(这两个序列的长度必须一样才能参与运算),则得到的(我们感兴趣的部分)是一个数。
以默认的A=corrcoef(f,g)为例,输出A是一个二维矩阵(对角元恒为1),我们感兴趣的f和g的相关系数就存放在A(1,2)=A(2,1)上,其值在[-1,1]之间,1表示最大的正相关,-1表示绝对值最大的负相关.
CORRCOEF Correlation coefficients.
R=CORRCOEF(X) calculates a matrix R of correlation coefficients for
an array X, in which each row is an observation and each column is a
variable.
R=CORRCOEF(X,Y), where X and Y are column vectors, is the same as
R=CORRCOEF([X Y]). CORRCOEF converts X and Y to column vectors if they
are not, i.e., R=CORRCOEF(X,Y) is equivalent to R=CORRCOEF([X(:) Y(:)])
in that case.
If C is the covariance matrix, C = COV(X), then CORRCOEF(X) is
the matrix whose (i,j)'th element is
C(i,j)/SQRT(C(i,i)*C(j,j)).
[R,P]=CORRCOEF(...) also returns P, a matrix of p-values for testing
the hypothesis of no correlation. Each p-value is the probability
of getting a correlation as large as the observed value by random
chance, when the true correlation is zero. If P(i,j) is small, say
less than 0.05, then the correlation R(i,j) is significant.
[R,P,RLO,RUP]=CORRCOEF(...) also returns matrices RLO and RUP, of
the same size as R, containing lower and upper bounds for a 95%
confidence interval for each coefficient.
[...]=CORRCOEF(...,'PARAM1',V AL1,'PARAM2',V AL2,...) specifies addit ional
parameters and their values. V alid parameters are the following:
Parameter V alue
'alpha' A number between 0 and 1 to specify a confidence
level of 100*(1-ALPHA)%. Default is 0.05 for 95%
confidence intervals.
'rows' Either 'all' (default) to use all rows, 'complete' to
use rows with no NaN values, or 'pairwise' to compute
R(i,j) using rows with no NaN values in column i or j.
The p-value is computed by transforming the correlation to create a t statistic having N-2 degrees of freedom, where N is the number of rows of X. The confidence bounds are based on an asymptotic normal distribution of 0.5*log((1+R)/(1-R)), with an approximate variance equal to 1/(N-3). These bounds are accurate for large samples when X has a multivariate normal distribution. The 'pairwise' option can produce
an R matrix that is not positive definite.
Example: Generate random data having correlation between column 4 and the other columns.
x = randn(30,4); % uncorrelated data
x(:,4) = sum(x,2); % introduce correlation
[r,p] = corrcoef(x) % compute sample correlation and p-values [i,j] = find(p<0.05); % find significant correlations
[i,j] % display their (row,col) indices。