R packages‎ > ‎

Analysing animal social networks: asnipe

Read about this package (with instructions and sample code) here and in the appendix of this paper.

I developed the package asnipe in order to help bridge the gap between data and the breadth of packages in R for conducting analyses on social networks (such as igraph or sna). This package has five primary roles: 
  1. Defining a group by individual matrix or sampling period matrices from association data.
  2. Creating association matrices from groups or sampling period data.
  3. Performing permutation tests on the data stream to generate biologically-relevant null models.
  4. Calculating lagged association rates, and a new measure: the lagged rate of association.
  5. Do multiple regression quadratic assignment procedure (MRQAP) on weighted social networks.
In doing so, asnipe provides routines that are essential in performing analyses on animal social network, such as controlling for sampling strategies. Further, asnipe provides built-in functionality that enables simple incorporation of time, space, and classes of individuals. This is essential for conducting biologically-relevant tests (such as controlling for age, sex or location). Finally, by sub-setting time internally, asnipe can be used to easily generate dynamic networks.

Futher details can be found in: Farine, D.R. (2013) Animal Social Network Inference and Permutations for Ecologists in R using asnipe. Methods in Ecology and Evolution (link)


TO INSTALL: asnipe is now on CRAN (https://cran.r-project.org/web/packages/asnipe/index.html), so can be installed directly using R. If you have any problems, you can manually download the package and use my old installation instructions below.


use the terminal in MAC with the command:

R CMD install asnipe_X.XX.tar.gz   (replace X.XX with the latest version number)

Make sure you navigate to the directory containing the file first. 


In Windows, I've found the following works for most people:

install.packages("Y:/asnipe_X.XX.tar.gz", repos = NULL, type="source")

Where you replace Y:/ with the drive and directory where the file has been downloaded.


GMMevents

My package now contains an implementation of GMMevents (previously available only on Matlab). This can be used to detect groups of animals based on their clustering in time (see this paper and this paper). Notably, my package includes one improvement on previous implementations in that it allows the splitting of over-lapping groups. The regular function allows detection of groups that overlap other groups in time - for example group A can run from t=5 to t=20, while group B can run from t=8 to t=11. My package allows group A to be split into two sub-groups, resulting in some improvement in the robustness of the method.


MRQAP-DSP

Most network analyses use MRQAP from UCINET. However, that implementation only permutes the dependent (y) variable. Thus, the null hypothesis for that test is that Y is not related to either X1, X2, or Xn. In contrast, most users want to determine if Y is related to X1 while controlling for X2..Xn (and similar for X2 while controlling for X1..). In the current function, I implement the method proposed by: 
Dekker, D., Krackhard, D., Snijders, T.A.B (2007) Sensitivity of MRQAP tests to collinearity and autocorellation conditions. Psychometrika 72(4): 563-581.

NOTE:  there is a typo in the user manual, on page 12, two following lines:

    species[,-i] <- as.numeric(inds$SPECIES[1] == inds$SPECIES[-i])
    sex[,-i] <- as.numeric(inds$SEX[1] == inds$SEX[-i])

should say:

    species[i,-i] <- as.numeric(inds$SPECIES[i] == inds$SPECIES[-i])
    sex[i,-i] <- as.numeric(inds$SEX[i] == inds$SEX[-i])



Note on permutations for Windows users

Unfortunately it seems that neither is R good at minimising memory use nor is Windows very good at managing memory. I've had some reports that permutations rapidly eat up all the system's memory due to the size of the resulting data stack. I've now implemented a solution (see point 1 below) that should help reduce the size of this data stack.



Thanks to everyone who has provided feedback on the package so far. I'm making a list below of things I need to implement - stay tuned for updates!


TO DO:

1. Allow multiple swaps before returning matrix in order to be able to create more permutations (i.e. 100000 permutations returning every 100 swaps for 1000 data points). (done on 18th October 2013 in version 0.71)
2. Fix bug in get_group_by_individual function (done on 10th October 2013 in version 0.7)
3. Create a function that performs one or more swaps and returns both the association matrix and the data stream matrix (done on 18th October 2013 in version 0.72)
4. Fixed an apparent issue in mrqap.dsp for formulas in newer versions of R (done 7th April 2014 in version 0.81)
5. Fixed a bug in mrqap.dsp I discovered after further testing (done 7th May 2014 in version 0.82)