Learn R Programming

asnipe (version 1.1)

get_network: Calculating Weighted Network

Description

Calculate a network from a group by individual matrix. This function allows various levels of subsetting.

Usage

get_network(association_data, data_format = "GBI", association_index = "SRI", identities = NULL, which_identities = NULL, times = NULL, locations = NULL, which_locations = NULL, start_time = NULL, end_time = NULL, classes = NULL, which_classes = NULL)

Arguments

association_data
a K x N matrix of K groups (observations, gathering events, etc.) and N individuals (all individuals that are present in at least one group) OR a K x N x N array of sampling periods.
data_format
"GBI" expect a group by individual matrix, "SP" Expect a sampling periods array
association_index
"SRI" Simple ratio index, "HWI" Half-weight index (more to come)
identities
N vector of identifiers for each individual (column) in the group by individual matrix
which_identities
vector of identities to include in the network (subset of identities)
times
K vector of times defining the middle of each group/event
locations
K vector of locations defining the location of each group/event
which_locations
vector of locations to include in the network (subset of locations)
start_time
element describing the starting time for inclusion in the network (useful for temporal analysis)
end_time
element describing the ending time for inclusion in the network (useful for temporal analysis)
classes
N vector of types or class of each individual (column) in the group by individual matrix (for subsetting)
which_classes
vector of class(es)/type(s) to include in the network (subset of classes)

Value

N x N matrix of association weights for each dyad.

Details

Provides the ability to generate networks from one group by individual matrix and subsetting within the function. This is particularly useful for generating several networks with different characteristics from the same group by individual matrix (for example networks from a given location or set of locations, or of a particular sex).

References

Whitehead (2008) Analyzing Animal Societies

Examples

Run this code
data("group_by_individual")
data("times")

## define to 2 x N x N network to hold two association matrices
networks <- array(0, c(2, ncol(gbi), ncol(gbi)))

## calculate network for first half of the time
networks[1,,] <- get_network(gbi, data_format="GBI",
	association_index="SRI", times=times, start_time=0, 
	end_time=max(times)/2)
networks[2,,] <- get_network(gbi, data_format="GBI",
	association_index="SRI", times=times, 
	start_time=max(times)/2, end_time=max(times))

## test if one predicts the other via a mantel test (must be loaded externally)
library(ape)
mantel.test(networks[1,,],networks[2,,])

## convert to igraph network and calculate degree of the first network
library(igraph)
net <- graph.adjacency(networks[1,,], mode="undirected", diag=FALSE, weighted=TRUE)
deg_weighted <- graph.strength(net)
detach(package:igraph)

## alternatively package SNA can use matrix stacks directly
library(sna)
deg_weighted <- degree(networks,gmode="graph", g=c(1,2), ignore.eval=FALSE)
detach(package:sna)

Run the code above in your browser using DataLab