MATLAB Correlation Analysis

Source: Internet
Author: User

Pearson correlation coefficient

Examine the degree of correlation between two things (what we call variables in the data), simply by measuring whether two data sets are on a line. The formula is: or OR

n indicates the number of variables to be evaluated.

The value of correlation coefficient r is between –1 and +1, i.e. –1≤r≤+1. The properties are as follows:

    1. When r>0, two variables are represented (when the value of x increases (decreases), the Y value increases (decreases)) is positively correlated, and when r<0, the two variables are negatively correlated (when the value of x increases (decreases) and the Y value decreases (increases)).
    2. When |r|=1, it means that the two variables are completely linearly related, that is, a function relationship.
    3. When r=0, it indicates the relationship between the two variables of the wireless correlation.
    4. When 0<|r|<1, there is a certain degree of linear correlation between the two variables. The closer the |r| is to 1, the closer the linear relationship between the two variables is, and the closer the |r| is to 0, the weaker the linear correlation between the two variables.

Generally can be divided into three levels: |r|<0.4 for low-grade linear correlation, 0.4≤|r|<0.7 is significant correlation; 0.7≤|r|<1 is highly linear dependent.

When the standard deviation of two variables is not zero, the correlation coefficients are defined, and the Pearson correlation coefficient applies To:

    1. There are linear relationships between the two variables, which are continuous data.
    2. The population of two variables is normally distributed, or a single-peak distribution close to the normal state.
    3. The observed values of two variables are paired, and each pair of observations is independent of each other.

A concrete example of calculation:

X Y 1 2 2 5 3 6

Using MATLAB, you can use the function Corrcoef or Corr

First look at the content of help CORRCOEF:

And look at the content of help Corr.

For the specific calculation examples mentioned earlier, the following can be implemented in MATLAB:

X=[1;2;3];y=[2;5;6];r1=corr (x, Y, ' type ', ' Pearson '); R2=corrcoef (x, y);

Finally, you can see

r1=0.9608

R2=

1.0000 0.9608

0.9608 1.0000

Are consistent with the previous calculation results. It is important to note that the Pearson correlation coefficient is calculated by default when using the Corr function

Spearman correlation coefficient

Spearman correlation coefficients are used to estimate correlations between two variables x and Y, where the correlations between variables can be described using monotone functions. If none of the two sets of two variables have the same two elements, then when one of the variables can be represented as a good monotone function of another variable (that is, two variables are trending the same), the correlation coefficients between two variables can reach +1 or-1.

Assume that two random variables are X, Y (also can be considered as two sets), they have the number of elements are N, two random variables take the first I (1<=I<=N) values are expressed as Xi, Yi. To sort x, Y (both ascending and descending), get two elements in the set X, Y, where element Xi, Yi is the rank of Xi in X, and Yi's rank in Y. Subtract the elements from the set X, y to get a line of difference set D, where di=xi-yi,1<=i<=n. The Spearman correlation coefficients between x and y of a random variable can be computed by x, Y, or D, as follows:

Calculated from the rank difference set D (Formula One):

Calculated from the rank set X and Y (the Spearman correlation coefficient is also considered to be the Pearson correlation coefficient of the two random variables that are ranked, the following is actually the Pearson correlation coefficient of x, y) (Formula Two):

The following is an example of calculating the ranking of elements in a set (only for Uspirman correlation coefficients)

It is important to note that when the two values of a variable are the same, their rank is obtained by averaging their positions.

Spearman correlation coefficient requirements for data conditions there is no strict Pearson correlation coefficient, as long as the observation value of two variables is paired, or is converted from continuous variable observation data, no matter the total distribution of two variables and the size of sample capacity, can be used spearman correlation coefficient to study.

Using MATLAB to calculate spearman correlation coefficients is relatively simple and also uses the Corr function, as follows:

r= Corr (x, Y, ' type ', ' Spearman ');

For the above example, you can calculate the r=1.

Note: When using MATLAB to calculate spearman correlation coefficients, it is necessary to ensure that both X and y are column vectors, and the function of MATLAB is to calculate the Spearman correlation coefficients of the series by Formula Two.

MATLAB Correlation Analysis

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.