knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

1. Data Organization

Data should be set out in the same format as in the giraffe example data file. Note that a warning will be given for any of the possible pairs not recorded together.

library(CaptiveIndex)
data(giraffe)
head(giraffe)

Columns should include the following: Subject - Individual being sampled Present – list of individuals present separate by a space N.N – names of individual who is the nearest neighbour (within x metres) C.P – names of individual who is within the closet proximity (within x metres)

NB. If there is no individual for N.N or C.P record as a 0 (zero).

2. Create a dataset for the association measures

Use DataCreate function to prepare data for analysis:

This function will identify the number of times pairs are together, providing a short hand descriptor of the pair using the first 3 letters of each individual.

NN.ID <- DataCreate (giraffe)

head(NN.ID)

3. Calculate weights

Calculate the weights for nearest neighbour and proximity values using the Weights function:

W <- Weights(giraffe)
W

4. Calculate Captive Index

Calculate the Captive Index (or association meassure) using the data created in the DataCreate function and applying the weights from Weights function:

Results <- CaptiveIndex(NN.ID, W$NN, W$IDist)
head(Results)

5. Plot network using igraph (optional)

Convert 'Results' output into a square matrix, then plot a sociogram using igraph.

# reshape the data frame into a square matrix 
# install.packages("reshape2")
library(reshape2)
mat <- acast(Results, Subject ~ Partner, value.var = "CaptiveIndex1")
# install.packages("igraph")
library(igraph)
## Plot graph with weighted edges
g <- graph.adjacency(mat, mode="undirected", weighted=TRUE, diag=FALSE)

plot.igraph(g, vertex.label = V(g)$name,
            layout = layout.fruchterman.reingold, 
            edge.color = "black",
            edge.width = (E(g)$weight)*20, 
            mode = "circle")


JDNorrey/CaptiveIndex documentation built on Oct. 30, 2019, 7:29 p.m.