assortment.continuous {assortnet} | R Documentation |
Calculates the assortativity coefficient for weighted and unweighted graphs with numerical vertex values
assortment.continuous(graph, vertex_values, weighted = TRUE, SE = FALSE, M = 1)
graph |
A Adjacency matrix, as an N x N matrix. Can be weighted or binary. |
vertex_values |
Values on which to calculate assortment, vector of N numbers |
weighted |
Flag: TRUE to use weighted edges, FALSE to turn edges into binary (even if weights are given) |
SE |
Calculate standard error using the Jackknife method. |
M |
Binning value for Jackknife, where M edges are removed rather than single edges. This helps speed up the estimate for large networks with many edges. |
This function returns a named list, with two elements:
$r the assortativity coefficient $SE the standard error
Damien Farine dfarine@orn.mpg.de
Newman (2003) Mixing patterns in networks. Physical Review E (67) Farine, D.R. (2014) Measuring phenotypic assortment in animal social networks: weighted associations are more robust than binary edges. Animal Behaviour 89: 141-153.
# DIRECTED NETWORK EXAMPLE # Create a random directed network N <- 20 dyads <- expand.grid(ID1=1:20,ID2=1:20) dyads <- dyads[which(dyads$ID1 != dyads$ID2),] weights <- rbeta(nrow(dyads),1,15) network <- matrix(0, nrow=N, ncol=N) network[cbind(dyads$ID1,dyads$ID2)] <- weights # Create random continues trait values traits <- rnorm(N) # Test for assortment as binary network assortment.continuous(network,traits,weighted=FALSE) # Test for assortment as weighted network assortment.continuous(network,traits,weighted=TRUE) # UNDIRECTED NETWORK EXAMPLE # Create a random undirected network N <- 20 dyads <- expand.grid(ID1=1:20,ID2=1:20) dyads <- dyads[which(dyads$ID1 < dyads$ID2),] weights <- rbeta(nrow(dyads),1,15) network <- matrix(0, nrow=N, ncol=N) network[cbind(dyads$ID1,dyads$ID2)] <- weights network[cbind(dyads$ID2,dyads$ID1)] <- weights # Create random continues trait values traits <- rnorm(N) # Test for assortment as binary network assortment.continuous(network,traits,weighted=FALSE) # Test for assortment as weighted network assortment.continuous(network,traits,weighted=TRUE)