assortment.discrete {assortnet}R Documentation

Assortment on discrete vertex values

Description

Calculates the assortativity coefficient for weighted and unweighted graphs with nominal/categorical vertex values

Usage

assortment.discrete(graph, types, weighted = TRUE, SE = FALSE, M = 1, na.rm = FALSE)

Arguments

graph

Adjacency matrix, as an N x N matrix. Can be weighted or binary.

types

Values on which to calculate assortment, vector of N labels

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.

na.rm

Remove all nodes which have NA as type from both the network and the types object. If this is False and NAs are present, an error message will be displayed.

Value

This function returns a named list, with three elements:

$r the assortativity coefficient $SE the standard error $mixing_matrix the mixing matrix with the distribution of edges or edge weights by category

Author(s)

Damien Farine dfarine@orn.mpg.de

References

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.

Examples

	# 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 discrete trait values
	traits <- rpois(N,2)
	
	# Test for assortment as binary network
	assortment.discrete(network,traits,weighted=FALSE)
	
	# Test for assortment as weighted network
	assortment.discrete(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 discrete trait values
	traits <- rpois(N,2)
	
	# Test for assortment as binary network
	assortment.discrete(network,traits,weighted=FALSE)
	
	# Test for assortment as weighted network
	assortment.discrete(network,traits,weighted=TRUE)


[Package assortnet version 0.20 Index]