Message Boards Message Boards

GROUPS:

Represent a correlation matrix via a graph

Posted 1 month ago
508 Views
|
8 Replies
|
4 Total Likes
|

I have a simple (maybe mistake!) question. Is it possible to present a correlation matrix via a graph? For example:

data1 = {11.22, 12.29, 12.97, 14.15, 17.33, 17.60, 16.62, 14.43, 
   13.62, 11.01};
data2 = {12.29, 12.97, 14.15, 17.33, 17.60, 16.625`, 14.43, 13.62, 
   11.01, 9.25};
data3 = {12.97, 14.15, 17.33, 17.60, 16.625`, 14.43, 13.62, 11.016, 
   9.25, 9.48};

Apply[Correlation, 
  Tuples[{data1, data2, data3}, 2] // Partition[#, 3, 3] &, {2}] // 
 MatrixPlot[#, ColorFunction -> "DeepSeaColors", 
   PlotLegends -> Automatic] &

enter image description here

Thank you for your help.

8 Replies
Posted 1 month ago

If you allow for edges to have custom weights, then I'm pretty sure that yes you can represent a correlation matrix with a directed graph. However, if you just label the edges with their weights, it may be challenging to visualize. It would be easy to include/omit edges if the correlation matrix was binary. Changing the thickness or opacity of the edges with their weights would be the best way to visualize a correlation matrix as a graph in my opinion.

Posted 1 month ago

Along the lines that Joseph suggested

corr = Apply[Correlation, Tuples[{data1, data2, data3}, 2] // Partition[#, 3, 3] &, {2}]

WeightedAdjacencyGraph[corr,
 DirectedEdges -> True,
 EdgeStyle -> {DirectedEdge[i_, j_] :> AbsoluteThickness[corr[[i, j]]]},
 PlotTheme -> "Scientific"]

enter image description here

Posted 1 month ago

Wow!

Thank you so much, man.

For more understanding, is it possible to show correlation values on the figure?

Posted 1 month ago

As Sam said, this can be easily found in the documentation.

rounded = Round[corr, .01]

WeightedAdjacencyGraph[rounded,
 DirectedEdges -> True,
 EdgeStyle -> {DirectedEdge[i_, j_] :> AbsoluteThickness[rounded[[i, j]]]},
 EdgeLabels -> "EdgeWeight",
 PlotTheme -> "Scientific"]

enter image description here

Hi Rohit,

That is great.

I noticed that recently in the scientific papers, researchers show the correlation between some lists through a graph like the following figure. I thought it may be interesting for you. enter image description here

Best Regards

Mohammad

Posted 1 month ago

Thank you, Joseph.

May I ask you to do for the example data? Is the result understandable?

Please read the rules: http://wolfr.am/READ-1ST
New questions require new discussions posted separately and not digressing topics of other discussions. This question was moved to its own new discussion.

@Alex Teymouri the questions you are asking are easily found in documentation. As you can read in the forum rules you should show your own effort first and explain what does and what does not work in your own code. Good places to start:

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract