Calculating Pearson’s correlation coefficient in R: co-expression measure

Pearson’s correlation coefficient is a measure of the linear correlation between two variables (X and Y). The coefficient is given in a value between +1 and −1, where 1 is interpreted as total positive correlation, 0 is no correlation, and −1 is a total negative correlation. This correlation coefficient is widely used for measuring co-expression between pairs of genes in different samples.

In the example below I’m demonstrating how to easily calculate the Pearson’s correlation coefficient using R; assuming that we have FPKM expression values for 6 genes (Var1 to Var6) from 9 different samples/experiments (TRT1 to TRT9).

Table input

      Var1  Var2  Var3   Var4   Var5     Var6
TRT1  0.09  0.02  37.56  38.65  547.44   637.01
TRT2  0.03  0.01  55.11  45.47  334.72   692.89
TRT3  0.04  0.02  22.11  22.42  635.39  1095.09
TRT4  0.00  0.00  25.94  25.92   86.32   130.26
TRT5  0.00  0.02  35.27  31.30  149.02   268.16
TRT6  0.00  0.00 112.01  71.00  127.19   178.33
TRT7  0.41  1.26  54.57  29.63  233.09   220.73
TRT8  0.01  0.02  24.70  29.78  481.40   523.52
TRT9  0.41  0.22  20.89  17.26   53.20    83.54

Commands in R

> data <- read.table(“table.txt”)
> cor(data)

Output matrix

     Var1    Var2    Var3    Var4    Var5    Var6
Var1  1      0.77   -0.12   -0.39   -0.28   -0.36
Var2  0.77   1       0.08   -0.19   -0.16   -0.28
Var3 -0.12   0.08    1       0.93   -0.27   -0.24
Var4 -0.39  -0.19    0.93    1      -0.10   -0.08
Var5 -0.28  -0.16   -0.27   -0.10    1       0.91
Var6 -0.36  -0.28   -0.24   -0.08    0.91    1

Positive correlation between pairs of genes (suggestion of co-expressed genes):

Var1 vs. Var2 = 0.77
Var3 vs. Var4 = 0.93
Var5 vs. Var6 = 0.91

Advertisements
This entry was posted in Local Tools. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s