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
# Example of setting row and column names | |
mdat <- matrix(c(1,2,3, 11,12,13), nrow = 2, ncol=3, byrow=TRUE, | |
dimnames = list(c("row1", "row2"), | |
c("C.1", "C.2", "C.3"))) | |
mdat |
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
# Order columns in a table | |
fakedata <- data.frame(A=c(0,0,0), X2=c(2,2,2), X1=c(1,1,1), X3=c(3,3,3)) | |
fakedata | |
A X2 X1 X3 | |
1 0 2 1 3 | |
2 0 2 1 3 | |
3 0 2 1 3 | |
pos <- colnames(fakedata)[2:ncol(fakedata)] |
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
# For larger graphs calculate the intersection | |
# of the two graphs, this is reasonably fast, and then | |
# the Hamming distance is the number of edges in the | |
# symmetric difference. (If i'm right...) | |
int <- graph.intersection(g1,g2) | |
ecount(g1)+ecount(g2)-2*ecount(int) |
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
#-------------------------------------------------- | |
# Contingency table | |
#-------------------------------------------------- | |
# Productivity Smoking No smoking | |
# High 13 44 | |
# Low 25 29 | |
count<-c(13,25,44,29) | |
smoking<-factor(c("Yes","Yes","No","No")) | |
productivity<-factor(c("High","High","Low","Low")) |
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
############################################################################## | |
### Read network data | |
# network | |
mont1<-read.paj("Monteverde.net",verbose=T) | |
nch1<-read.paj("nch.net",verbose=T) | |
hr1<-read.paj("hr.net",verbose=T) | |
# Initializing bipartite webs for library network | |
nch1<-network.initialize(dim(nch_lab)[1]+dim(nch_lab)[2], | |
bipartite=c(dim(nch_lab)[1]),directed=F) | |
nch1 <-network.bipartite(as.matrix(nch_lab),nch1) |
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
############################################################################## | |
# Code for plotting the networks. Library bipartite. | |
# Pedro Jordano. 2 Mar 2007. Rev 4 Apr 2008 | |
# | |
#----------------------------------------------------------------------------- | |
# Initializing the datasets | |
### | |
# Enter the adjacency matrix directly | |
myweb1<- read.delim("myweb.txt", row.names=1,,header=F,sep="\t") | |
plotweb(nch1, method="cca", text.rot="90", labsize=0.8, col.low="green", |
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
############################################################################## | |
# Code for plotting the networks. Library bipartite. | |
# Pedro Jordano. 2 Mar 2007. Rev 4 Apr 2008 | |
#----------------------------------------------------------------------------- | |
# Initializing the datasets | |
# Enter the adjacency matrix directly | |
myweb1<- read.delim("myweb.txt", row.names=1,,header=F,sep="\t") | |
plotweb(nch1, method="cca", text.rot="90", labsize=0.8, col.low="green", | |
col.high="yellow", col.interaction="blue") |
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
#-------------------------------------------------------------- | |
# Ordering matrices. Web must be a matrix with 'dimnames' | |
#-------------------------------------------------------------- | |
mat.ord <- function(web) { | |
web.ord <- web[order(rowSums(web), decreasing = TRUE), | |
order(colSums(web), decreasing = TRUE)] | |
web.ord | |
} |
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
############################################################################## | |
# Plotting the degree distribution. | |
#----------------------------------------------------------------------------- | |
# Assign the matrix to be analized | |
#----------------------------------------------------------------------------- | |
mat<-as.matrix(nch_lab) | |
#----------------------------------------------------------------------------- | |
# Degree | |
#----------------------------------------------------------------------------- | |
# Animals |
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
################################################################# | |
# Network analyses. | |
# Pedro. 7 Dec 2007 | |
################################################################# | |
# NOTE: These matrices have rows are animals, columns are plants. | |
# NOTE: JORDI's datasets for NESTEDNESS have Rows are plants, | |
# columns are animals. | |
library(bipartite) | |
library(networksis) | |
library(igraph) |
OlderNewer