当前位置:文档之家› 相关系数计算公式

相关系数计算公式

相关系数计算公式相关系数计算公式Statistical correlation coefficientDue to the statistical correlation coefficient used more frequently, so here is the use of a few articles introduce these coefficients.The correlation coefficient: a study of two things (in the data we call the degree of correlation between the variables).If there are two variables: X, Y, correlation coefficient obtained by the meaning can be understood as follows:(1), when the correlation coefficient is 0, X and Y two variable relationship.(2), when the value of X increases (decreases), Y value increases (decreases), the two variables are positive correlation, correlation coefficient between 0 and 1.(3), when the value of X increases (decreases), the value of Y decreases (increases), two variables are negatively correlated, the correlation coefficient between -1.00 and 0.The absolute value of the correlation coefficient is bigger, stronger correlations, the correlation coefficient is close to 1 or -1, the higher degree of correlation, the correlation coefficient is close to 0 and the correlation is weak.The related strength normally through the following range of judgment variables:The correlation coefficient 0.8-1.0 strong correlation0.6-0.8 strong correlation0.4-0.6 medium degree.0.2-0.4 weak correlation0.0-0.2 very weakly correlated or not correlatedPearson (Pearson) correlation coefficient1, introductionPearson is also known as the correlation (or correlation) is a kind of calculation method of the linear correlation of British statistician Pearson in twentieth Century.Suppose there are two variables X, Y, then the Pearson correlation coefficient between the two variables can be calculated by the following formula:A formula:Formula two:Formula three:Formula four:Four equivalent formulas listed above, where E is the mathematical expectation, cov said the covariance, N represents the number of variables.2, scope of applicationWhen the two variables of the standard deviation is not zero, the correlation coefficient is defined, the correlation coefficient for Pearson:(1), is the linear relationship between the two variables, are continuous data.(2) overall, two variables are normally distributed, or near normal unimodal distribution.(3) and the observation values of two variables is in pairs, each pair of observations are independent of each other.3, MatlabPearson correlation coefficient Matlab (according to the formula four):[cpp] view plaincopyFunction coeff = myPearson (X, Y)% of the function of the realization of the Pearson correlation coefficient calculating operation%% input:% X: numerical sequence input% Y: numerical sequence input%% output:% coeff: two input numerical sequence X, the correlation coefficient of Y%If length (X) ~ = length (Y)Error (two 'numerical sequence dimension is not equal to');Return;EndFenzi = sum (X * Y) - (sum (X) * sum (Y)) / length (X);(fenmu = sqrt (sum (X.^2) - sum (X) ^2 / length (X)) * (sum (Y.^2) - sum (Y) ^2 / length (X)));Coeff = fenzi / fenmu;End% myPearson end functionCalculate the Pearson correlation coefficient function can also be used in existing Matlab:[cpp] view plaincopyCoeff = corr (X, Y);4, reference contentSpearman Rank (Spielman rank correlation coefficient)1, introductionIn statistics, Spielman correlation coefficient is named for Charles Spearman, and often use the Greek symbol (rho) said its value. Spielman rank correlation coefficient is used to estimate the correlation between the two variables X and Y, the correlation between variables can be used to describe the monotone function.If the two sets of two variable does not have the same two elements, so, when one of the variables can be expressed as a monotone function well when another variable (i.e. changes in two variables of the same trend), between the two variables can reach +1 or -1.Suppose that two random variables were X, Y (also can be seen as a set of two), the number of their elements are N, two I(1<=i<=N) random variables take values respectively with Xi, Yi said. Sort of X, Y (at the same time as ascending or descending), two ranking elements set X, y, Xi, Yi elements which are Xi in X and Yi ranking in the Y ranking. The collection of X, y elements in the corresponding subtraction to get a list of difference set D, di=xi-yi, 1<=i<=N. Spielman rank correlation coefficient between random variables X and Y can be obtained by X, y or D calculation, the calculation methods are as follows:By ranking difference calculated from D diversity (formula one):From the top set X, calculated from Y (Spielman rank correlation coefficient were also considered after ranking two random variables Pearson correlation coefficient, the following is the actual Pearson calculated the correlation coefficient X, y) (formula two):The following is a set of elements in the list of examples of calculation (calculated only for Spielman rank correlation coefficient)Note: when the two variables of the same, their ranking is obtained by the average of their positions.2, scope of applicationSpielman rank correlation coefficient of the data conditions without Pearson correlation coefficient is strict, as long as the observed values of two variables is the rating data pairs,or transformed by continuous variable data level data, regardless of the overall distribution of the two variables of the form, the size of the sample, we can use Spielman correlation the coefficient of.3, MatlabA source program:Spielman rank correlation coefficient Matlab (based on ranking difference diversity D calculated using the above formula)[cpp] view plaincopyFunction coeff = mySpearman (X, Y)% of the function used to achieve computing Spielman rank correlation coefficient%% input:% X: numerical sequence input% Y: numerical sequence input%% output:% coeff: two input numerical sequence X, the correlation coefficient of YIf length (X) ~ = length (Y)Error (two 'numerical sequence dimension is not equal to');Return;EndN = length (X);% by the length of the sequenceXrank = zeros (1, N);% of elements stored in the X listYrank = zeros (1, N);% of elements stored in the Y list% calculated value in XrankFor I: N = 1Cont1 = 1; the number of records is higher than the specified element%Cont2 = -1;% records with specific elements of the same number of elementsFor J: N = 1If X (I) < X (J)Cont1 = cont1 + 1;Elseif X (I) = X (J)Cont2 = cont2 + 1;EndEndXrank (I) = cont1 + mean ([0: cont2]);End% calculated value in YrankFor I: N = 1Cont1 = 1; the number of records is higher than the specified element%Cont2 = -1;% records with specific elements of the same numberof elementsFor J: N = 1If Y (I) < Y (J) Cont1 = cont1 + 1; Elseif Y (I) = Y (J) Cont2 = cont2 + 1; EndEnd。

相关主题