Answers.Body: <p>Ok I think I roughly get what you want to get. Below I simulate something that's like your data because you provided two identical matrices.</p>
  
  <pre><code>#3 TE, 10 tissue, random values
  # number of tissue
  M1 = matrix(rnorm(30),3,10)
  rownames(M1) = paste("TE",1:3,sep="_")
  colnames(M1) = paste("Tissue",letters[1:10],sep="_")
  ## make gene matrix, , random values
  M2 = matrix(rnorm(30),3,10)
  rownames(M2) = paste("Gene",1:3,sep="_")
  colnames(M2) = paste("Tissue",letters[1:10],sep="_")
  ## here we make TE1 highly correlated to Gene1
  M2[1,] = M1[1,] + rnorm(10,0,0.3)
  ## here we make TE2 highly anti-correlated to Gene2
  M2[2,] = -1*M1[2,] + rnorm(10,0,0.3)
  #here we calculate for each TE, its correlation with each gene.
  #credit to @haci
  COR = apply(t(M1),t(M2))
  # you can look at the correlation
  COR
  </code></pre>
  
  <p>What you need is the last three rows. Remember, you can only calculate correlation between the gene and the TE, and you do this across all tissue. For example, if gene1 and TE1 has a high correlation, this tells you TE1 expression can predict gene1 expression in most tissue.</p>
  
  <p>It's meaningless to calculate correlation between one data point and another. You need more than 1 value. For example, if you do cor(10,5), it doesn't make sense. </p>
  
  <p>Hope this is what you are trying to do.. </p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-10-16T07:01:57.537Z
Answers.Text: `cor(t(M1), t(M2))` will suffice, you don't need an `apply()` call as `If x and y are matrices then the covariances (or correlations) between the columns of x and the columns of y are computed.`
Answers.UserDisplayName: haci
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-10-16T07:17:45.207Z
Answers.Text: You are right. Thanks @haci!
Answers.UserDisplayName: StupidWolf
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-10-16T19:29:41.793Z
Answers.Text: thank you very much
Answers.UserDisplayName: jonny
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-10-15T19:28:13.390Z
Answers.LastActivityDate: 2019-10-16T07:18:43.277Z
Answers.LastEditDate: 2019-10-16T07:18:43.277Z
Answers.UserDisplayName: StupidWolf
Body: <p>I have two matrix identical in N° of rows and columns. In the first matrix rows indicate transposable elements and columns  indicate samples. the matrix show the degree of expression of each element in samples: </p>
  
  <pre><code>M1 &lt;-
  
  
              elements          ova       testes       retina   optic_lobe       suckers 
  1   LINES/3           1.473559e+03   962.953589   673.903449   558.879946   947.631992          
  2   SINES             1.836210e+02   355.808323   577.807528   341.048786   99.902702          
  3  DNA TRANSP         9.181051e+00   178.661200  4387.148414    53.907711   353.413028           
  </code></pre>
  
  <p>In Second matrix rows indicate genes and columns indicate samples. the matrix show the degree of expression of each gene in samples: </p>
  
  <pre><code> M2 &lt;-
              elements          ova       testes       retina   optic_lobe  suckers 
  1   OCBIM_22028242mg 1.473559e+03   962.953589   673.903449   558.879946   947.631992          
  2   OCBIM_22008718mg 1.836210e+02   355.808323   577.807528   341.048786   99.902702          
  3   OCBIM_22009482mg 9.181051e+00   178.661200  4387.148414    53.907711   353.413028           
  </code></pre>
  
  <p>I have to make an element-gene correlation. I have to check, for example, if the element A expressed much in the tissue X has the corresponding gene A expressed very, little, or nothing in the tissue X</p>
  
  <p>fOR example I'm expecting this result:</p>
  
  <pre><code>M1,2 &lt;-
                  elements          ova       testes       retina   optic_lobe  suckers 
      1   TE/ gene1                  0.3          1          0.5         -1         0.3          
      2   TE/gene2                   0.1        0.6            0         -1         0.9      
      3   TE/gene3                     1          1          0.8        -0.2       -0.3            
  </code></pre>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-10-15T17:01:46.180Z
Comments.Text: Hi @jonny, you can only find the correlation between M1 and M2. In other words, you see how well each TE in each tissue predict each gene. you do cor(M1,M2)
Comments.UserDisplayName: StupidWolf
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-10-15T17:02:11.297Z
Comments.Text: Maybe you can rephrase the question if you mean to do something else?
Comments.UserDisplayName: StupidWolf
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-10-15T17:12:23.663Z
Comments.Text: ok, I'll rephrase it. for each row, I would like to find the correlation transposable element - gene in all tissues
Comments.UserDisplayName: jonny
Tags: <r><gene><correlation>
Title: correlation between transposon and gene
ThreadText: # correlation between transposon and gene
  
  (Asked by: username_0 on 2019-10-15)
  
  I have two matrix identical in N° of rows and columns. In the first matrix rows indicate transposable elements and columns indicate samples. the matrix show the degree of expression of each element in samples:
  
  ```
  M1 <-
  
              elements          ova       testes       retina   optic_lobe       suckers 
  1   LINES/3           1.473559e+03   962.953589   673.903449   558.879946   947.631992          
  2   SINES             1.836210e+02   355.808323   577.807528   341.048786   99.902702          
  3  DNA TRANSP         9.181051e+00   178.661200  4387.148414    53.907711   353.413028           
  
  ```
  
  In Second matrix rows indicate genes and columns indicate samples. the matrix show the degree of expression of each gene in samples:
  
  ```
   M2 <-
              elements          ova       testes       retina   optic_lobe  suckers 
  1   OCBIM_22028242mg 1.473559e+03   962.953589   673.903449   558.879946   947.631992          
  2   OCBIM_22008718mg 1.836210e+02   355.808323   577.807528   341.048786   99.902702          
  3   OCBIM_22009482mg 9.181051e+00   178.661200  4387.148414    53.907711   353.413028           
  
  ```
  
  I have to make an element-gene correlation. I have to check, for example, if the element A expressed much in the tissue X has the corresponding gene A expressed very, little, or nothing in the tissue X
  
  fOR example I'm expecting this result:
  
  ```
  M1,2 <-
                  elements          ova       testes       retina   optic_lobe  suckers 
      1   TE/ gene1                  0.3          1          0.5         -1         0.3          
      2   TE/gene2                   0.1        0.6            0         -1         0.9      
      3   TE/gene3                     1          1          0.8        -0.2       -0.3            
  
  ```
  
  **Tags:** r, gene, correlation
  
  > **Comments:**
  > **username_1**: Hi @username_0, you can only find the correlation between M1 and M2. In other words, you see how well each TE in each tissue predict each gene. you do cor(M1,M2)  
  > **username_1**: Maybe you can rephrase the question if you mean to do something else?  
  > **username_0**: ok, I'll rephrase it. for each row, I would like to find the correlation transposable element - gene in all tissues  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2019-10-15. Score: 1 | Accepted answer
  
  Ok I think I roughly get what you want to get. Below I simulate something that's like your data because you provided two identical matrices.
  
  ```
  #3 TE, 10 tissue, random values
  # number of tissue
  M1 = matrix(rnorm(30),3,10)
  rownames(M1) = paste("TE",1:3,sep="_")
  colnames(M1) = paste("Tissue",letters[1:10],sep="_")
  ## make gene matrix, , random values
  M2 = matrix(rnorm(30),3,10)
  rownames(M2) = paste("Gene",1:3,sep="_")
  colnames(M2) = paste("Tissue",letters[1:10],sep="_")
  ## here we make TE1 highly correlated to Gene1
  M2[1,] = M1[1,] + rnorm(10,0,0.3)
  ## here we make TE2 highly anti-correlated to Gene2
  M2[2,] = -1*M1[2,] + rnorm(10,0,0.3)
  #here we calculate for each TE, its correlation with each gene.
  #credit to @username_2
  COR = apply(t(M1),t(M2))
  # you can look at the correlation
  COR
  
  ```
  
  What you need is the last three rows. Remember, you can only calculate correlation between the gene and the TE, and you do this across all tissue. For example, if gene1 and TE1 has a high correlation, this tells you TE1 expression can predict gene1 expression in most tissue.
  
  It's meaningless to calculate correlation between one data point and another. You need more than 1 value. For example, if you do cor(10,5), it doesn't make sense.
  
  Hope this is what you are trying to do..
  
  > **Comments:**
  > **username_2**: `cor(t(M1), t(M2))` will suffice, you don't need an `apply()` call as `If x and y are matrices then the covariances (or correlations) between the columns of x and the columns of y are computed.`  
  > **username_1**: You are right. Thanks @username_2!  
  > **username_0**: thank you very much  
  
  ---
  
  