# Correlation finding between two Matrix

#1

Given Matrix
S1=[1 1 0 0 1]
S2=[1 0 0 0 0]
S3=[1 1 1 1 0]
S4=[0 0 0 1 0]
S5=[0 1 1 1 1]

Output will be the correlation of :
{S1,S2}=
{S1,S3}=
{S1,S4}=
{S1,S5}=
{S2,S3}=
{S2,S4}=
{S2.S5}=
{S3,S4}=
{S3,S5}=
{S4,S5}=

#2

Try to take a look at `cor()`, e.g.:

``````X = matrix(data = rnorm(100), nrow = 10, ncol = 10)
cor(x = X, method = "pearson")
``````

#3

It depends on what kind of correlation you want to calculate. See the below guide for getting started with calculating correlation in R.

https://www.statmethods.net/stats/correlations.html

In the spirit of the forum, it's best to give it a go yourself, and then, if you get stuck, include a reprex (short for minimal reproducible example) with your code, and we can help you troubleshoot from there!

#4

I have 409 by 610 binary matrix. I want to fin out the correlation like above demonstration using pearson method.

#5

R studio programming, using "for loop" find out the correlation (method = "pearson") of Given value :
F1 F2 F3
1 0 1
0 1 0
0 1 0
1 1 1
0 1 1
Output will be
R12 = cor (F1, F2) = ?
R13= cor (F1, F3) = ?
R23= cor (F2, F3) = ?
and save the output in excel file

#6

The correlation between two vectors in R is the `cor` function. For example;

``````x = 1:3
y = 4:2
cor(x,y, method = "pearson")
#> [1] -1
``````

Created on 2018-05-11 by the reprex package (v0.2.0).

It looks like you're dealing with a data frame. And it looks like you want to get all the combinations of columns?

``````df = matrix(c(2,4,3,1,5,7,1,2,3,5,8,2,4,5,1,1,3,6,1,3,4,5,6,1),nrow=6,ncol=4,byrow = TRUE)
df = as.data.frame(df)
df
#>   V1 V2 V3 V4
#> 1  2  4  3  1
#> 2  5  7  1  2
#> 3  3  5  8  2
#> 4  4  5  1  1
#> 5  3  6  1  3
#> 6  4  5  6  1
cor(df, method = "pearson")
#>            V1         V2         V3         V4
#> V1  1.0000000  0.7385489 -0.2533202  0.0000000
#> V2  0.7385489  1.0000000 -0.4287465  0.6324555
#> V3 -0.2533202 -0.4287465  1.0000000 -0.1898142
#> V4  0.0000000  0.6324555 -0.1898142  1.0000000
``````

Created on 2018-05-11 by the reprex package (v0.2.0).

You'll want to extract all those combinations in the last table.
How comfortable with R are you at this point?

#7

thank you, sir for your great help