Last active
August 29, 2015 13:57
-
-
Save dgrapov/9627429 to your computer and use it in GitHub Desktop.
Making edge lists for correlation networks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #------------------------------------------------------ | |
| # demonstration of making edge lists for | |
| # correlation network analysis | |
| # by Dmitry Grapov | |
| # 031814 | |
| #------------------------------------------------------ | |
| # load devium library for all functions | |
| source("http://pastebin.com/raw.php?i=JVyTrYRD") # sources function to download github repo (https://github.com/dgrapov/devium) | |
| #example data | |
| data(mtcars) | |
| tmp.data<-mtcars # change column names to numeric index for a more robust key, this key will need to match variable properties in the node attributes file | |
| #calculate correlation based edge list | |
| correl<-devium.calculate.correlations(tmp.data,type="spearman", results = "edge list") | |
| correl$fdr.p<-p.adjust(correl$p.values, method = "BH", n = length(correl$p.values)) # FDR adjusted p-values | |
| #(optional) limit maximum number of connections (max.edges) per source node | |
| # fxn allows more than max.edges to connect otherwise disconnected nodes | |
| filtered.id<-edge.list.filter.partial(edge.list=correl[,1:2],weight=correl[,3],max.edges=5) | |
| correl<-correl[filtered.id,] | |
| #prepare for network mapping | |
| edge.list<-correl[,1:2] | |
| edge.list$color<-"positive" | |
| edge.list$color[correl$value<0]<-"negative" | |
| edge.list$width<-abs(correl$value) | |
| #filter based on p<0.05 | |
| edge.list<-edge.list[correl$p.values<0.05,] # change optionally to correl$fdr.p for FDR adjusted correlations (could use package FDRtools for more robust measure) | |
| write.csv(edge.list,file="edge list.csv",row.names = FALSE) # save as CSV |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment